From c00623e6904f8e592a57676427ca5eea15f3dd59 Mon Sep 17 00:00:00 2001 From: Mina Choi Date: Wed, 7 Oct 2026 20:57:50 +0900 Subject: [PATCH] =?UTF-8?q?fix:=20=EA=B3=A0=EB=A5=B8=20=EC=8B=9C=EA=B0=84?= =?UTF-8?q?=EB=8C=80=20=EB=B0=B0=EA=B2=BD=EC=9D=84=20=EC=84=B8=EC=85=98=20?= =?UTF-8?q?=EC=A0=80=EC=9E=A5=EC=86=8C=EC=97=90=20=EB=91=90=EC=96=B4=20?= =?UTF-8?q?=ED=83=AD=EC=9D=84=20=EC=98=AE=EA=B2=A8=EB=8F=84=20=EC=9C=A0?= =?UTF-8?q?=EC=A7=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- frontend/src/b/BLayout.tsx | 30 +++++++++++++++++++++++++++--- frontend/src/b/TodayPage.tsx | 7 +++---- frontend/src/b/skyContext.ts | 4 ++-- 3 files changed, 32 insertions(+), 9 deletions(-) diff --git a/frontend/src/b/BLayout.tsx b/frontend/src/b/BLayout.tsx index 25fc4f5..63ef3a2 100644 --- a/frontend/src/b/BLayout.tsx +++ b/frontend/src/b/BLayout.tsx @@ -1,4 +1,4 @@ -import { useEffect, useMemo, useState, type ReactNode } from 'react' +import { useCallback, useEffect, useMemo, useState, type ReactNode } from 'react' import { NavLink, Outlet, useLocation } from 'react-router' import { cx } from '../lib/utils' import { kindOfHour, kst, type TimeKind } from './lib' @@ -103,8 +103,32 @@ function SkyBg() { ) } +const PREVIEW_KEY = 'nalssigak.b.skyPreview' +const KINDS: readonly string[] = ['morning', 'day', 'sunset', 'night'] satisfies TimeKind[] + +function readPreview(): TimeKind | null { + try { + const v = sessionStorage.getItem(PREVIEW_KEY) + return v && KINDS.includes(v) ? (v as TimeKind) : null + } catch { + // 저장소가 막힌 브라우저는 '지금'으로 시작한다 + return null + } +} + function SkyProvider({ children }: { children: ReactNode }) { - const [preview, setPreview] = useState(null) + // 고른 시간대는 탭을 옮겨도 이 창에서 유지한다 + const [preview, setPreviewState] = useState(readPreview) + const setPreview = useCallback((k: TimeKind | null) => { + setPreviewState(k) + try { + if (k) sessionStorage.setItem(PREVIEW_KEY, k) + else sessionStorage.removeItem(PREVIEW_KEY) + } catch { + // 저장이 막혀도 이번 화면에서는 메모리 값으로 쓴다 + return + } + }, []) const [serverKind, setServerKind] = useState(null) const [now, setNow] = useState(() => new Date()) useEffect(() => { @@ -113,7 +137,7 @@ function SkyProvider({ children }: { children: ReactNode }) { }, []) const t = kst(now) const kind = preview ?? serverKind ?? kindOfHour(t.h, t.mo, t.mi) - const api = useMemo(() => ({ kind, setPreview, setServerKind }), [kind]) + const api = useMemo(() => ({ kind, preview, setPreview, setServerKind }), [kind, preview, setPreview]) return ( {children} ) diff --git a/frontend/src/b/TodayPage.tsx b/frontend/src/b/TodayPage.tsx index f1f8b86..6590213 100644 --- a/frontend/src/b/TodayPage.tsx +++ b/frontend/src/b/TodayPage.tsx @@ -71,15 +71,14 @@ type HeroProps = { hero?: HeroData | null; today?: ResWeatherToday; feedLoad: Lo function Hero({ hero, today, feedLoad, todayLoad }: HeroProps) { const { open } = useSheet() - const [mode, setMode] = useState('now') + const { preview, setServerKind, setPreview } = useSky() + const mode: Mode = preview ?? 'now' + const setMode = (m: Mode) => setPreview(m === 'now' ? null : m) const clock = useNow() const t = kst(clock) const kind = mode === 'now' ? (hero?.sky_mode ?? kindOfHour(t.h, t.mo, t.mi)) : mode - const { setServerKind, setPreview } = useSky() // 화면 전체 하늘 배경도 같은 시간대로 맞춘다 useEffect(() => setServerKind(hero?.sky_mode ?? null), [hero?.sky_mode, setServerKind]) - useEffect(() => setPreview(mode === 'now' ? null : mode), [mode, setPreview]) - useEffect(() => () => setPreview(null), [setPreview]) const slots = today?.slots ?? [] const slot = slots.length ? slotAt(slots, mode === 'now' ? t.h : PREVIEW[mode].hour) : undefined // 지금은 /v1/feed hero 값을, 미리보기는 그 시각의 예보 칸을 쓴다 diff --git a/frontend/src/b/skyContext.ts b/frontend/src/b/skyContext.ts index 1d8e7c8..66e7f12 100644 --- a/frontend/src/b/skyContext.ts +++ b/frontend/src/b/skyContext.ts @@ -1,8 +1,8 @@ import { createContext, use } from 'react' import type { TimeKind } from './lib' -/** 화면 전체 하늘 배경의 시간대. 히어로의 미리보기 버튼이 잠시 바꿀 수 있다 */ -export type SkyApi = { kind: TimeKind; setServerKind: (k: TimeKind | null) => void; setPreview: (k: TimeKind | null) => void } +/** 화면 전체 하늘 배경의 시간대. 히어로의 미리보기 버튼으로 고른 값은 탭을 옮겨도 유지된다 */ +export type SkyApi = { kind: TimeKind; preview: TimeKind | null; setServerKind: (k: TimeKind | null) => void; setPreview: (k: TimeKind | null) => void } export const SkyContext = createContext(null)