-
Notifications
You must be signed in to change notification settings - Fork 209
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
Added User theme(Light/Dark) preference detection #1072
Changes from 3 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -15,7 +15,7 @@ const initialState = { | |
sidebar: { | ||
collapsed: false, | ||
}, | ||
mode: "light", | ||
mode: window?.matchMedia?.('(prefers-color-scheme: dark)')?.matches? "dark": "light", | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Not sure what happened, but the formatting is not that clear without the space between the first part of the ternary and the question mark. Would you mind extracting the ternary from the object to increase legibility? I suggest saving it to a variable with a name like initialMode or something like that There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @marcelluscaio I have made that change |
||
greeting: { index: 0, lastUpdate: null }, | ||
timezone: "America/Toronto", | ||
}; | ||
|
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.
🛠️ Refactor suggestion
One more thing about that initialization! 💡
Consider extracting the theme detection logic into a separate utility function. This would make it easier to test and maintain.
Create a new file
utils/themeDetection.js
:Then in uiSlice.js:
Yo! The theme detection needs some love! 🍝
While the implementation works, there are several improvements we could make to ensure robustness:
Here's a more robust implementation: