mirror of
https://github.com/bitsocialnet/5chan.git
synced 2026-08-03 07:41:04 +02:00
feat(theme): add halloween special theme
This commit is contained in:
@@ -104,7 +104,7 @@ describe('persisted extra stores', () => {
|
||||
expect(useModQueueStore.getState().getAlertThresholdSeconds()).toBe(900);
|
||||
});
|
||||
|
||||
it('blocks special theme enablement outside christmas and clears persisted enabled state on rehydrate', async () => {
|
||||
it('blocks special theme enablement outside active special dates and clears persisted enabled state on rehydrate', async () => {
|
||||
localStorage.setItem(
|
||||
'Special-theme-storage',
|
||||
JSON.stringify({
|
||||
@@ -121,12 +121,20 @@ describe('persisted extra stores', () => {
|
||||
expect(useSpecialThemeStore.getState().isEnabled).toBeNull();
|
||||
});
|
||||
|
||||
it('allows opting into the special theme during christmas', async () => {
|
||||
it('allows opting into the special theme during christmas and halloween', async () => {
|
||||
const useSpecialThemeStore = await loadSpecialThemeStore('2024-12-24T00:00:00Z');
|
||||
|
||||
expect(useSpecialThemeStore.getState().isEnabled).toBeNull();
|
||||
|
||||
useSpecialThemeStore.getState().setIsEnabled(true);
|
||||
expect(useSpecialThemeStore.getState().isEnabled).toBe(true);
|
||||
|
||||
localStorage.clear();
|
||||
const useHalloweenSpecialThemeStore = await loadSpecialThemeStore('2024-10-31T00:00:00Z');
|
||||
|
||||
expect(useHalloweenSpecialThemeStore.getState().isEnabled).toBeNull();
|
||||
|
||||
useHalloweenSpecialThemeStore.getState().setIsEnabled(true);
|
||||
expect(useHalloweenSpecialThemeStore.getState().isEnabled).toBe(true);
|
||||
});
|
||||
});
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import { create } from 'zustand';
|
||||
import { persist } from 'zustand/middleware';
|
||||
import { isChristmas } from '../lib/utils/time-utils';
|
||||
import { getActiveSpecialTheme } from '../lib/utils/time-utils';
|
||||
|
||||
interface SpecialThemeStore {
|
||||
isEnabled: boolean | null;
|
||||
@@ -12,7 +12,7 @@ const useSpecialThemeStore = create(
|
||||
(set) => ({
|
||||
isEnabled: null,
|
||||
setIsEnabled: (value: boolean) => {
|
||||
if (value && !isChristmas()) {
|
||||
if (value && !getActiveSpecialTheme()) {
|
||||
return;
|
||||
}
|
||||
set({ isEnabled: value });
|
||||
@@ -22,7 +22,7 @@ const useSpecialThemeStore = create(
|
||||
name: 'Special-theme-storage',
|
||||
onRehydrateStorage: () => {
|
||||
return (state) => {
|
||||
if (state && !isChristmas()) {
|
||||
if (state && !getActiveSpecialTheme()) {
|
||||
state.isEnabled = null;
|
||||
}
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user