mirror of
https://github.com/kremalicious/umami.git
synced 2025-02-01 20:39:44 +01:00
Updated theme check.
This commit is contained in:
parent
c69a703c7f
commit
902d4c83ba
@ -1,19 +1,13 @@
|
|||||||
import { useEffect } from 'react';
|
import { useEffect } from 'react';
|
||||||
import useStore, { setTheme } from 'store/app';
|
import useStore, { setTheme } from 'store/app';
|
||||||
import { getItem, setItem } from 'next-basics';
|
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';
|
import { colord } from 'colord';
|
||||||
|
|
||||||
const selector = (state: { theme: string }) => state.theme;
|
const selector = (state: { theme: string }) => state.theme;
|
||||||
|
|
||||||
export function useTheme() {
|
export function useTheme() {
|
||||||
const defaultTheme =
|
const theme = useStore(selector) || getItem(THEME_CONFIG) || DEFAULT_THEME;
|
||||||
typeof window !== 'undefined'
|
|
||||||
? window?.matchMedia('(prefers-color-scheme: dark)')?.matches
|
|
||||||
? 'dark'
|
|
||||||
: 'light'
|
|
||||||
: 'light';
|
|
||||||
const theme = useStore(selector) || getItem(THEME_CONFIG) || defaultTheme;
|
|
||||||
const primaryColor = colord(THEME_COLORS[theme].primary);
|
const primaryColor = colord(THEME_COLORS[theme].primary);
|
||||||
|
|
||||||
const colors = {
|
const colors = {
|
||||||
|
@ -9,9 +9,17 @@ import {
|
|||||||
} from 'lib/constants';
|
} from 'lib/constants';
|
||||||
import { getItem } from 'next-basics';
|
import { getItem } from 'next-basics';
|
||||||
|
|
||||||
|
function getDefaultTheme() {
|
||||||
|
return typeof window !== 'undefined'
|
||||||
|
? window?.matchMedia('(prefers-color-scheme: dark)')?.matches
|
||||||
|
? 'dark'
|
||||||
|
: 'light'
|
||||||
|
: 'light';
|
||||||
|
}
|
||||||
|
|
||||||
const initialState = {
|
const initialState = {
|
||||||
locale: getItem(LOCALE_CONFIG) || DEFAULT_LOCALE,
|
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,
|
dateRange: getItem(DATE_RANGE_CONFIG) || DEFAULT_DATE_RANGE,
|
||||||
shareToken: null,
|
shareToken: null,
|
||||||
user: null,
|
user: null,
|
||||||
|
Loading…
Reference in New Issue
Block a user