import { useCallback, useEffect, useMemo, useState, type ReactNode } from 'react' import { NavLink, Outlet, useLocation, useNavigationType } from 'react-router' import { useIsFetching, useQuery, useQueryClient } from '@tanstack/react-query' import { authConfigOptions, getSeasonWeekOptions } from '@nalssigak/shared/api/client/@tanstack/react-query.gen' import { cx } from '../lib/utils' import { kindOfHour, kst, seasonOf, type TimeKind } from '@nalssigak/shared/lib' import './b.css' import { AuthProvider } from './auth' import { RegionProvider } from './region' import { useAuth } from './authContext' import { preloadGoogle } from './googleScript' import { currentHoliday } from './holiday' import { LevelBadge, LevelWatcher } from './level' import { useRegion } from './regionContext' import { useSheet } from './sheetContext' import { SheetProvider } from './Sheets' import { SkyContext, useSky } from './skyContext' import { TossIntro } from './tossIntro' import { PinIcon, TabIcon } from './svg' import { Avatar, Ic, Skel } from './ui' const TABS = [ { to: '/sky', key: 'sky', label: '노을', title: '노을' }, { to: '/gak', key: 'gak', label: '각', title: '오늘의 각' }, // 메인인 오늘 탭을 가운데에 { to: '/', key: 'today', label: '오늘', title: null }, { to: '/week', key: 'week', label: '주말·행사', title: '주말·행사' }, { to: '/season', key: 'season', label: '계절·상식', title: '계절·상식' }, ] as const /** 로고 옆 계절 칩: 계절 이름과 지금 절기. 누르면 이번 주 절기 창. 좁은 화면에선 절기를 뺀다 */ function SeasonChip() { const { open } = useSheet() const week = useQuery(getSeasonWeekOptions()) const [month] = useState(() => kst(new Date()).mo) const [name, icon] = seasonOf(month) const term = week.data?.term_now?.name return ( ) } function TopBar() { const { pathname } = useLocation() const { region, locateStatus } = useRegion() const { open } = useSheet() const { me, mePending } = useAuth() const queryClient = useQueryClient() const tab = TABS.find((t) => t.to !== '/' && pathname.startsWith(t.to)) const loggedOut = !mePending && !me // 로그인 창을 처음 열 때 버벅이지 않게 구글 로그인 준비물을 미리 받아 둔다 useEffect(() => { if (!loggedOut) return void queryClient.prefetchQuery({ ...authConfigOptions(), staleTime: Infinity }) return preloadGoogle() }, [loggedOut, queryClient]) return (
{tab?.title ?

{tab.title}

:

날씨각

} {mePending ? ( ) : me ? ( ) : ( )}
) } const STARS = Array.from({ length: 46 }, (_, i) => ({ left: `${(i * 41 + 7) % 100}%`, top: `${(i * 67 + 3) % 96}%`, '--s': `${1 + (i % 3) * 0.8}px`, '--tw': `${3 + (i % 5)}s`, '--dl': `-${(i * 0.7) % 6}s`, })) // 별똥별: 위치·길이·주기를 엇갈려 몇 초마다 하나씩 떨어지게 const SHOOTS = [ { top: '8%', left: '78%', '--len': '110px', '--dur': '7s', '--dl': '1s' }, { top: '22%', left: '46%', '--len': '80px', '--dur': '9s', '--dl': '3.5s' }, { top: '5%', left: '30%', '--len': '95px', '--dur': '8s', '--dl': '5.5s' }, { top: '36%', left: '88%', '--len': '70px', '--dur': '10s', '--dl': '2.2s' }, { top: '52%', left: '62%', '--len': '90px', '--dur': '11s', '--dl': '7s' }, { top: '14%', left: '96%', '--len': '120px', '--dur': '12s', '--dl': '9s' }, ] const HOLIDAY = currentHoliday() /** 화면 전체 하늘: 시간대별 색, 아주 느리게 일렁이는 색 덩어리, 밤에는 별 */ function SkyBg() { const { kind } = useSky() const [hidden, setHidden] = useState(false) useEffect(() => { const onVis = () => setHidden(document.hidden) document.addEventListener('visibilitychange', onVis) return () => document.removeEventListener('visibilitychange', onVis) }, []) return (