AVGVSTVS96 / astroSite

Built with Astro and TailwindCSS, this MPA portfolio & blog site is version 3 of my personal website, my first MPA.
https://astrosite-aid.pages.dev/
GNU Affero General Public License v3.0
0 stars 0 forks source link

Investigate `AccentColorSelector` logic in conjunction with it's `BaseLayout` script #509

Open AVGVSTVS96 opened 3 months ago

AVGVSTVS96 commented 3 months ago
export const AccentColorSelector = () => {
  const isBrowser = typeof window !== 'undefined' && window.localStorage;
  const [selectedTheme, setSelectedTheme] = useState(() => {
    const storedTheme =
      isBrowser && window.localStorage.getItem('themeSwitcher');
    return storedTheme;
  });

  useEffect(() => {
    return () => {
      window.removeEventListener('storage', handleStorageChange);
    };
  }, []);

  const handleStorageChange = () => {
    const storedTheme = localStorage.getItem('themeSwitcher') || 'sky';

    if (isBrowser && storedTheme !== selectedTheme) {
      setSelectedTheme(storedTheme);
      document.documentElement.setAttribute('data-theme', storedTheme);
    }
  };

  isBrowser && window.addEventListener('storage', handleStorageChange);

  const handleThemeChange = (href: string) => {
    const theme = href.substring(1);
    setSelectedTheme(theme);
    localStorage.setItem('themeSwitcher', theme);
    document.documentElement.setAttribute('data-theme', theme);
  };
 </x-turndown>
  const storedThemeColor = localStorage.getItem('themeSwitcher');
  const theme = storedThemeColor || 'sky';
  document.documentElement.setAttribute('data-theme', theme);
linear[bot] commented 3 months ago

ASTRO-144 Investigate `AccentColorSelector` logic in conjunction with it's `BaseLayout` script