diff --git a/src/components/settings-modal/interface-settings/interface-settings.tsx b/src/components/settings-modal/interface-settings/interface-settings.tsx index 6863a98e..67aef408 100644 --- a/src/components/settings-modal/interface-settings/interface-settings.tsx +++ b/src/components/settings-modal/interface-settings/interface-settings.tsx @@ -9,6 +9,7 @@ import useInterfaceSettingsStore from '../../../stores/use-interface-settings-st import useCatalogFiltersStore from '../../../stores/use-catalog-filters-store'; import useExpandedMediaStore from '../../../stores/use-expanded-media-store'; import useSpecialThemeStore from '../../../stores/use-special-theme-store'; +import { isChristmas } from '../../../lib/utils/time-utils'; const commitRef = process.env.REACT_APP_COMMIT_REF; const isElectron = window.isElectron === true; @@ -71,10 +72,7 @@ const CheckForUpdates = () => { const Style = () => { const [theme, setTheme] = useTheme(); const { isEnabled, setIsEnabled } = useSpecialThemeStore(); - const today = new Date(); - const month = today.getMonth(); - const day = today.getDate(); - const isChristmas = (month === 11 && day >= 24) || (month === 0 && day <= 5); + const isChristmasTime = isChristmas(); const handleThemeChange = (e: React.ChangeEvent) => { const newTheme = e.target.value; @@ -96,7 +94,7 @@ const Style = () => { - {isChristmas && } + {isChristmasTime && } ); }; diff --git a/src/hooks/use-theme.ts b/src/hooks/use-theme.ts index 0214253c..346998c0 100644 --- a/src/hooks/use-theme.ts +++ b/src/hooks/use-theme.ts @@ -7,6 +7,7 @@ import useInitialTheme from './use-initial-theme'; import { nsfwTags } from '../views/home/home'; import { useAccountComment } from '@plebbit/plebbit-react-hooks'; import useSpecialThemeStore from '../stores/use-special-theme-store'; +import { isChristmas } from '../lib/utils/time-utils'; const themeClasses = ['yotsuba', 'yotsuba-b', 'futaba', 'burichan', 'tomorrow', 'photon']; @@ -39,17 +40,14 @@ const useTheme = (): [string, (theme: string) => void] => { // Check for Christmas and initialize special theme if needed useEffect(() => { - const today = new Date(); - const month = today.getMonth(); - const day = today.getDate(); - const isChristmas = (month === 11 && day >= 24) || (month === 0 && day <= 5); + const isChristmasTime = isChristmas(); const subplebbitAddress = params?.subplebbitAddress || pendingPostSubplebbitAddress; - if (isChristmas && isEnabled === null && subplebbitAddress && !isInAllView && !isInSubscriptionsView) { + if (isChristmasTime && isEnabled === null && subplebbitAddress && !isInAllView && !isInSubscriptionsView) { setIsEnabled(true); setCurrentTheme('tomorrow'); updateThemeClass('tomorrow'); - } else if (!isChristmas && isEnabled) { + } else if (!isChristmasTime && isEnabled) { setIsEnabled(false); } }, [isEnabled, setIsEnabled, params, pendingPostSubplebbitAddress, location.pathname, isInAllView, isInSubscriptionsView]); diff --git a/src/lib/snow.ts b/src/lib/snow.ts index f6385516..b7079b81 100644 --- a/src/lib/snow.ts +++ b/src/lib/snow.ts @@ -102,5 +102,5 @@ export const shouldShowSnow = (): boolean => { const today = new Date(); const month = today.getMonth(); const day = today.getDate(); - return (month === 11 && day >= 24) || (month === 0 && day <= 5); + return month === 11 && (day === 24 || day === 25); }; diff --git a/src/lib/utils/time-utils.ts b/src/lib/utils/time-utils.ts index 5c332bd8..8ecda623 100644 --- a/src/lib/utils/time-utils.ts +++ b/src/lib/utils/time-utils.ts @@ -68,3 +68,10 @@ export const getFormattedTimeAgo = (unixTimestamp: number): string => { } return t('time_x_years_ago', { count: Math.floor(timeDifference / 31104000) }); }; + +export const isChristmas = (): boolean => { + const today = new Date(); + const month = today.getMonth(); + const day = today.getDate(); + return month === 11 && (day === 24 || day === 25); +}; diff --git a/src/stores/use-special-theme-store.ts b/src/stores/use-special-theme-store.ts index 2378e8a5..535b1f06 100644 --- a/src/stores/use-special-theme-store.ts +++ b/src/stores/use-special-theme-store.ts @@ -1,18 +1,12 @@ import { create } from 'zustand'; import { persist } from 'zustand/middleware'; +import { isChristmas } from '../lib/utils/time-utils'; interface SpecialThemeStore { isEnabled: boolean | null; 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( (set) => ({