feat: 앱 오늘 피드를 웹과 맞춤 — 히어로 오늘/내일 전환·좋아요·댓글·보내기·점수 근거 창, 오늘의 각 카드(gak_post), 날씨각 카드(그림 슬라이드), 행사·TOP5 띠 없앰, 좋아요·댓글 로그인 없이 (GA hero_day_switch, like hero_post·gak_post)
Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
1 parent
e8b8cc79b6
commit
01b5f917b9
16 files changed
+449
-156
No files matched your search
@@ -1,8 +1,10 @@
|
||||
import type { Hero as HeroData, ResWeatherToday, TopIndex } from '@nalssigak/shared/api/client/types.gen';
|
||||
import { kindOfHour, kst, type Load, type TimeKind, WEEKDAYS } from '@nalssigak/shared/lib';
|
||||
import { getWeatherTodayOptions } from '@nalssigak/shared/api/client/@tanstack/react-query.gen';
|
||||
import type { Hero as HeroData, PostReaction, ResWeatherToday, TopIndex } from '@nalssigak/shared/api/client/types.gen';
|
||||
import { kindOfHour, kst, loadOf, type Load, type TimeKind, WEEKDAYS } from '@nalssigak/shared/lib';
|
||||
import { KINDS, PREVIEW, SLOT_KEY, WANING, type Weather, WEATHER_ICON, weatherOf } from '@nalssigak/shared/lib/today';
|
||||
import { deg, slotAt } from '@nalssigak/shared/lib/weatherText';
|
||||
import { useEffect, useState, type ReactNode } from 'react';
|
||||
import { useQuery } from '@tanstack/react-query';
|
||||
import { useEffect, useRef, useState, type ReactNode } from 'react';
|
||||
import { Pressable, View, type DimensionValue, type ViewStyle } from 'react-native';
|
||||
import { Text } from '@/components/text';
|
||||
import Animated, { cancelAnimation, Easing, useAnimatedStyle, useReducedMotion, useSharedValue, withDelay, withRepeat, withTiming } from 'react-native-reanimated';
|
||||
@@ -11,9 +13,15 @@ import Svg, { Defs, RadialGradient, Rect, Stop } from 'react-native-svg';
|
||||
|
||||
import { Fall } from '@/components/fall';
|
||||
import { MoonArt } from '@/components/moon';
|
||||
import { CommentIcon, HeartIcon, SendIcon } from '@/components/post/icons';
|
||||
import { Shoot, type ShootSpec } from '@/components/sky-bg';
|
||||
import { Ic, Skel } from '@/components/ui';
|
||||
import { track } from '@/lib/analytics';
|
||||
import { usePinnedLike } from '@/lib/pinned-like';
|
||||
import { useRegion } from '@/lib/region';
|
||||
import { shareView } from '@/lib/share-image';
|
||||
import { useSheet } from '@/lib/sheet';
|
||||
import { SITE_URL } from '@/lib/site';
|
||||
import { useSky } from '@/lib/sky';
|
||||
|
||||
type Mode = 'now' | TimeKind;
|
||||
@@ -103,18 +111,32 @@ function heroVal(load: Load, v: ReactNode, skel: string) {
|
||||
return <Text className="opacity-50">?</Text>;
|
||||
}
|
||||
|
||||
type Props = { hero?: HeroData | null; today?: ResWeatherToday; ranked: TopIndex[]; feedLoad: Load; todayLoad: Load };
|
||||
type Props = { hero?: HeroData | null; post?: PostReaction | null; today?: ResWeatherToday; ranked: TopIndex[]; feedLoad: Load; todayLoad: Load };
|
||||
|
||||
export function Hero({ hero, today, ranked, feedLoad, todayLoad }: Props) {
|
||||
export function Hero({ hero, post, today, ranked, feedLoad, todayLoad }: Props) {
|
||||
const { open } = useSheet();
|
||||
const { region } = useRegion();
|
||||
const like = usePinnedLike('hero_post', post);
|
||||
const shot = useRef<View>(null);
|
||||
// 내일 스위치: 내일 칸 날씨는 켤 때 받고, 시간대는 화면 전체 하늘과 따로 히어로 안에서만 고른다 (웹 TodayPage Hero)
|
||||
const [tmr, setTmr] = useState(false);
|
||||
const [tmrKind, setTmrKind] = useState<TimeKind>('day');
|
||||
const tomorrowQ = useQuery({ ...getWeatherTodayOptions({ query: { region: region.code, day: 'tomorrow' } }), enabled: tmr });
|
||||
const ahead = hero?.tomorrow;
|
||||
const { preview, setServerKind, setPreview } = useSky();
|
||||
const mode: Mode = preview ?? 'now';
|
||||
const t = kst(useNow());
|
||||
const mode: Mode = tmr ? tmrKind : (preview ?? 'now');
|
||||
const clock = useNow();
|
||||
const t = kst(tmr ? new Date(clock.getTime() + 86400000) : clock);
|
||||
const nowKind = hero?.sky_mode ?? kindOfHour(t.h, t.mo, t.mi);
|
||||
const kind = mode === 'now' ? nowKind : mode;
|
||||
// 화면 전체 하늘 배경도 같은 시간대로 맞춘다
|
||||
useEffect(() => setServerKind(hero?.sky_mode ?? null), [hero?.sky_mode, setServerKind]);
|
||||
const slots = today?.slots ?? [];
|
||||
// 내일을 볼 땐 배경·글자색도 내일 고른 칸을 따른다
|
||||
useEffect(() => {
|
||||
if (tmr) setPreview(tmrKind);
|
||||
}, [tmr, tmrKind, setPreview]);
|
||||
const slots = (tmr ? tomorrowQ.data?.slots : today?.slots) ?? [];
|
||||
const slotsLoad = tmr ? loadOf(tomorrowQ) : todayLoad;
|
||||
// 지금은 가장 가까운 3시간 칸. 시간대는 그 시각 칸, 비어 있으면(지난 새벽 칸 등) 그 뒤 첫 예보 칸
|
||||
const slotOf = (k: Mode) => {
|
||||
if (k === 'now') {
|
||||
@@ -127,20 +149,66 @@ export function Hero({ hero, today, ranked, feedLoad, todayLoad }: Props) {
|
||||
return s?.temp_c != null ? s : (slots.find((x) => kst(x.at).h > h && x.temp_c != null) ?? s);
|
||||
};
|
||||
const weather = weatherOf(slotOf(mode));
|
||||
const slotScore = mode === 'now' ? undefined : hero?.weather_slots?.[SLOT_KEY[mode]];
|
||||
const score = slotScore ?? hero?.weather_score;
|
||||
const slotTop = mode === 'now' ? undefined : ranked.find((g) => g.active);
|
||||
const top1 = slotTop ?? hero?.top1;
|
||||
const slotScore = mode === 'now' ? undefined : (tmr ? ahead?.weather_slots : hero?.weather_slots)?.[SLOT_KEY[mode]];
|
||||
const score = tmr ? slotScore : (slotScore ?? hero?.weather_score);
|
||||
// 점수를 누르면 보고 있는 시간대(지금이면 지금 구간)의 날씨 점수 근거
|
||||
const whyKey = mode === 'now' ? SLOT_KEY[nowKind] : SLOT_KEY[mode];
|
||||
const why = (tmr ? ahead?.weather_why : hero?.weather_why)?.[whyKey];
|
||||
const whyLabel = tmr && mode !== 'now' ? `내일 ${PREVIEW[mode].label}` : mode === 'now' || mode === nowKind ? '지금' : PREVIEW[mode].label;
|
||||
const slotTop = mode === 'now' || tmr ? undefined : ranked.find((g) => g.active);
|
||||
const top1 = tmr ? ahead?.top1 : (slotTop ?? hero?.top1);
|
||||
const dark = kind === 'sunset' || kind === 'night';
|
||||
const moon = dark && hero?.moon_name && hero.moon_pct != null ? { pct: hero.moon_pct, waning: WANING.includes(hero.moon_name) } : null;
|
||||
const moon = !tmr && dark && hero?.moon_name && hero.moon_pct != null ? { pct: hero.moon_pct, waning: WANING.includes(hero.moon_name) } : null;
|
||||
// 말풍선 머리말: 지금은 / 낮은 / 내일은 / 내일 낮은
|
||||
const when = mode === 'now' || mode === nowKind ? '지금' : PREVIEW[mode].label;
|
||||
const bubble = slotTop ? (slotTop.score >= 70 ? `${when}은 ${slotTop.name}!` : `${when}은 쉬어 가요`) : hero ? (hero.bubble ?? '지금은 쉬어 가요') : failed(feedLoad) ? '앗, 날씨를 못 불러왔어요' : null;
|
||||
const status = hero?.status ?? [];
|
||||
const tmrWhen = mode === 'now' ? '내일' : `내일 ${PREVIEW[mode].label}`;
|
||||
const bubble = tmr
|
||||
? top1
|
||||
? top1.score >= 70
|
||||
? `${tmrWhen}은 ${top1.name}!`
|
||||
: `${tmrWhen}은 쉬어 가요`
|
||||
: null
|
||||
: slotTop
|
||||
? slotTop.score >= 70
|
||||
? `${when}은 ${slotTop.name}!`
|
||||
: `${when}은 쉬어 가요`
|
||||
: hero
|
||||
? (hero.bubble ?? '지금은 쉬어 가요')
|
||||
: failed(feedLoad)
|
||||
? '앗, 날씨를 못 불러왔어요'
|
||||
: null;
|
||||
// 내일은 최저·최고 기온과 고른 시간대 습도
|
||||
const temps = slots.flatMap((x) => (x.temp_c != null ? [x.temp_c] : []));
|
||||
const humidity = tmr && mode !== 'now' ? slotOf(mode)?.humidity : null;
|
||||
const status = tmr
|
||||
? [
|
||||
...(temps.length
|
||||
? [
|
||||
{ label: '최저', value: deg(Math.min(...temps)), tone: 'info' },
|
||||
{ label: '최고', value: deg(Math.max(...temps)), tone: 'info' },
|
||||
]
|
||||
: []),
|
||||
...(humidity != null ? [{ label: '습도', value: `${humidity}%`, tone: 'info' }] : []),
|
||||
]
|
||||
: (hero?.status ?? []);
|
||||
const openWhy = () => why && score != null && open({ type: 'weatherWhy', why: { label: whyLabel, score, why, status } });
|
||||
const switchDay = (v: boolean) => {
|
||||
// 내일로 넘어갈 땐 지금 보던 시간대 그대로 시작해 배경이 튀지 않게
|
||||
if (v && !tmr) setTmrKind(kind);
|
||||
if (v !== tmr) track('hero_day_switch', { day: v ? 'tomorrow' : 'today' });
|
||||
setTmr(v);
|
||||
};
|
||||
const share = () => {
|
||||
const title = `${region.name} ${tmr ? '내일' : '오늘'} 날씨`;
|
||||
void shareView(shot, { title, message: `${title} · 날씨각 ${SITE_URL}` });
|
||||
};
|
||||
const gray = !dark && weather !== 'clear' && weather !== 'partly';
|
||||
const rain = weather === 'rain' || weather === 'sleet';
|
||||
const snow = weather === 'snow' || weather === 'sleet';
|
||||
const orb = ORB[kind === 'sunset' ? 'sunset' : kind === 'night' ? 'night' : 'sun'];
|
||||
const text = dark ? 'text-white' : 'text-[#28304a]';
|
||||
const icon = dark ? '#ffffff' : '#28304a';
|
||||
const strip = dark ? 'rgb(255 255 255 / 0.14)' : 'rgb(255 255 255 / 0.42)';
|
||||
// 가운데가 밝은 달이면 진한 글씨에 흰 번짐, 가운데가 어두운 달(초승·그믐·삭)이면 흰 글씨
|
||||
const orbText: { color: string; textShadowColor?: string; textShadowRadius?: number } = !moon
|
||||
? { color: orb.text }
|
||||
@@ -149,7 +217,7 @@ export function Hero({ hero, today, ranked, feedLoad, todayLoad }: Props) {
|
||||
: { color: '#fff', textShadowColor: 'rgba(10,14,40,0.6)', textShadowRadius: 8 };
|
||||
|
||||
return (
|
||||
<View className="mx-3 mt-1 overflow-hidden rounded-[28px] px-4 pt-3 pb-3">
|
||||
<View ref={shot} collapsable={false} className="mx-3 mt-1 overflow-hidden rounded-[28px] px-4 pt-3 pb-3">
|
||||
<LinearGradient colors={HERO_BG[gray ? 'gray' : kind]} locations={kind === 'night' ? [0, 0.6, 1] : [0, 0.5, 1]} style={{ position: 'absolute', inset: 0 }} />
|
||||
{kind === 'night' && STARS.map((s, i) => <View key={i} className="absolute size-[3px] rounded-full bg-white" style={{ left: s.left, top: s.top, opacity: s.opacity }} />)}
|
||||
{kind === 'night' && SHOOTS.map((s, i) => <Shoot key={i} {...s} />)}
|
||||
@@ -159,9 +227,42 @@ export function Hero({ hero, today, ranked, feedLoad, todayLoad }: Props) {
|
||||
{snow && FLAKES.map((p, i) => <Particle key={`s${i}`} {...p} snow light={dark} />)}
|
||||
</View>
|
||||
)}
|
||||
<Text className={`text-[14px] font-bold opacity-80 ${text}`}>
|
||||
{t.mo}월 {t.d}일 {WEEKDAYS[t.wd]}요일
|
||||
</Text>
|
||||
<View className="z-[3] flex-row items-center justify-between">
|
||||
<View className="flex-row items-center gap-2">
|
||||
<View className="flex-row rounded-full p-[3px]" style={{ backgroundColor: strip }} accessibilityRole="radiogroup" accessibilityLabel="오늘 또는 내일 날씨">
|
||||
{(
|
||||
[
|
||||
[false, '오늘'],
|
||||
[true, '내일'],
|
||||
] as const
|
||||
).map(([v, l]) => (
|
||||
<Pressable key={l} onPress={() => switchDay(v)} accessibilityRole="radio" accessibilityState={{ checked: tmr === v }} className={`rounded-full px-2.5 py-0.5 ${tmr === v ? 'bg-white' : ''}`}>
|
||||
<Text className={`font-jua text-[13px] ${tmr === v ? 'text-[#d4552a]' : `opacity-75 ${text}`}`}>{l}</Text>
|
||||
</Pressable>
|
||||
))}
|
||||
</View>
|
||||
<Text className={`text-[13px] font-bold opacity-80 ${text}`}>
|
||||
{t.mo}월 {t.d}일 {WEEKDAYS[t.wd]}요일
|
||||
</Text>
|
||||
</View>
|
||||
<View className="flex-row items-center">
|
||||
{post && (
|
||||
<>
|
||||
<Pressable onPress={like.toggle} hitSlop={6} accessibilityRole="button" accessibilityState={{ selected: like.liked }} accessibilityLabel={like.failed ? '좋아요를 반영하지 못했어요. 다시 눌러 주세요' : '오늘 날씨 좋아요'} className={`h-8 flex-row items-center gap-1 px-[5px] ${like.liked ? '' : 'opacity-80'}`}>
|
||||
<HeartIcon size={22} color={like.liked ? '#ff3b5c' : icon} filled={like.liked} />
|
||||
{like.count > 0 && <Text className={`text-[13px] font-extrabold ${text}`}>{like.count.toLocaleString()}</Text>}
|
||||
</Pressable>
|
||||
<Pressable onPress={() => open({ type: 'comments', postId: post.post_id })} hitSlop={6} accessibilityRole="button" accessibilityLabel="오늘 날씨 댓글" className="h-8 flex-row items-center gap-1 px-[5px] opacity-80">
|
||||
<CommentIcon size={22} color={icon} />
|
||||
{post.comment_count > 0 && <Text className={`text-[13px] font-extrabold ${text}`}>{post.comment_count.toLocaleString()}</Text>}
|
||||
</Pressable>
|
||||
</>
|
||||
)}
|
||||
<Pressable onPress={share} hitSlop={6} accessibilityRole="button" accessibilityLabel="오늘 날씨 보내기" className="h-8 flex-row items-center px-[5px] opacity-80">
|
||||
<SendIcon size={22} color={icon} />
|
||||
</Pressable>
|
||||
</View>
|
||||
</View>
|
||||
<View className="h-[146px] items-center">
|
||||
<Fall d={0} f={5600} amp={8}>
|
||||
<View className="mt-2 size-32 items-center justify-center" style={moon ? undefined : { boxShadow: `0 20px 40px ${kind === 'night' ? 'rgb(190 180 255 / 0.35)' : kind === 'sunset' ? 'rgb(255 150 110 / 0.4)' : 'rgb(240 106 58 / 0.32)'}`, borderRadius: 64 }}>
|
||||
@@ -183,12 +284,15 @@ export function Hero({ hero, today, ranked, feedLoad, todayLoad }: Props) {
|
||||
<Rect x="-1" y="-1" width="2" height="2" rx="1" fill="url(#orb)" opacity={gray ? 0.85 : 1} />
|
||||
</Svg>
|
||||
)}
|
||||
<Text className="font-jua text-[12px]" style={orbText}>
|
||||
{failed(feedLoad) ? '점수를 못 불러왔어요' : `${slotScore != null && mode !== 'now' ? PREVIEW[mode].label : '지금'} 날씨 점수`}
|
||||
</Text>
|
||||
<Text className="font-bagel text-[52px] leading-[52px]" style={orbText}>
|
||||
{heroVal(feedLoad, score, 'w-[84px] h-10')}
|
||||
</Text>
|
||||
{/* 점수 근거가 있으면 해를 눌러도 근거 창 */}
|
||||
<Pressable disabled={!why || score == null} onPress={openWhy} className="items-center" accessibilityLabel={why && score != null ? `${whyLabel} 날씨 점수 ${score}점, 어떻게 나왔는지 보기` : undefined}>
|
||||
<Text className="font-jua text-[12px]" style={orbText}>
|
||||
{failed(feedLoad) ? '점수를 못 불러왔어요' : `${tmr && mode !== 'now' ? `내일 ${PREVIEW[mode].label}` : slotScore != null && mode !== 'now' ? PREVIEW[mode].label : '지금'} 날씨 점수`}
|
||||
</Text>
|
||||
<Text className="font-bagel text-[52px] leading-[52px]" style={orbText}>
|
||||
{heroVal(feedLoad, score, 'w-[84px] h-10')}
|
||||
</Text>
|
||||
</Pressable>
|
||||
</View>
|
||||
</Fall>
|
||||
{CLOUDS.slice(0, CLOUD_N[weather]).map((c) => (
|
||||
@@ -217,19 +321,24 @@ export function Hero({ hero, today, ranked, feedLoad, todayLoad }: Props) {
|
||||
</Text>
|
||||
</Text>
|
||||
))}
|
||||
{why && score != null && (
|
||||
<Text onPress={openWhy} accessibilityRole="button" accessibilityLabel={`${whyLabel} 날씨 점수 ${score}점, 어떻게 나왔는지 보기`} style={{ color: dark ? '#ffb38a' : '#d4552a' }}>
|
||||
{' '}· 점수 근거 ›
|
||||
</Text>
|
||||
)}
|
||||
</Text>
|
||||
)}
|
||||
</View>
|
||||
<View className="mt-2.5 flex-row gap-1 rounded-[18px] p-[3px]" style={{ backgroundColor: dark ? 'rgb(255 255 255 / 0.14)' : 'rgb(255 255 255 / 0.42)' }} accessibilityRole="tablist" accessibilityLabel="하루 흐름, 누르면 그 시간대 하늘로">
|
||||
{KINDS.map((k) => {
|
||||
const isNow = k === nowKind;
|
||||
const isNow = !tmr && k === nowKind;
|
||||
const s = slotOf(isNow ? 'now' : k);
|
||||
const on = k === kind;
|
||||
return (
|
||||
<Pressable key={k} accessibilityRole="tab" accessibilityState={{ selected: on }} onPress={() => setPreview(isNow ? null : k)} className={`flex-1 items-center rounded-[14px] py-1.5 ${on ? 'bg-white' : ''}`} style={on ? { boxShadow: '0 4px 12px rgb(40 48 74 / 0.1)' } : undefined}>
|
||||
<Pressable key={k} accessibilityRole="tab" accessibilityState={{ selected: on }} onPress={() => (tmr ? setTmrKind(k) : setPreview(isNow ? null : k))} className={`flex-1 items-center rounded-[14px] py-1.5 ${on ? 'bg-white' : ''}`} style={on ? { boxShadow: '0 4px 12px rgb(40 48 74 / 0.1)' } : undefined}>
|
||||
<Text className={`text-[13px] font-bold ${on ? 'text-[#d4552a]' : `opacity-75 ${text}`}`}>{isNow ? '지금' : PREVIEW[k].label}</Text>
|
||||
<Ic name={k === 'night' && weatherOf(s) === 'clear' ? 'moon' : WEATHER_ICON[weatherOf(s)]} size={22} style={{ marginVertical: 2 }} />
|
||||
<Text className={`font-jua text-[15px] ${on ? 'text-[#28304a]' : text}`}>{heroVal(todayLoad, s?.temp_c != null ? deg(s.temp_c) : null, 'w-7')}</Text>
|
||||
<Text className={`font-jua text-[15px] ${on ? 'text-[#28304a]' : text}`}>{heroVal(slotsLoad, s?.temp_c != null ? deg(s.temp_c) : null, 'w-7')}</Text>
|
||||
</Pressable>
|
||||
);
|
||||
})}
|
||||
|
||||
Reference in new issue
Block a user