mirror of
https://github.com/bitsocialnet/5chan.git
synced 2026-08-03 07:41:04 +02:00
fix changing many themes quickly bugged out
This commit is contained in:
@@ -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);
|
||||||
|
|||||||
Reference in New Issue
Block a user