mirror of
https://github.com/bitsocialnet/5chan.git
synced 2026-08-03 07:41:04 +02:00
fix(use-theme): body css would bug out on navigation
This commit is contained in:
@@ -2,7 +2,7 @@ import { useState, useEffect } from 'react';
|
|||||||
import { useLocation, useParams } from 'react-router-dom';
|
import { useLocation, useParams } from 'react-router-dom';
|
||||||
import { isAllView, isSubscriptionsView } from '../lib/utils/view-utils';
|
import { isAllView, isSubscriptionsView } from '../lib/utils/view-utils';
|
||||||
import useThemeStore from '../stores/use-theme-store';
|
import useThemeStore from '../stores/use-theme-store';
|
||||||
import determineInitialTheme from './use-initial-theme';
|
import useInitialTheme from './use-initial-theme';
|
||||||
|
|
||||||
const useTheme = (): [string, (theme: string) => void] => {
|
const useTheme = (): [string, (theme: string) => void] => {
|
||||||
const location = useLocation();
|
const location = useLocation();
|
||||||
@@ -20,14 +20,18 @@ const useTheme = (): [string, (theme: string) => void] => {
|
|||||||
load();
|
load();
|
||||||
}, [loadThemes]);
|
}, [loadThemes]);
|
||||||
|
|
||||||
const initialTheme = determineInitialTheme();
|
const initialTheme = useInitialTheme();
|
||||||
|
|
||||||
const [theme, setLocalTheme] = useState(initialTheme);
|
const [theme, setLocalTheme] = useState(initialTheme);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
|
const previousTheme = document.body.className;
|
||||||
document.body.classList.add(initialTheme);
|
document.body.classList.add(initialTheme);
|
||||||
return () => {
|
return () => {
|
||||||
document.body.classList.remove(initialTheme);
|
document.body.classList.remove(initialTheme);
|
||||||
|
if (previousTheme) {
|
||||||
|
document.body.classList.add(previousTheme);
|
||||||
|
}
|
||||||
};
|
};
|
||||||
}, [initialTheme]);
|
}, [initialTheme]);
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user