mirror of
https://github.com/bitsocialnet/5chan.git
synced 2026-08-03 07:41:04 +02:00
fix(theme): christmas theme should only run on dec 24 and 25
that's how 4chan does it, it makes sense since the theme is distracting especially on desktop
This commit is contained in:
@@ -9,6 +9,7 @@ import useInterfaceSettingsStore from '../../../stores/use-interface-settings-st
|
|||||||
import useCatalogFiltersStore from '../../../stores/use-catalog-filters-store';
|
import useCatalogFiltersStore from '../../../stores/use-catalog-filters-store';
|
||||||
import useExpandedMediaStore from '../../../stores/use-expanded-media-store';
|
import useExpandedMediaStore from '../../../stores/use-expanded-media-store';
|
||||||
import useSpecialThemeStore from '../../../stores/use-special-theme-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 commitRef = process.env.REACT_APP_COMMIT_REF;
|
||||||
const isElectron = window.isElectron === true;
|
const isElectron = window.isElectron === true;
|
||||||
@@ -71,10 +72,7 @@ const CheckForUpdates = () => {
|
|||||||
const Style = () => {
|
const Style = () => {
|
||||||
const [theme, setTheme] = useTheme();
|
const [theme, setTheme] = useTheme();
|
||||||
const { isEnabled, setIsEnabled } = useSpecialThemeStore();
|
const { isEnabled, setIsEnabled } = useSpecialThemeStore();
|
||||||
const today = new Date();
|
const isChristmasTime = isChristmas();
|
||||||
const month = today.getMonth();
|
|
||||||
const day = today.getDate();
|
|
||||||
const isChristmas = (month === 11 && day >= 24) || (month === 0 && day <= 5);
|
|
||||||
|
|
||||||
const handleThemeChange = (e: React.ChangeEvent<HTMLSelectElement>) => {
|
const handleThemeChange = (e: React.ChangeEvent<HTMLSelectElement>) => {
|
||||||
const newTheme = e.target.value;
|
const newTheme = e.target.value;
|
||||||
@@ -96,7 +94,7 @@ const Style = () => {
|
|||||||
<option value='burichan'>Burichan</option>
|
<option value='burichan'>Burichan</option>
|
||||||
<option value='tomorrow'>Tomorrow</option>
|
<option value='tomorrow'>Tomorrow</option>
|
||||||
<option value='photon'>Photon</option>
|
<option value='photon'>Photon</option>
|
||||||
{isChristmas && <option value='special'>Special</option>}
|
{isChristmasTime && <option value='special'>Special</option>}
|
||||||
</select>
|
</select>
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -7,6 +7,7 @@ import useInitialTheme from './use-initial-theme';
|
|||||||
import { nsfwTags } from '../views/home/home';
|
import { nsfwTags } from '../views/home/home';
|
||||||
import { useAccountComment } from '@plebbit/plebbit-react-hooks';
|
import { useAccountComment } from '@plebbit/plebbit-react-hooks';
|
||||||
import useSpecialThemeStore from '../stores/use-special-theme-store';
|
import useSpecialThemeStore from '../stores/use-special-theme-store';
|
||||||
|
import { isChristmas } from '../lib/utils/time-utils';
|
||||||
|
|
||||||
const themeClasses = ['yotsuba', 'yotsuba-b', 'futaba', 'burichan', 'tomorrow', 'photon'];
|
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
|
// Check for Christmas and initialize special theme if needed
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
const today = new Date();
|
const isChristmasTime = isChristmas();
|
||||||
const month = today.getMonth();
|
|
||||||
const day = today.getDate();
|
|
||||||
const isChristmas = (month === 11 && day >= 24) || (month === 0 && day <= 5);
|
|
||||||
const subplebbitAddress = params?.subplebbitAddress || pendingPostSubplebbitAddress;
|
const subplebbitAddress = params?.subplebbitAddress || pendingPostSubplebbitAddress;
|
||||||
|
|
||||||
if (isChristmas && isEnabled === null && subplebbitAddress && !isInAllView && !isInSubscriptionsView) {
|
if (isChristmasTime && isEnabled === null && subplebbitAddress && !isInAllView && !isInSubscriptionsView) {
|
||||||
setIsEnabled(true);
|
setIsEnabled(true);
|
||||||
setCurrentTheme('tomorrow');
|
setCurrentTheme('tomorrow');
|
||||||
updateThemeClass('tomorrow');
|
updateThemeClass('tomorrow');
|
||||||
} else if (!isChristmas && isEnabled) {
|
} else if (!isChristmasTime && isEnabled) {
|
||||||
setIsEnabled(false);
|
setIsEnabled(false);
|
||||||
}
|
}
|
||||||
}, [isEnabled, setIsEnabled, params, pendingPostSubplebbitAddress, location.pathname, isInAllView, isInSubscriptionsView]);
|
}, [isEnabled, setIsEnabled, params, pendingPostSubplebbitAddress, location.pathname, isInAllView, isInSubscriptionsView]);
|
||||||
|
|||||||
+1
-1
@@ -102,5 +102,5 @@ export const shouldShowSnow = (): boolean => {
|
|||||||
const today = new Date();
|
const today = new Date();
|
||||||
const month = today.getMonth();
|
const month = today.getMonth();
|
||||||
const day = today.getDate();
|
const day = today.getDate();
|
||||||
return (month === 11 && day >= 24) || (month === 0 && day <= 5);
|
return month === 11 && (day === 24 || day === 25);
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -68,3 +68,10 @@ export const getFormattedTimeAgo = (unixTimestamp: number): string => {
|
|||||||
}
|
}
|
||||||
return t('time_x_years_ago', { count: Math.floor(timeDifference / 31104000) });
|
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);
|
||||||
|
};
|
||||||
|
|||||||
@@ -1,18 +1,12 @@
|
|||||||
import { create } from 'zustand';
|
import { create } from 'zustand';
|
||||||
import { persist } from 'zustand/middleware';
|
import { persist } from 'zustand/middleware';
|
||||||
|
import { isChristmas } from '../lib/utils/time-utils';
|
||||||
|
|
||||||
interface SpecialThemeStore {
|
interface SpecialThemeStore {
|
||||||
isEnabled: boolean | null;
|
isEnabled: boolean | null;
|
||||||
setIsEnabled: (value: boolean) => void;
|
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(
|
const useSpecialThemeStore = create(
|
||||||
persist<SpecialThemeStore>(
|
persist<SpecialThemeStore>(
|
||||||
(set) => ({
|
(set) => ({
|
||||||
|
|||||||
Reference in New Issue
Block a user