import { getFeedOptions, getWeatherTodayOptions } from '@nalssigak/shared/api/client/@tanstack/react-query.gen';
import { kst, loadOf } from '@nalssigak/shared/lib';
import { atSlot, PREVIEW } from '@nalssigak/shared/lib/today';
import { useQuery } from '@tanstack/react-query';
import { Fragment, type ReactNode } from 'react';
import { RefreshControl, ScrollView } from 'react-native';
import { isAppPost, PostCard, PostCardSkel } from '@/components/post/post-card';
import { Hero } from '@/components/today/hero';
import { EventsBand, SeasonBand, Stories, StoriesSkel, TopBand } from '@/components/today/rails';
import { Sec, StateBox } from '@/components/ui';
import { useRegion } from '@/lib/region';
import { useSky } from '@/lib/sky';
export default function TodayScreen() {
const { region } = useRegion();
const feed = useQuery(getFeedOptions({ query: { region: region.code } }));
const today = useQuery(getWeatherTodayOptions({ query: { region: region.code } }));
const { preview } = useSky();
const f = feed.data;
const posts = (f?.posts ?? []).filter(isAppPost);
const stories = atSlot(f?.stories ?? [], preview);
const sloted = preview != null && stories !== f?.stories;
const bands = f?.bands;
const nowAt = f?.hero?.now_at;
const load = loadOf(feed);
const refresh = () => Promise.all([feed.refetch(), today.refetch()]);
// 웹처럼 3·6·9번째 글 뒤에 띠를 넣고, 글이 모자라면 남은 띠는 맨 뒤에 붙인다
const bandAt: [number, ReactNode][] = [
[3, bands?.events?.length ? : null],
[6, bands?.top5?.length ? g.active) : bands.top5} sub={sloted ? `${PREVIEW[preview].label} 기준` : nowAt ? `${kst(nowAt).h}시 기준` : '오늘 기준'} /> : null],
[9, bands?.season?.length ? : null],
];
return (
// 지역마다 새로 그려 넘긴 슬라이드 위치가 남지 않게 한다
} style={{ opacity: feed.isPlaceholderData ? 0.6 : 1 }}>
{stories.length ? : load === 'loading' ? : feed.refetch()} empty="오늘 계산된 각이 없어요." hold={} boxClassName="inset-x-3 top-3 bottom-1" />}
{load === 'loading' && (
<>
>
)}
{/* 글이 없거나 못 받아도 스켈레톤 두 장 자리는 그대로 둔다. 다시 시도는 위 각 줄에 한 번만 */}
{load !== 'loading' && !posts.length && (
>
}
boxClassName="inset-x-3 top-3.5"
/>
)}
{posts.map((p, i) => (
{bandAt.find(([at]) => at === i + 1)?.[1]}
))}
{feed.isSuccess && bandAt.filter(([at]) => at > posts.length).map(([at, node]) => {node})}
);
}