openstreetmap / openstreetmap-website

The Rails application that powers OpenStreetMap
https://www.openstreetmap.org/
GNU General Public License v2.0
2.21k stars 918 forks source link

Color mode preference #5337

Open AntonKhorev opened 5 days ago

AntonKhorev commented 5 days ago

A quick implementation of auto/light scheme switch for those who want to stay on the light scheme even when their browser says they want the dark one.

image image image

Its on the /preferences page but it's not actually a preference stored in the User model. It's stored in a cookie. The question is do we want to store it in a cookie? Maybe we do because what browser reports as a preferred scheme is per browser, not per user, then perhaps its override should also be per browser. And it will be easier to extend the availability of this option to anonymous users. It is kind of available already, if they know how to edit cookies.

tomhughes commented 5 days ago

If it's in the user preferences it should be stored in the database not in cookies.

AntonKhorev commented 5 days ago

But should it be in user preferences?

AntonKhorev commented 5 days ago

And if stored in the database, should it be in User or UserPreference? This one depends on how do we want to make it available to other apps.

hlfan commented 5 days ago

I don't think this preference mashup between local and database storage is a great idea.

But if logged-in users have the preference synchronized and non-logged-in users have the color and language (editor choice seems pointless for non-logged-in users) stored in the cookies it could be interesting.

Or just decuple the local settings from the synced ones.

AntonKhorev commented 5 days ago

By making the setting available to other apps I meant iD of course. Its color scheme preferably should match the entire site, that means it has to know somehow whether to use prefers-color-scheme or ignore it. Let's suppose we made this setting somehow readable through the api. iD will look at it and adjust its color scheme accordingly.

Now let's suppose we don't use iD embedded in the osm-website. We'll run it from https://ideditor-release.netlify.app/, It can still read the setting in the api, but the reason to apply it is gone because iD is no longer embedded. Then maybe it's better to pass it as a startup parameter through https://github.com/openstreetmap/openstreetmap-website/blob/22942b1ca144444bdece1636451fd3ad86530b3e/app/views/site/_id.html.erb#L4 In this case we wouldn't need to worry how exactly we store the setting.

hlfan commented 5 days ago

How would not logged-in users change this setting?

AntonKhorev commented 5 days ago

How would not logged-in users change this setting?

At first they they wouldn't be able to, like with languages.

Whether this will work depends on how disruptive is whatever they run instead of the native dark mode, whether it will prevent them from logging in for their preferences to take effect.