spacedrive/interface/hooks/useTheme.ts

58 lines
1.6 KiB
TypeScript
Raw Normal View History

import { useEffect } from 'react';
import { useThemeStore } from '@sd/client';
[ENG-640, ENG-695, ENG-705, ENG-693] Categories arrow buttons + others (#851) * Overview categories arrow buttons * Hide indexer rules in location + category arrow buttons * Added masking on left and right of categories * Expose lock_app_theme function to frontend * Allow lockAppTheme to reset back to auto theme * Fixes, progress bar color, useTheme update, shrink-0 for arrow button * Only show fadeout if scrolled, onboarding css tweaks * Framer hook unstable, motion divs to handle last category entry is much better * Fix color picker closing * Remove ref that is no longer needed * Fix swift theme updating * cleanup * Overview categories arrow buttons and fixes Added masking on left and right of categories [HOTFIX] Remove placeholder nodes (#913) Update LibrarySection.tsx [ENG-694] Remove Spacedrop (#914) * goodbye Spacedrop * fix startup error escaping * fix error fallback being cringe with long error * backwards compatibility for early adopters [ENG-697] Fix rename library (#916) * random stuff * How have we had a deadlock for 2 months lol [ENG-701] Add explorer top bar options to tags (#918) Add top bar options [ENG-679] Reserve ids for built in indexer rules (#909) * indexer rules pub ids * should work? * better migrator * errors * debugging * maybe? * double migrate * please * maybe fix? * update lockfile * SD_ACCEPT_DATA_LOSS message * put tracing back * dumb * fix system indexer rule ui fix(interface): quick preview not closing with SPACE (#921) Co-authored-by: Utku <74243531+utkubakir@users.noreply.github.com> [ENG-700] Add empty notice to tags (#922) Add empty notice to tags [ENG-707] Fix list item bg color (#924) Fix list item bg color [ENG-706] Add deselect explorer view items (#923) Add deselect Expose lock_app_theme function to frontend Allow lockAppTheme to reset back to auto theme Fixes, progress bar color, useTheme update, shrink-0 for arrow button Only show fadeout if scrolled, onboarding css tweaks Framer hook unstable, motion divs to handle last category entry is much better Fix color picker closing Remove ref that is no longer needed Fix swift theme updating * cleanup * Update pnpm-lock.yaml * fix types & upgrade typescript version to 5.0.4 * fix folder icon * remove rust comment * remove mask * masking tweak --------- Co-authored-by: Vítor Vasconcellos <vasconcellos.dev@gmail.com> Co-authored-by: nikec <nikec.job@gmail.com> Co-authored-by: Utku Bakir <74243531+utkubakir@users.noreply.github.com>
2023-06-10 12:25:46 +00:00
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]);
}