-
-
Notifications
You must be signed in to change notification settings - Fork 7.5k
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
gear_menu: Add theme switcher to the gear menu popover. #30334
base: main
Are you sure you want to change the base?
Conversation
🔍 Existing Issues For ReviewYour pull request is modifying functions with the following pre-existing issues: 📄 File: web/src/ui_init.js
Did you find this useful? React with a 👍 or 👎 |
@amanagr Could you please review this PR? Thanks! |
web/src/dark_theme.ts
Outdated
@@ -22,9 +24,17 @@ export function disable(): void { | |||
const ls = localstorage(); | |||
ls.set("spectator-theme-preference", "light"); | |||
user_settings.color_scheme = settings_config.color_scheme_values.day.code; | |||
realm_logo.render(); | |||
} | |||
} | |||
|
|||
export function default_preference_checker(): void { |
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.
Should we rename this function and library? dark_theme.default_preference_checker
is a weird thing to call.
I would prefer it to be called theme.use_system_default
instead.
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.
Let's open a czo thread to weight in opinion from others.
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.
Opened a CZO thread discussing this idea, thanks!
web/src/dark_theme.ts
Outdated
const ls = localstorage(); | ||
ls.set("spectator-theme-preference", "automatic"); | ||
user_settings.color_scheme = settings_config.color_scheme_values.automatic.code; | ||
realm_logo.render(); |
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.
Let's extract this into a function since it seems like it would make this easier to look at and of course has the benefit of DRY.
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.
Extracted this and other such methods for setting spectator theme into dark_theme.set_theme_for_spectator()
.
web/src/gear_menu.js
Outdated
const theme_code = Number.parseInt($(e.currentTarget).attr("data-theme-code"), 10); | ||
requestAnimationFrame(() => { | ||
dark_theme.disable(); | ||
if (theme_code === settings_config.color_scheme_values.night.code) { | ||
dark_theme.enable(); | ||
} else if (theme_code === settings_config.color_scheme_values.day.code) { | ||
dark_theme.disable(); | ||
} else { | ||
dark_theme.default_preference_checker(); | ||
} | ||
message_lists.update_recipient_bar_background_color(); |
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.
Let's move this call inside dark_theme
and calling it in the server events dispatch path too.
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.
Moved the CSS class logic into dark_theme.set_theme()
and added dark_theme.set_theme_and_update()
, which calls set_theme()
and also calls the realm logo and recipient bar update methods. The idea is that all theme switchers and commands call dark_theme.set_theme_and_update()
, which will set the theme and also update the necessary elements. While dark_theme.set_theme()
is used in ui_init.js
to only set the theme via the CSS classes, since the theme is set before the message list and the realm logo are initialised.
web/src/dark_theme.ts
Outdated
@@ -12,6 +13,7 @@ export function enable(): void { | |||
const ls = localstorage(); | |||
ls.set("spectator-theme-preference", "dark"); | |||
user_settings.color_scheme = settings_config.color_scheme_values.night.code; | |||
realm_logo.render(); |
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 was wondering why we don't need realm_logo.render();
call for logged-in users and it seems like we do, so we move the call inside these enable/ disable
functions as well.
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.
Makes sense, thanks! Moved realm_logo.render()
along with message_lists.update_recipient_bar_background_color()
into dark_theme
module.
@sayamsamal thanks for working on this! Looks like this library and the code surrounding it needs some long due cleanup. Let's make it happen! |
d54c01c
to
51653d4
Compare
51653d4
to
82c3bfb
Compare
Similar to the light/dark theme support for the spectators, this adds the automatic color scheme support by storing the user's preference in the local storage.
Before this, the realm logo was not being updated instantly when the theme was changed through the gear menu, and instead required a page reload to take effect.
Standardize theme selection across the web app by replacing separate light/dark theme menu options being used in the spectator view with the new 3-way theme switcher. Fixes zulip#30318.
This commit centralizes the logic for setting a user's theme preference, both for regular users and spectators, into the `dark_theme.ts` module. This simplifies theme handling throughout the codebase and ensures that the theme is set consistently across all modules. Instead of relying on various call sites to update the recipient bar's background color and switch between the light/dark realm logo after a theme change, this commit modifies the `set_theme_and_update` function to include these calls after every theme change. Before this commit, some modules used to update the realm logo after a theme change, while others did not. This led to inconsistencies in the UI depending on which method was used to change the theme.
The dark_theme module now contains logic for light, dark, and automatic theme switching. Thus, we rename it a more generic name, `theme.ts`.
As a follow-up to the previous commit renaming the `dark_theme.ts` module to `theme.ts`, this commit renames the following functions: - `enable` -> `set_dark_theme` - `disable` -> `set_light_theme` - `default_preference_checker` -> `set_automatic_theme`
This commit standardizes the naming of the day and night themes to light and dark, respectively. This makes the codebase more consistent with the naming used in the settings and the user interface.
82c3bfb
to
b7270ae
Compare
Heads up @sayamsamal, we just merged some commits that conflict with the changes you made in this pull request! You can review this repository's recent commits to see where the conflicts occur. Please rebase your feature branch against the |
This PR improves the theme experience for spectators by:
Fixes: #30318
Screenshots and screen captures:
Self-review checklist
(variable names, code reuse, readability, etc.).
Communicate decisions, questions, and potential concerns.
Individual commits are ready for review (see commit discipline).
Completed manual review and testing of the following: