import { listArticlesOptions, listIndicesOptions } from '@nalssigak/shared/api/client/@tanstack/react-query.gen'; import { ArticleCategory, IndexCategory } from '@nalssigak/shared/api/client/types.gen'; import { kst, loadOf, seasonOf } from '@nalssigak/shared/lib'; import { useQuery } from '@tanstack/react-query'; import { useState } from 'react'; import { Pressable, RefreshControl, ScrollView, View } from 'react-native'; import { Text } from '@/components/text'; import { GakGrid, GridSkel } from '@/components/gak/grid'; import { Podium, PodiumSkel } from '@/components/gak/podium'; import { Chips, Ic, Sec, StateBox } from '@/components/ui'; import { useRegion } from '@/lib/region'; import { useSheet } from '@/lib/sheet'; 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 }; export default function GakScreen() { 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 articles = useQuery(listArticlesOptions({ query: { category: ArticleCategory.GAK } })); const top = q.data?.top3 ?? []; const items = q.data?.items ?? []; const day = q.data?.day?.split('-').map(Number); const load = loadOf(q); const howto = articles.data?.articles?.find((a) => a.code === 'howgak'); return ( q.refetch()} />}> {top.length === 3 ? : load === 'loading' ? : q.refetch()} empty="오늘 1~3위를 아직 못 정했어요." hold={} />} {load === 'loading' ? ( ) : !items.length ? ( // 실패 안내·다시 시도는 위 받침대 자리에 한 번만 } boxClassName="inset-3" /> ) : ( )} {howto && load !== 'loading' && ( open({ type: 'article', articleId: howto.article_id })} className="mx-3 mt-1.5 flex-row items-center gap-3 rounded-[22px] bg-[#ece7ff] p-3.5"> 각 점수는 어떻게 매길까? 기온·비·바람·습도·공기·시간대 6가지로 계산해요 )} ); }