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

Theme Toggling Feature #2972

Closed
wants to merge 33 commits into from
Closed

Conversation

ayanaar
Copy link
Contributor

@ayanaar ayanaar commented Oct 3, 2023

This PR addresses the last step in the process of implementing theme support for Pontoon. It introduces the capability for users to seamlessly switch between the platform's existing dark theme and the newly added light theme (Issue #2936 ).

Changes:

  • New UI Element: Added buttons in the settings page allowing users to select their preferred theme: Dark, Light, or Match System.
  • Theme Persistence: User theme preference is stored in their profile, ensuring a consistent experience across sessions.
  • Dynamic Theme Application: Leveraging JavaScript, the theme is applied dynamically without requiring a page reload.
  • Fallback Mechanism: In case of any issues, the system defaults to the dark theme, ensuring no disruption to the user experience.

Additional Notes:

  • Future Work:
    • Light Theme Creation (Issue Create a new light-theme.css file #2935): The next step will involve the creation of a new light-theme.css file, which will house the variables and styles specific to the light theme.
    • The light-mode.css file used in this PR is a placeholder.

@ayanaar ayanaar requested a review from mathjazz October 3, 2023 00:51
pontoon/base/models.py Outdated Show resolved Hide resolved
pontoon/base/models.py Outdated Show resolved Hide resolved
pontoon/base/templates/base.html Outdated Show resolved Hide resolved
pontoon/base/templates/base.html Outdated Show resolved Hide resolved
pontoon/base/templates/django/base.html Outdated Show resolved Hide resolved
@mathjazz
Copy link
Collaborator

mathjazz commented Oct 3, 2023

Nice work!

Please note that the spec has now been updated with the theme selector mockups:
9605154

I'll share the corresponding HTML and CSS with you.

We should also change the tooltips as noted in the spec.

pontoon/base/templates/base.html Outdated Show resolved Hide resolved
pontoon/base/templates/django/base.html Outdated Show resolved Hide resolved
pontoon/base/templates/django/base.html Outdated Show resolved Hide resolved
pontoon/contributors/templates/contributors/settings.html Outdated Show resolved Hide resolved
pontoon/contributors/templates/contributors/settings.html Outdated Show resolved Hide resolved
pontoon/contributors/templates/contributors/settings.html Outdated Show resolved Hide resolved
pontoon/contributors/views.py Outdated Show resolved Hide resolved
pontoon/contributors/views.py Outdated Show resolved Hide resolved
@mathjazz
Copy link
Collaborator

mathjazz commented Oct 3, 2023

Excellent work with the updates! Added a few more minor requests.

@mathjazz
Copy link
Collaborator

mathjazz commented Oct 4, 2023

Thanks for another set of updates!

I had a closer look at how the toggle logic actually works. Here's my list of proposals:

  1. System theme does not get applied. Themes are applied by setting the corresponding class on the <body> element, which results in the use of the right theme file. Since we don't have a system-theme.css file, setting system-theme on the <body> element doesn't apply any of the theme files. If the system theme is set, we should detect what it is and set light-theme / dark-theme class accordingly. It would also be nice to add an event handler (as used in the Stackoverflow) that will change the theme immediately after it is changed in the OS.

  2. Changing the theme doesn't seem to apply in the Translate view.

  3. In order to prevent the error triggered on theme switch, you'll need to make the selector at https://github.com/mozilla/pontoon/blob/main/pontoon/contributors/static/js/settings.js#L3 more specific, to make sure it doesn't apply to the theme selector.

  4. Changes to the specs/ folder need to be excluded from the PR. You'll need to rebase against the main branch.

@flodolo flodolo changed the title Theme Toggling Feauture Theme Toggling Feature Oct 5, 2023
) {
return 'dark';
} else {
return 'light';
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should default to dark, not light. So if the user sets "System" in Pontoon and "Auto" on macOS, she should get the dark theme. Right now she gets the light theme.

pontoon/base/static/js/themeSwitcher.js Outdated Show resolved Hide resolved
pontoon/base/static/js/themeSwitcher.js Outdated Show resolved Hide resolved
pontoon/base/static/js/themeSwitcher.js Outdated Show resolved Hide resolved
pontoon/base/static/js/themeSwitcher.js Outdated Show resolved Hide resolved
translate/public/translate.html Outdated Show resolved Hide resolved
translate/public/translate.html Outdated Show resolved Hide resolved
translate/public/translate.html Outdated Show resolved Hide resolved
translate/public/translate.html Outdated Show resolved Hide resolved
translate/public/translate.html Outdated Show resolved Hide resolved
pontoon/translate/views.py Outdated Show resolved Hide resolved
pontoon/contributors/templates/contributors/settings.html Outdated Show resolved Hide resolved
pontoon/settings/base.py Outdated Show resolved Hide resolved
pontoon/base/templates/base.html Outdated Show resolved Hide resolved
pontoon/base/static/js/theme-switcher.js Outdated Show resolved Hide resolved
pontoon/base/static/js/theme-switcher.js Outdated Show resolved Hide resolved
@mathjazz mathjazz marked this pull request as ready for review October 12, 2023 16:08
Copy link
Collaborator

@mathjazz mathjazz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just a couple of comments left!

What is the status of applying the theme in the translate view?

Please also look into the failing tests.

pontoon/contributors/templates/contributors/settings.html Outdated Show resolved Hide resolved
pontoon/base/templates/base.html Outdated Show resolved Hide resolved
pontoon/base/templates/base.html Outdated Show resolved Hide resolved
pontoon/base/templates/base.html Outdated Show resolved Hide resolved
translate/public/translate.html Outdated Show resolved Hide resolved
@mathjazz
Copy link
Collaborator

mathjazz commented Oct 17, 2023

Just noticed that the insights pages (e.g. http://localhost:8000/sl/insights/ and http://localhost:8000/projects/firefox/insights/ appear to be broken (JS error).

To fix that, we should use document.body (points to <body>) instead of document.documentElement (points to <html>) in places like:
https://github.com/mozilla/pontoon/blob/main/pontoon/insights/static/js/insights_tab.js#L7

And also get rid of trim() after style.getPropertyValue().

pontoon/base/templates/base.html Outdated Show resolved Hide resolved
translate/src/context/Theme.tsx Outdated Show resolved Hide resolved
translate/src/context/Theme.tsx Outdated Show resolved Hide resolved
translate/src/context/Theme.tsx Outdated Show resolved Hide resolved
@mathjazz
Copy link
Collaborator

Nice work with the updates!

  • I've kicked the pytest - I only have 3 failing tests locally.
  • As discussed, there is a JS error on the /profile when the system theme is selected. I'll take a look.

Copy link
Collaborator

@mathjazz mathjazz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great work - the core functionality is there!

Pytest is failing due to a conflicting migration. We have recently landed an existing migration 0047, so you'll need to rename yours to 0048 and update the dependency migration: pontoon/base/static/css/light-theme.css.

We also need to get rid of the eslint warnings.

pontoon/base/templates/base.html Outdated Show resolved Hide resolved
Copy link
Collaborator

@mathjazz mathjazz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Excellent job!

Now we need to fix the tests and possibly rebase and we're ready to merge.

@mathjazz
Copy link
Collaborator

mathjazz commented Oct 18, 2023

As discussed on Slack, we should probably revert the last commit and remove "theme" from the form.

As for the rebase, I suggest you create a fresh branch out of the current main, git apply the patch, remove the changes in the specs folder and push to a new PR.

@mathjazz mathjazz mentioned this pull request Oct 19, 2023
@mathjazz
Copy link
Collaborator

Works like a charm! Woohoo! 🥳

Continuing in #2996.

@mathjazz mathjazz closed this Oct 19, 2023
mathjazz added a commit that referenced this pull request Oct 19, 2023
Implements theme toggle in the /settings page.

Adds the light theme CSS file with the same values as in the dark theme CSS file.

Theme toggle in the Profile Menu and the actual light theme CSS file will be submitted in a followup.

---------

Co-authored-by: Ayanaa Rahman <ayanaa.rahman@mail.utoronto.ca>
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.

2 participants