Files
o2o-weather/mobile/src/components/sky/parts.tsx
T

191 lines
8.6 KiB
TypeScript
Raw Blame History

This file contains invisible Unicode characters
This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
import type { BestTime, SkyPlanData } from '@nalssigak/shared/api/client/types.gen';
import { clockShort } from '@nalssigak/shared/lib';
import { LinearGradient } from 'expo-linear-gradient';
import { useState, type ReactNode } from 'react';
import { Pressable, View } from 'react-native';
import { Text } from '@/components/text';
import { useCSSVariable } from 'uniwind';
import { RAIL, skyOf } from '@/components/sky/colors';
import { SitSun, Skyline } from '@/components/sky/skyline';
import { MapLink, Skel } from '@/components/ui';
const SHADOW = { textShadowColor: 'rgb(50 25 70 / 0.35)', textShadowOffset: { width: 0, height: 2 }, textShadowRadius: 10 };
const FOUR = [0, 1, 2, 3];
/** 히어로엔 답만: 노을 피크 시각과 어떻게 물드는지. 상자는 불러오는 중·실패·빈 값 모두 같은 크기 */
export function SkyHero({ plan, children }: { plan?: SkyPlanData; children?: ReactNode }) {
const g = skyOf(plan?.grade_label).hero;
return (
<View className="mx-3 mt-1 min-h-[230px] overflow-hidden rounded-[32px] px-5 pt-5 pb-14">
<LinearGradient colors={g.colors} locations={g.locations} style={{ position: 'absolute', inset: 0 }} />
<SitSun />
<Skyline />
{children ?? (
<View>
{plan ? (
<Text className="font-jua text-[28px] leading-tight text-white" style={SHADOW}>
{plan.title}
</Text>
) : (
<Skel className="h-7 w-[230px]" />
)}
{!plan ? (
<Skel className="mt-2 w-[180px]" />
) : plan.situation_label ? (
<Text className="mt-1.5 text-[15px] font-bold text-white" style={SHADOW}>
{plan.situation_label}
</Text>
) : null}
</View>
)}
</View>
);
}
/** 오늘·내일·모레를 그날 예상 하늘색 타일로. 누르면 그날로 */
export function DayTiles({ plans, day, onPick }: { plans: SkyPlanData[]; day?: string; onPick: (day: string) => void }) {
const ink = String(useCSSVariable('--color-ink'));
return (
<View className="mx-3 mt-2.5 flex-row gap-2">
{plans.map((p) => {
const g = skyOf(p.grade_label).tile;
const on = p.day === day;
return (
<Pressable key={p.day} accessibilityState={{ selected: on }} onPress={() => onPick(p.day)} className="flex-1 rounded-[18px] p-[2px]" style={{ borderWidth: 3, borderColor: on ? ink : 'transparent' }}>
<View className="overflow-hidden rounded-2xl px-2.5 pt-2 pb-2.5">
<LinearGradient colors={g.colors} locations={g.locations} start={{ x: 0.2, y: 0 }} end={{ x: 0.8, y: 1 }} style={{ position: 'absolute', inset: 0 }} />
<Text className="text-[11.5px] font-extrabold text-white">{p.when}</Text>
<Text className="font-jua text-lg leading-tight text-white">{p.best_at ? clockShort(p.best_at) : '–'}</Text>
<Text className="text-[11.5px] font-bold text-white">
{p.grade_label} {p.score}
</Text>
</View>
</Pressable>
);
})}
</View>
);
}
function Toggle({ label, children, end }: { label: ReactNode; children: ReactNode; end?: boolean }) {
const [open, setOpen] = useState(false);
return (
<View>
<Pressable onPress={() => setOpen(!open)} accessibilityState={{ expanded: open }} className={`flex-row items-center gap-1.5 ${end ? 'justify-between' : ''}`}>
{label}
</Pressable>
{open && children}
</View>
);
}
const Q = ({ className = 'bg-card/80' }: { className?: string }) => (
<View className={`size-[18px] items-center justify-center rounded-full ${className}`}>
<Text className="text-[11px] font-extrabold text-ink">?</Text>
</View>
);
/** 노을 점수 뜻. 지금 하늘이 아니라 해 질(뜰) 무렵 예보라는 것도 */
export function ScoreHelp({ plan }: { plan: SkyPlanData }) {
const sunAt = plan.timeline?.find((t) => t.kind === 'sun')?.at;
const rise = plan.kind === 'sunrise';
return (
<View className="mx-3 mt-1.5 px-1">
<Toggle
end
label={
<>
<Text className="text-[12px] font-bold text-ink2">노을 점수 100점 만점 · 높을수록 붉어요</Text>
<Q />
</>
}
>
<Text className="mt-1.5 rounded-xl bg-card/70 px-2.5 py-2 text-[12px] leading-snug font-semibold text-ink2">
80점 넘으면 붉게, 60점 넘으면 곱게, 40점 넘으면 은은하게 물들어요.
{sunAt && ` 해 ${rise ? '뜰' : '질'} 무렵(${new Date(sunAt).getHours()}시) 날씨 예보로 계산했고, 노을 피크 시각은 해 ${rise ? '뜨기 10~20분 전' : '지고 10~20분 뒤'}로 어림한 거라 실제와 다를 수 있어요.`}
</Text>
</Toggle>
</View>
);
}
/** 언제 보면 좋을까: 왼쪽 세로 줄 색이 그 시각 하늘색, 노을 피크만 강조 */
export function Timeline({ rows, kind = 'sunset' }: { rows?: BestTime[]; kind?: SkyPlanData['kind'] }) {
const rail = RAIL[kind === 'sunrise' ? 'sunrise' : 'sunset'];
const list = rows ?? FOUR.map(() => undefined);
return (
<View className="mx-3 mt-3 rounded-[22px] border-b-[5px] border-shade bg-card px-4 pt-3.5 pb-3">
<View className="flex-row gap-3">
<LinearGradient colors={rail.colors} locations={rail.locations} style={{ width: 12, borderRadius: 6 }} />
<View className="flex-1">
{list.map((t, i) => {
const peak = t?.kind === 'peak';
return (
<View key={t?.kind ?? i} className={`flex-row items-baseline gap-2.5 ${peak ? '-mx-1.5 my-0.5 rounded-xl bg-[#fff1f2] px-2.5 py-2' : 'py-1.5'}`} style={!peak && i < list.length - 1 ? { borderBottomWidth: 1 } : undefined}>
<View className="min-w-[96px]">
{t ? <Text className={`font-jua ${peak ? 'text-[20px] text-[#d23d5a]' : 'text-[17px] text-ink'}`}>{t.end ? `${clockShort(t.at)}~${clockShort(t.end)}` : clockShort(t.at)}</Text> : <Skel className="w-11" />}
</View>
{t ? <Text className={`flex-1 ${peak ? 'font-jua text-base text-[#d23d5a]' : 'text-[13.5px] font-bold text-ink2'}`}>{t.label}</Text> : <Skel className="w-20" />}
</View>
);
})}
</View>
</View>
{rows && (
<View className="mt-2">
<Toggle
label={
<>
<Q className="bg-[#f1ebe3]" />
<Text className="text-[12px] font-bold text-ink2">골든아워·블루아워가 뭐예요</Text>
</>
}
>
<Text className="mt-1.5 rounded-xl bg-[#faf6f1] px-2.5 py-2 text-[12px] leading-snug text-[#5a6380]">
<Text className="font-bold text-[#28304a]">골든아워</Text> 해가 {kind === 'sunrise' ? '뜬 뒤' : '지기 전'}, 햇빛이 금빛으로 물드는 시간{'\n'}
<Text className="font-bold text-[#28304a]">블루아워</Text> 해가 {kind === 'sunrise' ? '뜨기 전' : '진 뒤'}, 하늘이 짙은 파랑으로 남는 시간
</Text>
</Toggle>
</View>
)}
</View>
);
}
const ROW = 'flex-row items-center gap-2.5 px-1 py-3';
export function LiSkel({ ghost = false, last = false }: { ghost?: boolean; last?: boolean }) {
return (
<View className={`${ROW} border-line ${ghost ? 'opacity-0' : ''}`} style={last ? undefined : { borderBottomWidth: 1.5 }}>
<View className="w-[34px] items-center">
<Skel className="w-5" />
</View>
<View className="flex-1 gap-1.5">
<Skel className="h-4 w-24" />
<Skel className="w-40" />
</View>
<Skel className="w-9" />
</View>
);
}
/** 번호 · 이름(+설명) · 오른쪽 값 한 줄 */
export function Li({ no, title, sub, right, mine = false, place, last = false }: { no: number; title: string; sub?: string | null; right: string; mine?: boolean; place?: string; last?: boolean }) {
return (
<View className={`${ROW} border-line ${mine ? 'rounded-2xl bg-card' : ''}`} style={last ? undefined : { borderBottomWidth: 1.5 }}>
<Text className="w-[34px] text-center font-bagel text-xl text-orange">{no}</Text>
<View className="min-w-0 flex-1">
<Text className="font-jua text-[17px] text-ink">
{place ? <MapLink place={place}>{title}</MapLink> : title}
{mine && <Text className="text-xs font-extrabold text-rain"> 내 지역</Text>}
</Text>
<Text numberOfLines={1} className="text-[12.5px] font-semibold text-ink2">
{sub || ' '}
</Text>
</View>
<Text className="font-jua text-base text-ink">{right}</Text>
</View>
);
}