fix changing many themes quickly bugged out

This commit is contained in:
Tom (plebeius.eth)
2024-06-22 12:43:37 +02:00
parent 032ba62cbe
commit dc4416880e
+7 -5
View File
@@ -4,8 +4,10 @@ import { isAllView, isSubscriptionsView } from '../lib/utils/view-utils';
import useThemeStore from '../stores/use-theme-store'; import useThemeStore from '../stores/use-theme-store';
import useInitialTheme from './use-initial-theme'; import useInitialTheme from './use-initial-theme';
const themeClasses = ['yotsuba', 'yotsuba-b', 'futaba', 'burichan', 'tomorrow', 'photon'];
const updateThemeClass = (newTheme: string) => { const updateThemeClass = (newTheme: string) => {
document.body.classList.remove('yotsuba', 'yotsuba-b', 'futaba', 'burichan', 'tomorrow', 'photon'); document.body.classList.remove(...themeClasses);
if (newTheme) { if (newTheme) {
document.body.classList.add(newTheme); document.body.classList.add(newTheme);
} }
@@ -52,17 +54,17 @@ const useTheme = (): [string, (theme: string) => void] => {
updateThemeClass(themeToSet); updateThemeClass(themeToSet);
}, [initialTheme, location.pathname, params, getTheme, themesLoaded]); }, [initialTheme, location.pathname, params, getTheme, themesLoaded]);
const setSubplebbitTheme = (newTheme: string) => { const setSubplebbitTheme = async (newTheme: string) => {
const subplebbitAddress = params?.subplebbitAddress; const subplebbitAddress = params?.subplebbitAddress;
const isInAllView = isAllView(location.pathname, params); const isInAllView = isAllView(location.pathname, params);
const isInSubscriptionsView = isSubscriptionsView(location.pathname, params); const isInSubscriptionsView = isSubscriptionsView(location.pathname, params);
if (subplebbitAddress) { if (subplebbitAddress) {
setThemeStore(subplebbitAddress, newTheme); await setThemeStore(subplebbitAddress, newTheme);
} else if (isInAllView) { } else if (isInAllView) {
setThemeStore('all', newTheme); await setThemeStore('all', newTheme);
} else if (isInSubscriptionsView) { } else if (isInSubscriptionsView) {
setThemeStore('subscriptions', newTheme); await setThemeStore('subscriptions', newTheme);
} }
setLocalTheme(newTheme); setLocalTheme(newTheme);