-
Notifications
You must be signed in to change notification settings - Fork 34
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
Automatically Switch to Dark Mode #410
Merged
Merged
Changes from 6 commits
Commits
Show all changes
21 commits
Select commit
Hold shift + click to select a range
e5a8a93
Feat.: Add dark mode following device color scheme
Viyerelu23333 7f93bdc
Fix: Reduce flickers caused by loading courses
Viyerelu23333 d50be64
Feat.: Add method of change scheme to device color
Viyerelu23333 fa09a96
FIX: Change the implementation of dark mode switch
Viyerelu23333 8bc46a0
Fix: Change positions of toaster notifications
Viyerelu23333 33bb788
Feat.: Change color scheme without refreshing
Viyerelu23333 d3add46
Fix: Coding style enhancements
Viyerelu23333 50fcd63
Fix: Code readability
Viyerelu23333 1dda935
Feat.: Add dark mode following device color scheme
Viyerelu23333 571f7c9
Fix: Reduce flickers caused by loading courses
Viyerelu23333 ddc1c1d
Feat.: Add method of change scheme to device color
Viyerelu23333 fe6c7fe
FIX: Change the implementation of dark mode switch
Viyerelu23333 66cace1
Fix: Change positions of toaster notifications
Viyerelu23333 94c581a
Feat.: Change color scheme without refreshing
Viyerelu23333 7451fc3
Fix: Coding style enhancements
Viyerelu23333 dd76415
Fix: Code readability
Viyerelu23333 8950be6
Merge branch 'switch-dark-mode' of https://github.com/YACS-RCOS/yacs.…
66903a7
Fix: Resolved conflicts
dca88dd
Merge remote-tracking branch 'origin/master' into switch-dark-mode
Viyerelu23333 e1e95dd
fix: code duplicates and fix cookie reset function
Viyerelu23333 b2519d0
Merge branch 'master' into switch-dark-mode
Viyerelu23333 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
From what I understand, it looks like the first
if
block is checking the cookies to see if the user has an existing color-scheme preference and the secondif
block is setting the colorscheme to the device preference. right?If so, lets maybe refactor a bit. Here's a few ideas so that we can get to:
this way the code reads a bit simpler and we can seperate the concerns of checking if the dark mode is set, linking to cookie and matching device preference.
wyt?
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.
Thanks for your comments!
Yes, I think your refactoring ideas are great. Semantic function names are intuitive.
There are still two points:
if
checks the cookie or current scheme, and the secondif
checks the native support of color scheme: bothif
blocks will run, so it cannot be considered as aif-else
block.window.matchMedia
, so I deleted the testing for capabilities.How about this:
App.Vue
Any ideas? Not commit yet.
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.
Reads much better! Lets take it one step further.
Lets only read the preferance once with
.matches
and not keep the listener open. This change would sit more inline with the UX that we are looking for from the issue definitionCodewise, we'd no longer need the eventListener as we'd only take the value once that you can wrap in a function
getDarkModeDevicePreferance
.Then, I think we can follow the earlier logic that reads at the same abstraction level as the issue statement
Also small note on this predicates like this (not sure if itll be the same one):
but better to give it a function so that when reading you can stay at one level of abstraction (figuring out where darkmode preferances are coming from) and not worry about mq.matches and what that means and what a JS MediaQuery object is.
Lastly, strings
"darkMode:
and the"(prefers-color-scheme: dark)"
can be extracted out likehttps://github.com/YACS-RCOS/yacs.n/blob/master/src/web/src/controllers/Schedule.js#L7-L8
so that we catch string mismatches as compile time errors. You can throw these strings up to the top of the class as something like
App.COOKIE_DARKMODE
andApp.MQ_COLORSCHEME
orApp.MEDIAQUERY_COLORSCHEME
wyt? or should we keep the responsiveness to colorscheme changes?
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.
I'm way out of the loop here, but instead of only using
prefers-color-scheme: dark
when thedarkMode
cookie is null, could we just update thedarkMode
cookie state to match theprefers-color-scheme: dark
state if it changes?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.
Sorry, I forgot to update the feature request. My bad. That was the original idea, and it only covers the change for new users who don't have cookies. On actual coding I found it is easy to implement a responsive color scheme as a third state... Personally I would like to preserve this feature.
Agree. I thought this sentence shows a clear relationship of the conditions... But not optimal for reading it.
I will wrap it before the next push.
Do you mean
state.darkMode
instore/index.js
? Not sure if this will affect current usage of cookies...Also, not sure if
App.Vue
has aclass
...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.
It is a bit confusing.
If I interpret your idea correct,
darkMode
cookie has a string for saving the user's current option for color scheme.Also there is a boolean
state.darkMode
, which records the current site color scheme. This will change on each load, if the cookie was set to dark mode; or the user did not specify the scheme, it will change to follow the current device preference.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.
Yep you're right, extracting out into
store/index.js
should do it where you'd importCOOKIE_DARKMODE
.Shouldn't change the behavior, only a code change
Proposed change goes from:
to
so easier to take advantage of autocomplete and reduce typos/silent errors
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.
Perhaps something like this code below?
store/index.js
:Same
import
will apply toHeader.Vue
too.App.Vue