Skip to content
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

Using selected mode (dark, light) by default when userChoice is enabled #29

Merged
merged 1 commit into from
Mar 5, 2023

Conversation

Racso
Copy link
Contributor

@Racso Racso commented Mar 3, 2023

Hi! I propose a change in the logic that picks the color mode (light, dark) to use. It's simpler, and I think achieves the same behaviour as before, with an improvement for a specific case.

The following rules from the docs will still work:

If the autoDark option is enabled, the color scheme of the operating system is used.
If neither of the two options is selected, a static color scheme can be selected via theme.
If both options are enabled, then Auto mode will be used until the user makes a choice. From this point on, only the user's choice is taken into account.

But also, this will happen now:

If only userChoice is enabled, then the selected static mode will be used until the user makes a choice.

Which I believe works better than the current behavior (forcing light mode in that case until the user makes a choice).

This would close #28.

…ault when userChoice is set and autoDark is not.
@MrReSc
Copy link
Owner

MrReSc commented Mar 3, 2023

Thanks for solving the problem yourself!
I'll look at it, but it may take a few days.

@Racso
Copy link
Contributor Author

Racso commented Mar 3, 2023

No problem! Thanks for your work on the template!

@MrReSc
Copy link
Owner

MrReSc commented Mar 4, 2023

If only userChoice is enabled, then the selected static mode will be used until the user makes a choice.

Unfortunately, this does not work because the cookie has never been set.
grafik

To test your change you have to delete the cookie "theme" and reload the page with Ctrl + F5.
Basically, I think your idea is good. Please adjust the PR, then I can look at it again.

@Racso
Copy link
Contributor Author

Racso commented Mar 4, 2023

I'm afraid I don't understand the issue. I'm getting the desired behavior correctly.

The cookie is only set after the user toggles the theme with the "Toggle theme" button at least once. Before that, there is no cookie. When there is no cookie, the selected static theme (stored in the settings) is used.

When you saved those settings shown in your image (theme=dark, userChoice=true, autoDark=false), what did you get after deleting the cookie and reloading? Dark or Light?

In that case, I get a Dark theme (correctly).

This is the first load. No cookie, Dark theme:

image

Then I toggle the theme with the "Toggle theme" button. The cookie appears with "Light":

image

If I reload the page at this point, I keep getting Light (because the cookie now exists and is used).

If I click again on "Toggle threme", I go back to dark and the cookie is updated:

image

If at any point I delete the cookie and then reload the page, it appears Dark again by default (because Dark is set in the settings).

Do you get a different behavior?

@MrReSc
Copy link
Owner

MrReSc commented Mar 4, 2023

I thought I had tested it exactly as you described. But probably not - it was still early in the morning 😴. As soon as I have time again, I'll try it again!

@MrReSc
Copy link
Owner

MrReSc commented Mar 5, 2023

I just tested it with the wrong branch. Shame on me ;-).
Everything works. Thanks for your contribution!

@MrReSc MrReSc merged commit 9409bb8 into MrReSc:master Mar 5, 2023
@Racso
Copy link
Contributor Author

Racso commented Mar 5, 2023

Great! :D Thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Template starts in light mode even when it should start in dark mode
2 participants