-
Notifications
You must be signed in to change notification settings - Fork 16
Centralize the app's theme and reorder the Reduce/Verify panes #223
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
Merged
Merged
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
5744f9c
Move Reduce pane below Verify
Trosper3 6aae276
Match /browse's theme to the app's orange/grey/white palette
Trosper3 0606b68
Centralize the app's theme; fix home page's missing background
Trosper3 aa4e35a
Add app-wide light/dark mode toggle
Trosper3 16f426f
Fix remaining dark-mode readability issues across the home page
Trosper3 1154da4
Merge remote-tracking branch 'origin/theme/combined-theming-bundle' i…
Trosper3 b8dbf27
Merge remote-tracking branch 'origin/task/move-reduce-below-verify' i…
Trosper3 afb53ca
Suppress react-hooks/set-state-in-effect in ThemeModeContext with jus…
Trosper3 349167d
Merge remote-tracking branch 'origin/ReduxAPI_GUI' into theme-and-lay…
Trosper3 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,63 @@ | ||
| /** | ||
| * ThemeModeContext.js | ||
| * | ||
| * App-wide light/dark mode state, wired in once at pages/_app.js so every | ||
| * page shares the same theme instance and the toggle in ResponsiveAppBar can | ||
| * flip it everywhere at once. Persisted to localStorage; defaults to light | ||
| * on first visit and while the persisted value hasn't loaded yet server-side | ||
| * (localStorage isn't available during SSR, so the very first client render | ||
| * always starts light too, then switches after mount if "dark" was saved -- | ||
| * a brief flash for returning dark-mode users, not worth a blocking | ||
| * SSR/cookie script for a research tool's admin toggle). | ||
| */ | ||
|
|
||
| import { CssBaseline, ThemeProvider } from "@mui/material"; | ||
| import { createContext, useContext, useEffect, useMemo, useState } from "react"; | ||
| import { createAppTheme } from "./theme"; | ||
|
|
||
| const STORAGE_KEY = "redux-theme-mode"; | ||
|
|
||
| const ThemeModeContext = createContext({ | ||
| mode: "light", | ||
| toggleMode: () => {}, | ||
| }); | ||
|
|
||
| export function ThemeModeProvider({ children }) { | ||
| const [mode, setMode] = useState("light"); | ||
|
|
||
| useEffect(() => { | ||
| // Deliberately read-then-setState here, not moved into a useState lazy initializer: | ||
| // localStorage isn't available during SSR, so the server always renders "light". Reading | ||
| // it in the initializer would make the client's first (pre-hydration) render read real | ||
| // localStorage and could produce "dark" while the server-rendered HTML says "light" -- | ||
| // a hydration mismatch, which is worse than this rule's generic extra-render concern. | ||
| const saved = window.localStorage.getItem(STORAGE_KEY); | ||
| if (saved === "light" || saved === "dark") { | ||
| // eslint-disable-next-line react-hooks/set-state-in-effect | ||
| setMode(saved); | ||
| } | ||
| }, []); | ||
|
|
||
| const toggleMode = () => { | ||
| setMode((current) => { | ||
| const next = current === "light" ? "dark" : "light"; | ||
| window.localStorage.setItem(STORAGE_KEY, next); | ||
| return next; | ||
| }); | ||
| }; | ||
|
|
||
| const theme = useMemo(() => createAppTheme(mode), [mode]); | ||
|
|
||
| return ( | ||
| <ThemeModeContext.Provider value={{ mode, toggleMode }}> | ||
| <ThemeProvider theme={theme}> | ||
| <CssBaseline /> | ||
| {children} | ||
| </ThemeProvider> | ||
| </ThemeModeContext.Provider> | ||
| ); | ||
| } | ||
|
|
||
| export function useThemeMode() { | ||
| return useContext(ThemeModeContext); | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.