Files
o2o-weather/mobile/src/app/foliage.tsx
T

86 lines
4.0 KiB
TypeScript

import { headline, md, type Kind, type Spot } from '@nalssigak/shared/lib/foliage';
import { useLocalSearchParams } from 'expo-router';
import { useEffect, useMemo, useRef, useState } from 'react';
import { Pressable, ScrollView, useWindowDimensions, View } from 'react-native';
import { useCSSVariable } from 'uniwind';
import { FoliageMap, type FoliageMapHandle } from '@/components/foliage/foliage-map';
import { ChosenBar, SpotList } from '@/components/foliage/spot-list';
import { SendIcon } from '@/components/post/icons';
import { ScreenHeader } from '@/components/screen-header';
import { Text } from '@/components/text';
import { Chips, Ic } from '@/components/ui';
import { track } from '@/lib/analytics';
import { useFoliage } from '@/lib/foliage';
import { useShare } from '@/lib/share-image';
import { SITE_URL } from '@/lib/site';
type Filter = 'all' | Kind;
const FILTERS: [Filter, string][] = [
['all', '전체'],
['maple', '단풍'],
['ginkgo', '은행'],
];
/** 단풍 지도: 명소 67곳을 지도에서 확대해 보고 아래 목록으로 고른다. ?spot= 으로 열면 그 명소로 (웹 FoliagePage) */
export default function FoliageScreen() {
const params = useLocalSearchParams<{ spot?: string }>();
const { today, spots } = useFoliage();
const [filter, setFilter] = useState<Filter>('all');
const [sel, setSel] = useState<string | null>(params.spot ?? null);
const mapRef = useRef<FoliageMapHandle>(null);
const shotRef = useRef<View>(null);
const shareView = useShare();
const ink = String(useCSSVariable('--color-ink'));
const { width, height: winH } = useWindowDimensions();
// 지도는 스크롤 밖에 고정: 가로만큼 정사각형, 화면이 낮으면 화면 높이의 45%까지
const mapH = Math.max(280, Math.min(width * 1.05, winH * 0.45, 560));
const shown = useMemo(() => spots.filter((m) => filter === 'all' || m.kind === filter), [spots, filter]);
useEffect(() => track('foliage_open', {}), []);
useEffect(() => {
if (sel) track('foliage_spot', { spot_name: sel, from: 'page' });
}, [sel]);
const chosen = spots.find((m) => m.name === sel);
const peakCount = spots.filter((m) => m.stage === 'peak').length;
const title = headline(spots);
const pick = (m: Spot) => {
setSel(m.name);
mapRef.current?.focus(m);
};
const share = () => void shareView(shotRef, { title: chosen ? `${chosen.name} 단풍` : '단풍 지도', message: `${title} · 날씨각 단풍 지도 ${SITE_URL}/foliage` });
return (
<View className="flex-1">
<ScreenHeader
title="단풍 지도"
right={
<Pressable onPress={share} hitSlop={8} accessibilityRole="button" accessibilityLabel="단풍 지도 보내기" className="size-10 items-center justify-center">
<SendIcon size={24} color={ink} />
</Pressable>
}
/>
<View className="px-4 pt-1 pb-2">
<View className="flex-row items-center gap-1">
<Ic name="maple" size={16} />
<Text className="text-[13px] font-extrabold text-ink2">{`단풍 지도 · ${md(today)}`}</Text>
</View>
<Text className="mt-0.5 font-jua text-[24px] leading-tight text-ink">{title}</Text>
</View>
{/* 보내기는 지금 보이는 지도 그대로 찍어 보낸다 (웹은 따로 만든 공유 그림) */}
<View ref={shotRef} collapsable={false}>
<FoliageMap ref={mapRef} spots={shown} sel={sel} onSelect={setSel} height={mapH} />
</View>
<ChosenBar chosen={chosen} legendColor={ink} />
<ScrollView className="flex-1" contentContainerClassName="pb-8">
<Chips items={FILTERS} value={filter} onChange={setFilter} />
<SpotList spots={shown} sel={sel} onPick={pick} />
<Text className="px-5 pt-4 text-[11.5px] leading-relaxed font-semibold text-ink3">
{`출처: 산림청 2026 단풍절정 예측 · 잎 절반이 물든 때를 절정으로, 그 2주 전부터 첫 단풍으로 봐요${peakCount ? ` · 지금 절정 ${peakCount}곳` : ''}`}
</Text>
</ScrollView>
</View>
);
}