Skip to content

armgit / umami

Public Imported from GitHub
0

Umami is a privacy-first web and product analytics platform. Traffic, campaigns, behavior, conversions, and revenue in one place. No cookies, no surveillance, self-hosted or in the cloud.

Updated theme check.

Mike Cao902d4c83bab9
diff --git a/src/components/hooks/useTheme.ts b/src/components/hooks/useTheme.ts
index 099bf962b..f2a2d448b 100644
--- a/src/components/hooks/useTheme.ts
+++ b/src/components/hooks/useTheme.ts
@@ -1,19 +1,13 @@
import { useEffect } from 'react';
import useStore, { setTheme } from 'store/app';
import { getItem, setItem } from 'next-basics';
-import { THEME_COLORS, THEME_CONFIG } from 'lib/constants';
+import { DEFAULT_THEME, THEME_COLORS, THEME_CONFIG } from 'lib/constants';
import { colord } from 'colord';
const selector = (state: { theme: string }) => state.theme;
export function useTheme() {
- const defaultTheme =
- typeof window !== 'undefined'
- ? window?.matchMedia('(prefers-color-scheme: dark)')?.matches
- ? 'dark'
- : 'light'
- : 'light';
- const theme = useStore(selector) || getItem(THEME_CONFIG) || defaultTheme;
+ const theme = useStore(selector) || getItem(THEME_CONFIG) || DEFAULT_THEME;
const primaryColor = colord(THEME_COLORS[theme].primary);
const colors = {
diff --git a/src/store/app.ts b/src/store/app.ts
index 8fa1a0d5b..cbd2ac2de 100644
--- a/src/store/app.ts
+++ b/src/store/app.ts
@@ -9,9 +9,17 @@ import {
} from 'lib/constants';
import { getItem } from 'next-basics';
+function getDefaultTheme() {
+ return typeof window !== 'undefined'
+ ? window?.matchMedia('(prefers-color-scheme: dark)')?.matches
+ ? 'dark'
+ : 'light'
+ : 'light';
+}
+
const initialState = {
locale: getItem(LOCALE_CONFIG) || DEFAULT_LOCALE,
- theme: getItem(THEME_CONFIG) || DEFAULT_THEME,
+ theme: getItem(THEME_CONFIG) || getDefaultTheme() || DEFAULT_THEME,
dateRange: getItem(DATE_RANGE_CONFIG) || DEFAULT_DATE_RANGE,
shareToken: null,
user: null,