140 lines
6.1 KiB
TypeScript
140 lines
6.1 KiB
TypeScript
import type { BandArticle, BandEvent, TopIndex } from '@nalssigak/shared/api/client/types.gen';
|
|
import { cardBg, MEDALS } from '@nalssigak/shared/lib';
|
|
import { LinearGradient } from 'expo-linear-gradient';
|
|
import { Link, type Href } from 'expo-router';
|
|
import type { ReactNode } from 'react';
|
|
import { Pressable, Text, View } from 'react-native';
|
|
|
|
import { Ic, Rail, Sec, Skel, Thumb } from '@/components/ui';
|
|
import { CARD_BG, BAND_BG } from '@/lib/colors';
|
|
import { useSheet } from '@/lib/sheet';
|
|
import { useSky } from '@/lib/sky';
|
|
|
|
const CARD = 'overflow-hidden rounded-[22px] border-b-[5px] border-shade bg-card';
|
|
|
|
/** 오늘의 각 순위: 동그라미 + 이름 + 점수. 지금 시간대가 아닌 각은 흐리게 */
|
|
export function Stories({ items }: { items: TopIndex[] }) {
|
|
const { open } = useSheet();
|
|
return (
|
|
<Rail>
|
|
{items.map((g, i) => (
|
|
<Pressable key={g.index_id} onPress={() => open({ type: 'gak', indexId: g.index_id })} accessibilityLabel={g.active ? `${g.rank}위 ${g.name} ${g.score}점` : `${g.name}, 지금 시간대 아님`} className={`w-[72px] items-center gap-1 ${g.active ? '' : 'opacity-55'}`}>
|
|
<View className="size-[68px]">
|
|
{!g.active || g.score < 50 ? (
|
|
<View className="absolute inset-0 rounded-full bg-[#d6deea]" />
|
|
) : (
|
|
<LinearGradient colors={['#ff7a45', '#ffc86e', '#8fcaff']} start={{ x: 0, y: 0 }} end={{ x: 1, y: 1 }} style={{ position: 'absolute', inset: 0, borderRadius: 34 }} />
|
|
)}
|
|
<View className="m-[3px] flex-1 items-center justify-center rounded-full border-[3px] border-page bg-page">
|
|
<Ic name={g.icon} size={42} />
|
|
</View>
|
|
{i < 3 && g.active && <Ic name={MEDALS[i]} size={25} style={{ position: 'absolute', right: -4, bottom: -4 }} />}
|
|
</View>
|
|
<Text numberOfLines={1} className="font-jua text-[13px] text-ink">
|
|
{g.name}
|
|
</Text>
|
|
{g.active ? <Text className="font-bagel text-[12.5px] leading-[14px] text-orange">{g.score}</Text> : <Text className="text-[11px] leading-[14px] font-extrabold text-ink3">지금 아님</Text>}
|
|
</Pressable>
|
|
))}
|
|
</Rail>
|
|
);
|
|
}
|
|
|
|
const SKELS = Array.from({ length: 6 }, (_, i) => i);
|
|
|
|
export function StoriesSkel() {
|
|
return (
|
|
<Rail>
|
|
{SKELS.map((i) => (
|
|
<View key={i} className="w-[72px] items-center gap-1.5">
|
|
<View className="size-[68px] rounded-full bg-skel" />
|
|
<Skel className="w-12" />
|
|
<Skel className="w-6" />
|
|
</View>
|
|
))}
|
|
</Rail>
|
|
);
|
|
}
|
|
|
|
function Band({ tone, title, sub, to, children }: { tone: 1 | 2 | 3; title: string; sub: string; to: Href; children: ReactNode }) {
|
|
const { kind } = useSky();
|
|
return (
|
|
<View className="mt-3.5 pb-3.5" accessibilityLabel={title}>
|
|
<LinearGradient colors={BAND_BG[kind === 'night' ? 'night' : 'day'][tone]} style={{ position: 'absolute', inset: 0 }} />
|
|
<View className="-mt-[6px]">
|
|
<Sec title={title} sub={sub} more={to} />
|
|
</View>
|
|
{children}
|
|
</View>
|
|
);
|
|
}
|
|
|
|
function useCardBg() {
|
|
const { kind } = useSky();
|
|
return CARD_BG[kind === 'night' ? 'night' : 'day'];
|
|
}
|
|
|
|
export function EventsBand({ events }: { events: BandEvent[] }) {
|
|
const bg = useCardBg();
|
|
return (
|
|
<Band tone={1} title="이번 주 가까운 행사" sub="30km 안 · 날씨까지 같이 보고 골라요" to="/week">
|
|
<Rail>
|
|
{events.map((e, i) => (
|
|
<Link key={e.event_id} href="/week" asChild>
|
|
<Pressable className={`w-[200px] ${CARD}`}>
|
|
<Thumb image={e.image} icon={e.icon} iconSize={76} className="h-[116px]">
|
|
<LinearGradient colors={bg[cardBg(e.icon, i)]} style={{ position: 'absolute', inset: 0, zIndex: -1 }} />
|
|
<View className={`absolute top-2.5 left-2.5 rounded-full px-2 py-[3px] ${e.status_label === '진행 중' ? 'bg-[#1f9d62]' : 'bg-orange'}`}>
|
|
<Text className="text-[11.5px] font-extrabold text-white">{e.status_label}</Text>
|
|
</View>
|
|
</Thumb>
|
|
<Text className="px-3 pt-2.5 pb-3 font-jua text-[16.5px] leading-snug text-ink">{e.name}</Text>
|
|
</Pressable>
|
|
</Link>
|
|
))}
|
|
</Rail>
|
|
</Band>
|
|
);
|
|
}
|
|
|
|
export 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) => (
|
|
<Pressable key={g.index_id} onPress={() => open({ type: 'gak', indexId: g.index_id })} className="w-[138px] gap-1 rounded-[22px] border-b-[5px] border-shade bg-card p-3">
|
|
{i < 3 ? <Ic name={MEDALS[i]} size={26} style={{ position: 'absolute', top: 8, left: 8 }} /> : <Text className="absolute top-2.5 left-3 font-jua text-ink3">{i + 1}위</Text>}
|
|
<Ic name={g.icon} size={58} style={{ alignSelf: 'center' }} />
|
|
<Text className="font-jua text-base text-ink">{g.name}</Text>
|
|
<Text className="font-bagel text-[22px] leading-[24px] text-orange">{g.score}</Text>
|
|
{g.summary && <Text className="text-xs font-semibold text-ink2">{g.summary}</Text>}
|
|
</Pressable>
|
|
))}
|
|
</Rail>
|
|
</Band>
|
|
);
|
|
}
|
|
|
|
export function SeasonBand({ news }: { news: BandArticle[] }) {
|
|
const bg = useCardBg();
|
|
const { open } = useSheet();
|
|
return (
|
|
<Band tone={3} title="이번 주 계절 이야기" sub="예년 이맘때의 소식" to="/season">
|
|
<Rail>
|
|
{news.map((a) => (
|
|
<Pressable key={a.article_id} onPress={() => open({ type: 'article', articleId: a.article_id })} className={`w-[200px] ${CARD}`}>
|
|
<Thumb image={a.image} icon={a.icon} iconSize={76} className="h-[116px]">
|
|
<LinearGradient colors={bg[cardBg(a.icon, a.article_id)]} style={{ position: 'absolute', inset: 0, zIndex: -1 }} />
|
|
</Thumb>
|
|
<View className="px-3 pt-2.5 pb-3">
|
|
<Text className="font-jua text-[16.5px] leading-snug text-ink">{a.title}</Text>
|
|
<Text className="text-[12.5px] font-semibold text-ink2">{a.meta}</Text>
|
|
</View>
|
|
</Pressable>
|
|
))}
|
|
</Rail>
|
|
</Band>
|
|
);
|
|
}
|