feat: 시안 B 화면을 기본 화면으로, Hey API로 백엔드 연결

- 예전 화면(/, /a)과 목업 데이터를 지우고 시안 B 를 / 로
- @hey-api/openapi-ts 로 타입·TanStack Query 함수 생성, 토큰·401 갱신 처리
- 공유는 기본 공유창, 없으면 링크 복사

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
minaChoiandClaude Opus 5.5 committed 2026-10-02 11:32:22 +09:00
1 parent e134295ce5
commit f8b47f064a
147 files changed
+12350

No files matched your search

+268
View File
@@ -0,0 +1,268 @@
import { Fragment, useEffect, useState, type ReactNode } from 'react'
import { Link } from 'react-router'
import { useQuery } from '@tanstack/react-query'
import { getFeedOptions, getWeatherTodayOptions } from '../api/client/@tanstack/react-query.gen'
import type { BandArticle, BandEvent, Hero as HeroData, ResWeatherToday, TopIndex } from '../api/client/types.gen'
import { cx } from '../lib/utils'
import { cardBg, fall, kindOfHour, kst, MEDALS, sidoOf, WEEKDAYS, type TimeKind } from './lib'
import { PostCard } from './Post'
import { useRegion } from './regionContext'
import { useSheet } from './sheetContext'
import { Ic, Rail, Sec, StateBox } from './ui'
import { deg, skyText, slotAt } from './weatherText'
type Mode = 'now' | TimeKind
const MODES: [Mode, string][] = [
['now', '지금 시간'],
['morning', '아침'],
['day', '낮'],
['sunset', '노을'],
['night', '밤'],
]
// 미리보기 시간대마다 보여 줄 시계와 그 시각의 예보 칸
const PREVIEW: Record<TimeKind, { label: string; clock: string; hour: number }> = {
morning: { label: '아침', clock: '07:40', hour: 7 },
day: { label: '낮', clock: '13:20', hour: 13 },
sunset: { label: '노을', clock: '18:25', hour: 18 },
night: { label: '밤', clock: '22:10', hour: 22 },
}
const STARS = Array.from({ length: 26 }, (_, i) => ({ left: `${(i * 37) % 100}%`, top: `${(i * 53) % 60}%`, opacity: 0.4 + ((i * 7) % 6) / 10 }))
const ORB_POS = [
{ left: '66%', top: '6px', d: '.5s', f: '4.4s' },
{ left: '0%', top: '34px', d: '.7s', f: '5.1s' },
{ left: '4%', top: '184px', d: '.9s', f: '4.7s' },
]
function useNow(ms = 20000) {
const [now, setNow] = useState(() => new Date())
useEffect(() => {
const id = setInterval(() => setNow(new Date()), ms)
return () => clearInterval(id)
}, [ms])
return now
}
type HeroProps = { hero?: HeroData | null; today?: ResWeatherToday }
function Hero({ hero, today }: HeroProps) {
const { open } = useSheet()
const [mode, setMode] = useState<Mode>('now')
const clock = useNow()
const t = kst(clock)
const kind = mode === 'now' ? (hero?.sky_mode ?? kindOfHour(t.h)) : mode
const slots = today?.slots ?? []
const slot = slots.length ? slotAt(slots, mode === 'now' ? t.h : PREVIEW[mode].hour) : undefined
// 지금은 /v1/feed hero 값을, 미리보기는 그 시각의 예보 칸을 쓴다
const temp = mode === 'now' && hero ? hero.temp_c : slot?.temp_c
const feels = mode === 'now' && hero ? hero.feels_c : slot?.feels_c
const top3 = hero?.top3 ?? []
const who = kind === 'night' ? 'bear' : 'rabbit'
return (
<div className="b-hero relative mx-3 mt-1 overflow-hidden rounded-[32px] px-[18px] pt-4 pb-[18px]" data-t={kind}>
<div className="b-stars pointer-events-none absolute inset-0" aria-hidden="true">
{STARS.map((s, i) => (
<i key={i} className="absolute size-[3px] rounded-full bg-white shadow-[0_0_6px_#fff]" style={s} />
))}
</div>
<div className="relative z-[3] flex flex-wrap gap-1.5" role="group" aria-label="시간대 배경 미리보기">
{MODES.map(([m, l]) => (
<button key={m} type="button" aria-pressed={mode === m} onClick={() => setMode(m)} className={cx('cursor-pointer rounded-full px-2.5 py-[5px] text-xs font-bold', mode === m ? 'bg-(--ink) text-white' : 'bg-white/55 text-(--ink)')}>
{l}
</button>
))}
</div>
<div className="relative z-[3] mt-3 flex items-end justify-between">
<div>
<p className="mb-1 text-[13.5px] font-bold opacity-85">
{t.mo}월 {t.d}일 {WEEKDAYS[t.wd]}요일 · {mode === 'now' ? '지금' : `${PREVIEW[mode].label} 미리보기`}
</p>
<div className="font-bagel text-[60px] leading-none">{mode === 'now' ? `${String(t.h).padStart(2, '0')}:${String(t.mi).padStart(2, '0')}` : PREVIEW[mode].clock}</div>
</div>
<div className="text-right">
<b className="font-bagel text-[42px] leading-none font-normal">{temp != null ? deg(temp) : '--°'}</b>
<span className="block text-[12.5px] font-bold opacity-85">{temp != null ? `체감 ${deg(feels)}${slot ? ` · ${skyText(slot)}` : ''}` : '날씨를 불러오는 중'}</span>
</div>
</div>
<div className="relative z-[3] mt-3 grid grid-cols-2 gap-2.5">
<div className="b-stat flex items-center gap-2.5 rounded-[20px] px-3 py-[9px]">
<Ic name="thermo" className="w-9" />
<div>
<small className="block text-xs font-bold opacity-80">불쾌지수</small>
<b className="font-jua text-lg font-normal">{hero?.discomfort != null ? `${hero.discomfort} · ${hero.discomfort_label ?? ''}` : '-'}</b>
</div>
</div>
<div className="b-stat flex items-center gap-2.5 rounded-[20px] px-3 py-[9px]">
<Ic name="umbrella" className="w-9" />
<div>
<small className="block text-xs font-bold opacity-80">지금 비</small>
<b className="font-jua text-lg font-normal">{hero?.will_rain_2h == null ? '-' : hero.will_rain_2h ? '2시간 안에 비' : '2시간 없음'}</b>
</div>
</div>
</div>
<div className="relative mt-5 h-[286px]">
<span className="b-cloud b-fall top-6 left-[6%] h-[30px] w-[84px]" style={fall('.1s', '6s')} aria-hidden="true" />
<div className="b-sun b-fall absolute top-10 left-1/2 -ml-[82px] grid aspect-square w-[164px] place-items-center rounded-full text-center" style={fall('0s', '5.6s', '8px')}>
<span>
<b className="block font-bagel text-[56px] leading-[0.9] font-normal">{hero?.weather_score ?? '-'}</b>
<small className="mt-0.5 block font-jua text-[14.5px]">오늘 날씨 점수</small>
</span>
</div>
<span className="b-cloud b-fall top-[188px] left-[54%] h-10 w-[118px]" style={fall('.25s', '6.4s')} aria-hidden="true" />
{top3.map((g, i) => (
<button
key={g.index_id}
type="button"
onClick={() => open({ type: 'gak', indexId: g.index_id })}
aria-label={`${i + 1}위 ${g.name} ${g.score}점, 계산 근거 보기`}
className="b-fall absolute z-[2] flex w-24 cursor-pointer flex-col items-center"
style={{ left: ORB_POS[i].left, top: ORB_POS[i].top, ...fall(ORB_POS[i].d, ORB_POS[i].f) }}
>
<span className={cx('relative', i === 0 ? 'w-[78px]' : 'w-[60px]')}>
<Ic name={g.icon} className="w-full drop-shadow-[0_10px_12px_rgb(40_48_74/0.16)]" />
<Ic name={MEDALS[i]} className="absolute -top-2 -left-3.5 w-[30px]" />
</span>
<span className="b-orb-label font-jua text-sm whitespace-nowrap">
{i + 1}위 {g.name} <em className="font-bagel text-(--orange) not-italic">{g.score}</em>
</span>
</button>
))}
</div>
{hero?.bubble && (
<div className="relative z-[3] flex items-end gap-2">
<Ic name={who} alt={who === 'rabbit' ? '토끼' : '곰'} className="w-[50px] drop-shadow-[0_8px_10px_rgb(40_48_74/0.15)]" />
<span className="mb-3 rounded-[20px_20px_20px_6px] bg-white px-3.5 py-[9px] font-jua text-base text-(--ink) shadow-[0_8px_16px_rgb(40_48_74/0.1)]">{hero.bubble}</span>
</div>
)}
</div>
)
}
function Stories({ items }: { items: TopIndex[] }) {
const { open } = useSheet()
return (
<Rail label="오늘의 각 순위">
{items.map((g, i) => (
<button key={g.index_id} type="button" onClick={() => open({ type: 'gak', indexId: g.index_id })} aria-label={`${g.rank}위 ${g.name} ${g.score}점`} className="flex w-[72px] cursor-pointer flex-col items-center gap-1">
<span className={cx('relative size-[68px] rounded-full p-[3px]', g.score < 50 ? 'bg-[#d6deea]' : 'b-ring')}>
<i className="grid size-full place-items-center rounded-full border-[3px] border-(--page) bg-(--page)">
<Ic name={g.icon} className="w-[42px]" />
</i>
{i < 3 && <Ic name={MEDALS[i]} className="absolute -right-1 -bottom-1 w-[25px]" />}
</span>
<b className="font-jua text-[13px] font-normal whitespace-nowrap">{g.name}</b>
<em className="font-bagel text-[12.5px] leading-none text-(--orange) not-italic">{g.score}</em>
</button>
))}
</Rail>
)
}
function Band({ tone, title, sub, to, children }: { tone: 1 | 2 | 3; title: string; sub: string; to: string; children: ReactNode }) {
return (
<section className={cx('mt-3.5 pt-4 pb-3.5', `b-band-${tone}`)} aria-label={title}>
<Sec title={title} sub={sub} more={{ to }} className="pt-0" />
{children}
</section>
)
}
function EventsBand({ events }: { events: BandEvent[] }) {
const { region } = useRegion()
return (
<Band tone={1} title={`이번 주 ${sidoOf(region.name)} 행사`} sub="날씨까지 같이 보고 골라요" to="/week">
<Rail>
{events.map((e, i) => (
<Link key={e.event_id} to="/week" className="w-[200px] overflow-hidden rounded-[22px] bg-white shadow-[inset_0_-5px_0_var(--shade),0_8px_16px_rgb(40_48_74/0.06)]">
<span className={cx('relative grid h-[116px] place-items-center', `b-bg-${cardBg(e.icon, i)}`)}>
<span className={cx('absolute top-2.5 left-2.5 rounded-full px-2 py-[3px] text-[11.5px] font-extrabold text-white', e.status_label === '진행 중' ? 'bg-[#1f9d62]' : 'bg-(--orange)')}>{e.status_label}</span>
<Ic name={e.icon} className="w-[76px]" />
</span>
<span className="block px-3 pt-2.5 pb-3">
<b className="block font-jua text-[16.5px] leading-snug font-normal">{e.name}</b>
</span>
</Link>
))}
</Rail>
</Band>
)
}
function TopBand({ items, sub }: { items: TopIndex[]; sub: string }) {
const { open } = useSheet()
return (
<Band tone={2} title="지금 뜨는 각 TOP 5" sub={sub} to="/gak">
<Rail>
{items.slice(0, 5).map((g, i) => (
<button key={g.index_id} type="button" onClick={() => open({ type: 'gak', indexId: g.index_id })} className="relative flex w-[138px] cursor-pointer flex-col items-start gap-1 rounded-[22px] bg-white p-3 text-left shadow-[inset_0_-5px_0_var(--shade)]">
{i < 3 ? <Ic name={MEDALS[i]} alt={`${i + 1}위`} className="absolute top-2 left-2 w-[26px]" /> : <span className="absolute top-2.5 left-3 font-jua text-(--ink3)">{i + 1}위</span>}
<Ic name={g.icon} className="w-[58px] self-center" />
<b className="font-jua text-base font-normal">{g.name}</b>
<em className="font-bagel text-[22px] leading-none text-(--orange) not-italic">{g.score}</em>
{g.summary && <small className="text-xs font-semibold text-(--ink2)">{g.summary}</small>}
</button>
))}
</Rail>
</Band>
)
}
function SeasonBand({ news }: { news: BandArticle[] }) {
const { open } = useSheet()
return (
<Band tone={3} title="이번 주 계절 이야기" sub="예년 이맘때의 소식" to="/season">
<Rail>
{news.map((a) => (
<button key={a.article_id} type="button" onClick={() => open({ type: 'article', articleId: a.article_id })} className="w-[200px] cursor-pointer overflow-hidden rounded-[22px] bg-white text-left shadow-[inset_0_-5px_0_var(--shade),0_8px_16px_rgb(40_48_74/0.06)]">
<span className={cx('grid h-[116px] place-items-center', `b-bg-${cardBg(a.icon, a.article_id)}`)}>
<Ic name={a.icon} className="w-[76px]" />
</span>
<span className="block px-3 pt-2.5 pb-3">
<b className="block font-jua text-[16.5px] leading-snug font-normal">{a.title}</b>
<small className="text-[12.5px] font-semibold text-(--ink2)">{a.meta}</small>
</span>
</button>
))}
</Rail>
</Band>
)
}
export function TodayPage() {
const { region } = useRegion()
const feed = useQuery(getFeedOptions({ query: { region: region.code } }))
const today = useQuery(getWeatherTodayOptions({ query: { region: region.code } }))
const f = feed.data
const posts = f?.posts ?? []
const stories = f?.stories ?? []
const bands = f?.bands
const nowAt = f?.hero?.now_at
// 디자인대로 3·6·9번째 글 뒤에 띠를 넣고, 글이 모자라면 남은 띠는 맨 뒤에 붙인다
const bandAt: [number, ReactNode][] = [
[3, bands?.events?.length ? <EventsBand key="events" events={bands.events} /> : null],
[6, bands?.top5?.length ? <TopBand key="top5" items={bands.top5} sub={nowAt ? `${kst(nowAt).h}시 기준` : '오늘 기준'} /> : null],
[9, bands?.season?.length ? <SeasonBand key="season" news={bands.season} /> : null],
]
return (
<section aria-label="오늘">
<Hero hero={f?.hero} today={today.data} />
<Sec title="오늘의 각" sub="누르면 계산 근거를 보여 줘요" more={{ to: '/gak' }} />
{stories.length ? <Stories items={stories} /> : <StateBox loading={feed.isPending} error={feed.error} onRetry={() => feed.refetch()} empty="오늘 계산된 각이 없어요." />}
<StateBox loading={feed.isPending} error={feed.error} onRetry={() => feed.refetch()} empty={feed.isSuccess && !posts.length ? '오늘 올라온 글이 아직 없어요.' : undefined} />
<div>
{posts.map((p, i) => (
<Fragment key={p.post_id}>
<PostCard key={`${p.post_id}-${p.liked}-${p.saved}-${p.like_count}`} post={p} />
{bandAt.find(([at]) => at === i + 1)?.[1]}
</Fragment>
))}
{feed.isSuccess && bandAt.filter(([at]) => at > posts.length).map(([at, node]) => <Fragment key={at}>{node}</Fragment>)}
</div>
</section>
)
}