mirror of
https://github.com/bitsocialnet/5chan.git
synced 2026-08-03 07:41:04 +02:00
fix(theme): prevent special theme from persisting outside holiday period
This commit is contained in:
@@ -49,6 +49,8 @@ const useTheme = (): [string, (theme: string) => void] => {
|
||||
setIsEnabled(true);
|
||||
setCurrentTheme('tomorrow');
|
||||
updateThemeClass('tomorrow');
|
||||
} else if (!isChristmas && isEnabled) {
|
||||
setIsEnabled(false);
|
||||
}
|
||||
}, [isEnabled, setIsEnabled, params, pendingPostSubplebbitAddress, location.pathname, isInAllView, isInSubscriptionsView]);
|
||||
|
||||
|
||||
@@ -6,14 +6,33 @@ interface SpecialThemeStore {
|
||||
setIsEnabled: (value: boolean) => void;
|
||||
}
|
||||
|
||||
const isChristmas = () => {
|
||||
const today = new Date();
|
||||
const month = today.getMonth();
|
||||
const day = today.getDate();
|
||||
return (month === 11 && day >= 24) || (month === 0 && day <= 5);
|
||||
};
|
||||
|
||||
const useSpecialThemeStore = create(
|
||||
persist<SpecialThemeStore>(
|
||||
(set) => ({
|
||||
isEnabled: null,
|
||||
setIsEnabled: (value: boolean) => set({ isEnabled: value }),
|
||||
setIsEnabled: (value: boolean) => {
|
||||
if (value && !isChristmas()) {
|
||||
return;
|
||||
}
|
||||
set({ isEnabled: value });
|
||||
},
|
||||
}),
|
||||
{
|
||||
name: 'Special-theme-storage',
|
||||
onRehydrateStorage: () => {
|
||||
return (state) => {
|
||||
if (state && !isChristmas()) {
|
||||
state.isEnabled = null;
|
||||
}
|
||||
};
|
||||
},
|
||||
},
|
||||
),
|
||||
);
|
||||
|
||||
Reference in New Issue
Block a user