-
-
Notifications
You must be signed in to change notification settings - Fork 83
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Follow system color scheme #210
Conversation
WalkthroughThe changes introduced in this pull request involve extending the Changes
Poem
Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media? 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. CodeRabbit Commands (Invoked using PR comments)
Other keywords and placeholders
CodeRabbit Configuration File (
|
575f291
to
a31ba01
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 2
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
📒 Files selected for processing (2)
src/@types/types.d.ts
(1 hunks)src/context/AppContext.tsx
(1 hunks)
🧰 Additional context used
🪛 Biome (1.9.4)
src/@types/types.d.ts
[error] 36-36: Don't use 'Function' as a type.
Prefer explicitly define the function shape. This type accepts any function-like value, which can be a common source of bugs.
(lint/complexity/noBannedTypes)
🪛 eslint
src/@types/types.d.ts
[error] 36-36: Don't use Function
as a type. The Function
type accepts any function-like value.
It provides no type safety when calling the function, which can be a common source of bugs.
It also accepts things like class declarations, which will throw at runtime as they will not be called with new
.
If you are expecting the function to accept certain arguments, you should explicitly define the function shape.
(@typescript-eslint/ban-types)
mql.addEventListener("change", themeListener); | ||
if ( | ||
window.systemColorSchemeCallbacks && | ||
Array.isArray(window.systemColorSchemeCallbacks) | ||
) { | ||
window.systemColorSchemeCallbacks.push(themeListener); | ||
} | ||
|
||
return () => { | ||
mql.removeEventListener("change", themeListener); | ||
if ( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ensure compatibility with older browsers for media query listeners
The MediaQueryList
interface's addEventListener
and removeEventListener
methods are not supported in some older browsers. To maintain broader compatibility, consider using addListener
and removeListener
or include a fallback.
Here is how you can modify the code to support both methods:
// Add event listener for theme changes
- mql.addEventListener("change", themeListener);
+ if (mql.addEventListener) {
+ mql.addEventListener("change", themeListener);
+ } else {
+ mql.addListener(themeListener);
+ }
And in the cleanup function:
// Remove event listener
- mql.removeEventListener("change", themeListener);
+ if (mql.removeEventListener) {
+ mql.removeEventListener("change", themeListener);
+ } else {
+ mql.removeListener(themeListener);
+ }
This ensures compatibility with browsers that only support the older addListener
and removeListener
methods.
📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
mql.addEventListener("change", themeListener); | |
if ( | |
window.systemColorSchemeCallbacks && | |
Array.isArray(window.systemColorSchemeCallbacks) | |
) { | |
window.systemColorSchemeCallbacks.push(themeListener); | |
} | |
return () => { | |
mql.removeEventListener("change", themeListener); | |
if ( | |
if (mql.addEventListener) { | |
mql.addEventListener("change", themeListener); | |
} else { | |
mql.addListener(themeListener); | |
} | |
if ( | |
window.systemColorSchemeCallbacks && | |
Array.isArray(window.systemColorSchemeCallbacks) | |
) { | |
window.systemColorSchemeCallbacks.push(themeListener); | |
} | |
return () => { | |
if (mql.removeEventListener) { | |
mql.removeEventListener("change", themeListener); | |
} else { | |
mql.removeListener(themeListener); | |
} | |
if ( |
/** Injected by hkbus.app app webview | ||
* @since Dec 2024 | ||
*/ | ||
systemColorSchemeCallbacks?: Function[]; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Specify function types explicitly instead of using Function
Using Function
as a type is discouraged because it lacks type safety and can lead to bugs. It's better to define the function type explicitly to ensure type safety.
Apply this diff to fix the type definition:
/** Injected by hkbus.app app webview
* @since Dec 2024
*/
- systemColorSchemeCallbacks?: Function[];
+ systemColorSchemeCallbacks?: Array<() => void>;
This change defines systemColorSchemeCallbacks
as an array of functions that take no arguments and return void, which aligns with the expected callback signature used in your code.
📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
systemColorSchemeCallbacks?: Function[]; | |
systemColorSchemeCallbacks?: Array<() => void>; |
🧰 Tools
🪛 Biome (1.9.4)
[error] 36-36: Don't use 'Function' as a type.
Prefer explicitly define the function shape. This type accepts any function-like value, which can be a common source of bugs.
(lint/complexity/noBannedTypes)
🪛 eslint
[error] 36-36: Don't use Function
as a type. The Function
type accepts any function-like value.
It provides no type safety when calling the function, which can be a common source of bugs.
It also accepts things like class declarations, which will throw at runtime as they will not be called with new
.
If you are expecting the function to accept certain arguments, you should explicitly define the function shape.
(@typescript-eslint/ban-types)
See hkbus/mobile-bus-app/pull/22
Summary by CodeRabbit
New Features
Bug Fixes
Refactor
Documentation