hubs
hubs copied to clipboard
Fix and unify theme retrieval
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
onThemeChangedhelper 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
getThemeColorhelper which can retrieve a single color. - Adds a
registerDarkModeQueryhelper 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.jstosrc/utils/theme.js, for reuse - Moves the
themesarray export fromsrc/react-components/styles/theme.jstosrc/utils/theme.js, so that it can be used more broadly - Updates
sprites.js,avatar-preview.js, andpin-networked-object-button.jsto use the newonThemeChangedhelper, 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 "_"