fix(theme): prevent special theme from persisting outside holiday period

This commit is contained in:
Tom (plebeius.eth)
2025-01-26 23:29:26 +01:00
parent 87aefc7ba1
commit 65ed3dffd5
2 changed files with 22 additions and 1 deletions
+2
View File
@@ -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]);
+20 -1
View File
@@ -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;
}
};
},
},
),
);