46 lines
1.9 KiB
TypeScript
46 lines
1.9 KiB
TypeScript
import { listShortsOptions } from '@nalssigak/shared/api/client/@tanstack/react-query.gen';
|
|
import { useQuery } from '@tanstack/react-query';
|
|
import { Image } from 'expo-image';
|
|
import { LinearGradient } from 'expo-linear-gradient';
|
|
import { Link } from 'expo-router';
|
|
import { Pressable, View } from 'react-native';
|
|
|
|
import { Text } from '@/components/text';
|
|
import { Rail } from '@/components/ui';
|
|
|
|
const SKELS = [0, 1, 2, 3];
|
|
|
|
export const thumb = (id: string) => `https://i.ytimg.com/vi/${id}/hqdefault.jpg`;
|
|
|
|
/** 오늘 화면 히어로 아래 쇼츠 줄. 누르면 쇼츠 화면에서 위아래로 넘겨 본다. 앱은 데이터를 아끼려고 줄에서는 표지만 (웹은 첫 카드를 소리 없이 재생) */
|
|
export function ShortsRail() {
|
|
const q = useQuery(listShortsOptions());
|
|
const items = q.data?.items ?? [];
|
|
if (q.isPending)
|
|
return (
|
|
<Rail>
|
|
{SKELS.map((i) => (
|
|
<View key={i} className="aspect-[9/16] w-[120px] rounded-xl bg-skel" />
|
|
))}
|
|
</Rail>
|
|
);
|
|
if (!items.length) return null;
|
|
return (
|
|
<View accessibilityLabel="날씨각 쇼츠">
|
|
<Rail>
|
|
{items.map((s) => (
|
|
<Link key={s.id} href={{ pathname: '/shorts/[id]', params: { id: s.id } }} asChild>
|
|
<Pressable accessibilityLabel={`${s.title} 보기`} className="aspect-[9/16] w-[120px] overflow-hidden rounded-xl bg-[#1d2233]">
|
|
<Image source={{ uri: thumb(s.id) }} style={{ position: 'absolute', inset: 0 }} contentFit="cover" />
|
|
<LinearGradient colors={['transparent', 'rgba(0,0,0,0.65)']} locations={[0.55, 1]} style={{ position: 'absolute', inset: 0 }} />
|
|
<Text numberOfLines={3} className="absolute inset-x-2 bottom-2 text-[12px] leading-[16px] font-bold text-white">
|
|
{s.title}
|
|
</Text>
|
|
</Pressable>
|
|
</Link>
|
|
))}
|
|
</Rail>
|
|
</View>
|
|
);
|
|
}
|