freeCodeCamp icon indicating copy to clipboard operation
freeCodeCamp copied to clipboard

Use System Default for Initial Theme?

Open naomi-lgbt opened this issue 3 years ago • 17 comments

Describe the Issue

I had an issue with another website that was fixed by clearing my browser cache. As a result, I had to log in to all of my sites again. I ended up on Reddit which defaulted to light mode for unauthenticated users, and realised that freeCodeCamp does the same.

Affected Page

https://freecodecamp.org

Steps to Reproduce

  1. Log out.
  2. See light mode?

Expected behavior

I'm wondering if we should leverage the user's system setting to determine if we should default to light or dark mode.

Screenshots

No response

System

The only relevant thing here is that I'm on Windows, I think.

Additional context

No response

naomi-lgbt avatar Aug 15 '22 20:08 naomi-lgbt

Yes, we default to light mode.

... we should leverage the user's system setting ...

I'm not against this - although, I think the bigger issue is that you can only switch the theme if you are logged in. Seems like you should be able to switch regardless. I don't recall if there was any reason that we don't allow that.

moT01 avatar Aug 16 '22 15:08 moT01

@moT01 Wouldn't it be more helpful to have night-mode for non-logged in user as well, and also it defaults to system's theme?

iarmankhan avatar Aug 21 '22 18:08 iarmankhan

So the logic should be the followings: // if user has a set a preference, set the theme // else if system setting has a theme, set the theme, // else set the theme as default.

We could set the theme in the localstorage and pull it up on the upcoming sessions. Reference: https://github.com/gaearon/overreacted.io/blob/master/src/html.js#L21-L48

ahmaxed avatar Aug 31 '22 10:08 ahmaxed

Do we want to allow non-authed users to switch to night mode using the menu? I feel like we should. If so, we may not need some of this logic (or, may need more).

moT01 avatar Sep 21 '22 00:09 moT01

I think we should allow non-auth users to switch theme. If users have not set a preference in the localhost and have a theme preference on their record, we could pull that data and set it accordingly if possible. Moving forward we would not want to use the user records for theme switching.

ahmaxed avatar Sep 23 '22 13:09 ahmaxed

To resolve this issue in the short term:

  • If the camper has set the theme to night: We should display night mode (the current behaviour)
  • If the camper has set the theme to default: We should respect the system settings for the theme.

naomi-lgbt avatar Nov 09 '22 15:11 naomi-lgbt

Reopened because the solution isn't optimal, but it did improve it

Sboonny avatar Dec 14 '22 16:12 Sboonny

@ahmadabdolsaheb, @ojeytonwilliams, @raisedadead. I want to bring back the discussion to the issue, and finalize the solution before the implementation.

image

I have a looked into different implementation, and the one from Mozilla foundation seems the most fitting to me and want to discuss it with you.

What do you think of 3rd option for OS system? So people can have an opt-in system option, when the ability to store data hinder the camper experience, because they want to have different themes in different devices.

Sboonny avatar Dec 19 '22 12:12 Sboonny

Sure, that sounds good.

ojeytonwilliams avatar Dec 19 '22 13:12 ojeytonwilliams

@ahmadabdolsaheb, I lost the notes because of the holiday so I am not sure, we didn't want the themes to be a dropdown, but just buttons for now.

Was that about the menu or the setting picker? I am not sure.

image

Sboonny avatar Jan 06 '23 07:01 Sboonny

We can keep them as buttons. Also, we could remove the theme switching from the navigation entirely.

ahmaxed avatar Jan 06 '23 14:01 ahmaxed

My two cents:

  • They should be a drop-down on the settings page. Dropdowns make it very nice and clear of the selection and not to mention easiest to maintain (a11y and UX wise, etc.).
  • There was a very strong argument to keep the theme in the nav and was a very common request. I wonder if the toggle can be converted into a similar UX as the language selector, then we would be set.

raisedadead avatar Jan 06 '23 14:01 raisedadead

They should be a drop-down on the settings page. Dropdowns make it very nice and clear of the selection and not to mention easiest to maintain (a11y and UX wise, etc.).

We can come back to the dropdown, when we add new themes. Maybe we create a different component that display part of the page in different themes instead, like GitHub. So let's not spend our effort on this yet, while the one we're currently having something that is working. 👍

They should be a drop-down on the settings page. Dropdowns make it very nice and clear of the selection and not to mention easiest to maintain (a11y and UX wise, etc.).

I am worried that we will run into the issue of it being obscure, like what we have in the language selector.

Sboonny avatar Jan 06 '23 16:01 Sboonny

We can come back to the dropdown, when we add new themes.

A wise man (Quincy) once said, you should avoid introducing big changes to UI. If you have to, then delay and introduce them all at once, because you WILL get called out for doing something radical. Might as well do it fewer times.

Point being, if you are building something that you are going to throw away (and you know it), you are doing it wrong. 🤷🏽

raisedadead avatar Jan 06 '23 16:01 raisedadead

Themes switchers seems to be the convention in blog/documentation website navigations. As the app gets more complicated, the theme switcher gets relocated to the settings.

The language selector is moving to the top navigation. If we rely on the settings page's theme switcher, we could remove related section from the dropdown navigation entirely. That being said, if there is a lot of demand for it, we should keep it around in the nav.

If we keep the theme switcher in the nav, it makes sense to use a component that looks good on mobile such as a dropdown so we could reuse it in the settings page as well.

ahmaxed avatar Jan 06 '23 17:01 ahmaxed

Based on discussion with @ojeytonwilliams:

  • it's possible to add the theme values to local storage and set the default theme of the pages based on them.
  • it's possible to have system theme if the local storage store third value
  • it's possible to clear the flash with the usage of local storage

Sboonny avatar Jan 26 '23 08:01 Sboonny

If the logic seem convoluted, feel free to lay it down in pseudo code. Once everyone is in agreement, we can proceed with the implementation.

ahmaxed avatar Jan 27 '23 11:01 ahmaxed

Closing as stale. Thanks and happy coding 🎉

moT01 avatar Jun 06 '24 15:06 moT01