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

Fix and unify theme retrieval #5651

Merged
merged 5 commits into from
Aug 15, 2022
Merged

Fix and unify theme retrieval #5651

merged 5 commits into from
Aug 15, 2022

Conversation

brianpeiris
Copy link
Contributor

@brianpeiris brianpeiris commented Aug 10, 2022

This builds on top of #4332 and unifies theme retrieval and theme switching into helpers that live in src/utils/theme.js. Tested this in local dev and against a remote hubs cloud instance.

  • Adds an onThemeChanged helper that listens to both hubs preference changes and browser/system dark mode changes
    • This helper returns a cleanup function that can be called to remove the event listener
  • Adds a getThemeColor helper which can retrieve a single color.
  • Adds a registerDarkModeQuery helper which takes a listener, and returns the dark mode query, and a function to remove the listener.
  • Moves a bunch of config and theme related logic from src/react-components/styles/theme.js to src/utils/theme.js, for reuse
  • Moves the themes array export from src/react-components/styles/theme.js to src/utils/theme.js, so that it can be used more broadly
  • Updates sprites.js, avatar-preview.js, and pin-networked-object-button.js to use the new onThemeChanged helper, so that they update immediately when dark mode is changed at the browser or system level, in addition to theme preference changes.
  • Add an eslint exception to ignore destructured variables that begin with "_"

src/utils/theme.js Outdated Show resolved Hide resolved
@brianpeiris brianpeiris merged commit a6f44a9 into master Aug 15, 2022
@brianpeiris brianpeiris deleted the fix-themes-improved branch August 15, 2022 19:56
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.

None yet

3 participants