feat: 헤더 로고 옆 계절 칩(계절·지금 절기, 누르면 이번 주 절기), 처음 들어올 때 '날씨 불러오는 중…' 화면
This commit is contained in:
1 parent
66a73a4756
commit
b91212b9e1
3 files changed
+74
-2
No files matched your search
@@ -1,5 +1,7 @@
|
||||
import { useCallback, useEffect, useMemo, useState, type ReactNode } from 'react'
|
||||
import { NavLink, Outlet, useLocation } from 'react-router'
|
||||
import { useIsFetching, useQuery } from '@tanstack/react-query'
|
||||
import { getSeasonWeekOptions } from '../api/client/@tanstack/react-query.gen'
|
||||
import { cx } from '../lib/utils'
|
||||
import { kindOfHour, kst, type TimeKind } from './lib'
|
||||
import './b.css'
|
||||
@@ -11,7 +13,7 @@ import { useSheet } from './sheetContext'
|
||||
import { SheetProvider } from './Sheets'
|
||||
import { SkyContext, useSky } from './skyContext'
|
||||
import { PinIcon, TabIcon } from './svg'
|
||||
import { Avatar, Skel } from './ui'
|
||||
import { Avatar, Ic, Skel } from './ui'
|
||||
|
||||
const TABS = [
|
||||
{ to: '/sky', key: 'sky', label: '노을', title: '노을' },
|
||||
@@ -22,6 +24,26 @@ const TABS = [
|
||||
{ to: '/season', key: 'season', label: '계절·상식', title: '계절·상식' },
|
||||
] as const
|
||||
|
||||
// 달(1~12) → 계절 이름과 아이콘
|
||||
const SEASONS: [string, string][] = [['겨울', 'snow'], ['봄', 'garden'], ['여름', 'sun'], ['가을', 'maple']]
|
||||
const seasonOf = (month: number) => SEASONS[Math.floor((month % 12) / 3)]
|
||||
|
||||
/** 로고 옆 계절 칩: 계절 이름과 지금 절기. 누르면 이번 주 절기 창. 좁은 화면에선 절기를 뺀다 */
|
||||
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 (
|
||||
<button type="button" onClick={() => open({ type: 'seasonWeek' })} aria-label={`지금 ${name}${term ? `, ${term}` : ''}. 이번 주 절기 보기`} className="flex shrink-0 cursor-pointer items-center gap-1 rounded-full bg-white/70 py-1 pr-2.5 pl-1.5 text-[13px] font-extrabold whitespace-nowrap shadow-[0_4px_10px_rgb(40_48_74/0.06)]">
|
||||
<Ic name={icon} className="size-[18px]" />
|
||||
{name}
|
||||
{term && <span className="hidden font-bold opacity-70 min-[400px]:inline">· {term}</span>}
|
||||
</button>
|
||||
)
|
||||
}
|
||||
|
||||
function TopBar() {
|
||||
const { pathname } = useLocation()
|
||||
const { region, locateStatus } = useRegion()
|
||||
@@ -31,7 +53,8 @@ function TopBar() {
|
||||
|
||||
return (
|
||||
<header className="sticky top-0 z-20 flex h-[calc(54px+env(safe-area-inset-top,0px))] items-center justify-between gap-2.5 px-4 pt-[env(safe-area-inset-top,0px)]">
|
||||
{tab?.title ? <h1 className="font-jua text-[22px] font-normal">{tab.title}</h1> : <h1 className="font-jua text-[25px] font-normal text-(--orange)">날씨각</h1>}
|
||||
{tab?.title ? <h1 className="shrink-0 font-jua text-[22px] font-normal">{tab.title}</h1> : <h1 className="shrink-0 font-jua text-[25px] font-normal text-(--orange)">날씨각</h1>}
|
||||
<SeasonChip />
|
||||
<button
|
||||
type="button"
|
||||
onClick={() => open({ type: 'region' })}
|
||||
@@ -151,6 +174,36 @@ const NOTCH_BG: Record<TimeKind, string> = {
|
||||
night: '#0e1433',
|
||||
}
|
||||
|
||||
/** 처음 들어올 때만: 첫 데이터를 다 받을 때까지 하늘 위에 캐릭터와 '날씨 불러오는 중…'. 한 번 사라지면 다시 안 뜬다 */
|
||||
function FirstLoad() {
|
||||
const fetching = useIsFetching()
|
||||
const { kind } = useSky()
|
||||
const [started, setStarted] = useState(false)
|
||||
const [done, setDone] = useState(false)
|
||||
const [gone, setGone] = useState(false)
|
||||
// 받기 시작했다가 받는 게 없어지면 끝 (렌더 중에 바로 맞춘다)
|
||||
if (fetching > 0 && !started) setStarted(true)
|
||||
if (fetching === 0 && started && !done) setDone(true)
|
||||
// 느린 망에서도 10초 넘게 막지 않는다 (그 뒤는 화면 안 스켈레톤이 맡는다)
|
||||
useEffect(() => {
|
||||
const id = setTimeout(() => setDone(true), 10000)
|
||||
return () => clearTimeout(id)
|
||||
}, [])
|
||||
if (gone) return null
|
||||
return (
|
||||
<div
|
||||
role="status"
|
||||
aria-live="polite"
|
||||
onTransitionEnd={() => done && setGone(true)}
|
||||
className={cx('fixed inset-0 z-50 flex flex-col items-center justify-center gap-3 transition-opacity duration-400', done && 'pointer-events-none opacity-0')}
|
||||
style={{ backgroundColor: NOTCH_BG[kind] }}
|
||||
>
|
||||
<Ic name={kind === 'night' ? 'bear' : 'rabbit'} className="b-hop w-[88px]" />
|
||||
<p className="m-0 font-jua text-[19px]">날씨 불러오는 중…</p>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
function Shell() {
|
||||
const { pathname } = useLocation()
|
||||
const { kind } = useSky()
|
||||
@@ -164,6 +217,7 @@ function Shell() {
|
||||
return (
|
||||
<div className="min-h-dvh text-(--ink)">
|
||||
<SkyBg />
|
||||
<FirstLoad />
|
||||
{/* 위·아래 바: 띠는 화면 끝까지, 내용은 가운데 440px 안 */}
|
||||
<div className="b-topbg fixed inset-x-0 top-0 z-[19] h-[calc(54px+env(safe-area-inset-top,0px))] backdrop-blur-md" aria-hidden="true" />
|
||||
<div className="fixed inset-x-0 top-0 z-[19] h-[env(safe-area-inset-top,0px)] transition-colors duration-1400" style={{ backgroundColor: NOTCH_BG[kind] }} aria-hidden="true" />
|
||||
|
||||
@@ -129,7 +129,23 @@
|
||||
}
|
||||
}
|
||||
|
||||
/* 처음 불러오는 동안 캐릭터가 통통 뛴다 */
|
||||
.b-hop {
|
||||
animation: b-hop 0.9s cubic-bezier(0.3, 0, 0.4, 1) infinite;
|
||||
transform-origin: 50% 100%;
|
||||
}
|
||||
@keyframes b-hop {
|
||||
0%,
|
||||
100% {
|
||||
transform: translateY(0) scale(1.06, 0.94);
|
||||
}
|
||||
45% {
|
||||
transform: translateY(-22px) scale(0.97, 1.03);
|
||||
}
|
||||
}
|
||||
|
||||
@media (prefers-reduced-motion: reduce) {
|
||||
.b-hop,
|
||||
.b-fall,
|
||||
.b-heart-pop,
|
||||
.b-like-bit,
|
||||
|
||||
Reference in new issue
Block a user