import { useState } from 'react' import { useQuery } from '@tanstack/react-query' import { listArticlesOptions, listIndicesOptions } from '../api/client/@tanstack/react-query.gen' import { ArticleCategory, IndexCategory } from '../api/client/types.gen' import { cx } from '../lib/utils' import { kst, loadOf, MEDALS, seasonOf } from './lib' import { useRegion } from './regionContext' import { useSheet } from './sheetContext' import { Chips, Ic, Sec, Skel, StateBox } from './ui' type Cat = 'all' | 'out' | 'food' | 'home' | 'life' | 'core' // 마지막 칩은 지금 계절의 제철 각 (예: 가을 각) const CATS: readonly (readonly [Cat, string])[] = [ ['all', '전체'], ['out', '밖에서 놀기'], ['food', '먹고 마시기'], ['home', '집안일'], ['life', '생활 고민'], ['core', `${seasonOf(kst(new Date()).mo)[0]} 각`], ] const CAT_PARAM: Partial> = { out: IndexCategory.OUTSIDE, food: IndexCategory.FOOD, home: IndexCategory.HOME, life: IndexCategory.LIFE } const GRID_SKELS = Array.from({ length: 9 }, (_, i) => i) /** 1~3위 받침대와 같은 칸(가운데가 높은 3칸)의 스켈레톤 */ function PodiumSkel() { return ( ) } function GakCellSkel() { return ( ) } function GridSkel() { return (
{GRID_SKELS.map((i) => ( ))}
) } export function GakPage() { const { region } = useRegion() const { open } = useSheet() const [cat, setCat] = useState('all') const q = useQuery(listIndicesOptions({ query: { region: region.code, category: CAT_PARAM[cat], core: cat === 'core' ? true : undefined } })) const top = q.data?.top3 ?? [] const items = q.data?.items ?? [] const day = q.data?.day?.split('-').map(Number) const load = loadOf(q) const howto = useQuery(listArticlesOptions({ query: { category: ArticleCategory.GAK } })).data?.articles?.find((a) => a.code === 'howgak') return (
{top.length !== 3 ? ( load === 'loading' ? ( ) : ( q.refetch()} empty="오늘 1~3위를 아직 못 정했어요." hold={} className="inset-x-3 top-3 bottom-0" /> ) ) : (
{[1, 0, 2].map((k) => { const g = top[k] return ( ) })}
)} {load === 'loading' ? ( ) : !items.length ? ( // 실패 안내·다시 시도는 위 받침대 자리에 한 번만 } className="inset-3" /> ) : (
{items.map((g) => { return ( ) })}
)} {/* 목록 칸 수가 정해진 뒤에 붙여 목록이 늘어날 때 밀리지 않게 */} {howto && load !== 'loading' && ( )}
) }