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 useInitialTheme from './use-initial-theme';
|
||||
|
||||
const themeClasses = ['yotsuba', 'yotsuba-b', 'futaba', 'burichan', 'tomorrow', 'photon'];
|
||||
|
||||
const updateThemeClass = (newTheme: string) => {
|
||||
document.body.classList.remove('yotsuba', 'yotsuba-b', 'futaba', 'burichan', 'tomorrow', 'photon');
|
||||
document.body.classList.remove(...themeClasses);
|
||||
if (newTheme) {
|
||||
document.body.classList.add(newTheme);
|
||||
}
|
||||
@@ -52,17 +54,17 @@ const useTheme = (): [string, (theme: string) => void] => {
|
||||
updateThemeClass(themeToSet);
|
||||
}, [initialTheme, location.pathname, params, getTheme, themesLoaded]);
|
||||
|
||||
const setSubplebbitTheme = (newTheme: string) => {
|
||||
const setSubplebbitTheme = async (newTheme: string) => {
|
||||
const subplebbitAddress = params?.subplebbitAddress;
|
||||
const isInAllView = isAllView(location.pathname, params);
|
||||
const isInSubscriptionsView = isSubscriptionsView(location.pathname, params);
|
||||
|
||||
if (subplebbitAddress) {
|
||||
setThemeStore(subplebbitAddress, newTheme);
|
||||
await setThemeStore(subplebbitAddress, newTheme);
|
||||
} else if (isInAllView) {
|
||||
setThemeStore('all', newTheme);
|
||||
await setThemeStore('all', newTheme);
|
||||
} else if (isInSubscriptionsView) {
|
||||
setThemeStore('subscriptions', newTheme);
|
||||
await setThemeStore('subscriptions', newTheme);
|
||||
}
|
||||
|
||||
setLocalTheme(newTheme);
|
||||
|
||||
Reference in New Issue
Block a user