Skip to content

Commit

Permalink
automatically detect display mode
Browse files Browse the repository at this point in the history
  • Loading branch information
qrtp committed Jan 16, 2025
1 parent 984301a commit 9de4397
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 3 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
## 3.1.47
* Performance optimization
* Light mode / dark mode support
* Solana transaction history
* Bug fixes

## 3.1.46
Expand Down
14 changes: 11 additions & 3 deletions src/components/Root.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import {
ThemeMode,
WalletType,
} from "@unstoppabledomains/ui-components/styles/theme";
import {useMediaQuery} from "@unstoppabledomains/ui-kit";

import config from "../config";
import usePreferences from "../hooks/usePreferences";
Expand Down Expand Up @@ -147,6 +148,7 @@ const Root: React.FC = () => (

function RootApp() {
const {userId} = useUserId();
const isDarkModeSystemDefault = useMediaQuery("(prefers-color-scheme: dark)");
const [themeName, setThemeName] = useState<WalletType>();
const [themeMode, setThemeMode] = useState<ThemeMode>();
const [theme, setTheme] = useState<Theme>();
Expand All @@ -159,13 +161,19 @@ function RootApp() {
setThemeName(name);

// initialize the theme mode
const mode =
localStorage.getItem(themeModeKey) === "dark" ? "dark" : "light";
const userDefinedMode = localStorage.getItem(themeModeKey);
const mode = userDefinedMode
? userDefinedMode === "dark"
? "dark"
: "light"
: isDarkModeSystemDefault
? "dark"
: "light";
setThemeMode(mode);

// set initial theme
setTheme(getTheme(name, mode));
}, []);
}, [isDarkModeSystemDefault]);

// dynamically set the page theme
useEffect(() => {
Expand Down

0 comments on commit 9de4397

Please sign in to comment.