mirror of
https://github.com/spacedriveapp/spacedrive
synced 2024-07-07 02:03:28 +00:00
f7cd96732f
* `createSolid` + `createPersistedMutable` * Move all Valtio stores to SolidJS * Remove Valtio from `@sd/client` * Missed auth store * wip * `useSolidStore` allow mutable setting * Restructure `@sd/client` a bit * Add `WithSolid` + custom `useObserver` * Parse props both ways * Universal Context * Solid to React context working * Working universal context * context inheritance * whoops * Make it clearer how the demo works * wip: `useUniversalQuery`
58 lines
1.6 KiB
TypeScript
58 lines
1.6 KiB
TypeScript
import { useEffect } from 'react';
|
|
import { useThemeStore } from '@sd/client';
|
|
|
|
import { usePlatform } from '..';
|
|
|
|
export function useTheme() {
|
|
const themeStore = useThemeStore();
|
|
const { lockAppTheme } = usePlatform();
|
|
const systemTheme = window.matchMedia('(prefers-color-scheme: dark)');
|
|
|
|
useEffect(() => {
|
|
const handleThemeChange = () => {
|
|
if (themeStore.syncThemeWithSystem) {
|
|
lockAppTheme?.('Auto');
|
|
if (systemTheme.matches) {
|
|
document.documentElement.classList.remove('vanilla-theme');
|
|
document.documentElement.style.setProperty(
|
|
'--dark-hue',
|
|
themeStore.hueValue.toString()
|
|
);
|
|
themeStore.theme = 'dark';
|
|
} else {
|
|
document.documentElement.classList.add('vanilla-theme');
|
|
document.documentElement.style.setProperty(
|
|
'--light-hue',
|
|
themeStore.hueValue.toString()
|
|
);
|
|
themeStore.theme = 'vanilla';
|
|
}
|
|
} else {
|
|
if (themeStore.theme === 'dark') {
|
|
document.documentElement.classList.remove('vanilla-theme');
|
|
document.documentElement.style.setProperty(
|
|
'--dark-hue',
|
|
themeStore.hueValue.toString()
|
|
);
|
|
lockAppTheme?.('Dark');
|
|
} else if (themeStore.theme === 'vanilla') {
|
|
document.documentElement.classList.add('vanilla-theme');
|
|
document.documentElement.style.setProperty(
|
|
'--light-hue',
|
|
themeStore.hueValue.toString()
|
|
);
|
|
lockAppTheme?.('Light');
|
|
}
|
|
}
|
|
};
|
|
|
|
handleThemeChange();
|
|
|
|
systemTheme.addEventListener('change', handleThemeChange);
|
|
|
|
return () => {
|
|
systemTheme.removeEventListener('change', handleThemeChange);
|
|
};
|
|
}, [themeStore, lockAppTheme, systemTheme]);
|
|
}
|