Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 11 additions & 4 deletions src/pages/games/SnackGame/game/hook/useNoticeModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,10 @@ import ImageWithFallback from '@components/ImageWithFallback/ImageWithFallback';
import { KEY_LAST_NOTICE_INFO } from '@constants/localStorage.constant';
import useModal from '@hooks/useModal';

// notice_YYYYMMDD_keyword(_version)
const CURRENT_ID = 'notice_20250710_bomb';
const NOTICE_CONFIG = {
id: 'notice_2025-07-10_bomb',
expireDate: '2025-07-17T23:59:59+09:00',
} as const;
Comment thread
nijuy marked this conversation as resolved.

const Notice = () => {
const { closeModal } = useModal();
Expand All @@ -18,7 +20,7 @@ const Notice = () => {
localStorage.setItem(
KEY_LAST_NOTICE_INFO,
JSON.stringify({
id: CURRENT_ID,
id: NOTICE_CONFIG.id,
hideUntil: new Date(Date.now() + ONE_DAY),
}),
);
Expand Down Expand Up @@ -63,14 +65,19 @@ const Notice = () => {
export const useNoticeModal = () => {
const { openModal } = useModal();

const isNoticeExpired = () => {
return new Date() > new Date(NOTICE_CONFIG.expireDate);
};
Comment thread
nijuy marked this conversation as resolved.

const isNoticeHidden = () => {
const lastNotice = localStorage.getItem(KEY_LAST_NOTICE_INFO);
const { id, hideUntil } = lastNotice ? JSON.parse(lastNotice) : {};

return id === CURRENT_ID && new Date(hideUntil) > new Date();
return id === NOTICE_CONFIG.id && new Date(hideUntil) > new Date();
};

const openNoticeModal = () => {
if (isNoticeExpired()) return;
if (isNoticeHidden()) return;

openModal({
Expand Down
Loading