chore: main 병합 — 지금 날씨 점수 보정을 바꾸기 표로 통일
- index_service.py 충돌: main 의 오늘·내일 날씨 점수 계산은 그대로 쓰고, 보정만 strict_weather 에서 구간별 바꾸기 표(weather_slot_scores)로 바꿈
- weather_slot_scores 는 main 의 weather_why 가 쓰는 점수 근거(factors)를 그대로 둔 Result 를 돌려줌
- strict_weather 와 그 테스트(test_weather_score_is_strict_near_top) 삭제 (바꾸기 표로 통일하기로 정함)
- test_board_activates_gak_outside_its_time_window 의 ensure 스텁을 main 의 {날짜: {구간: Result}} 모양으로 맞춤
This commit is contained in:
commit
621a0cf90d
133 files changed
+8963
-489
No files matched your search
+367
-108
@@ -1,15 +1,35 @@
|
||||
import { Fragment, useEffect, useState, type ReactNode } from 'react'
|
||||
import { Link } from 'react-router'
|
||||
import { Fragment, useEffect, useRef, useState, type ReactNode } from 'react'
|
||||
import { Link, useLocation } from 'react-router'
|
||||
import { useQuery } from '@tanstack/react-query'
|
||||
import { getFeedOptions, getWeatherTodayOptions } from '../api/client/@tanstack/react-query.gen'
|
||||
import { RainType, Sky, type BandArticle, type BandEvent, type Hero as HeroData, type ResWeatherToday, type TopIndex, type WeatherSlot } from '../api/client/types.gen'
|
||||
import {
|
||||
RainType,
|
||||
Sky,
|
||||
type BandArticle,
|
||||
type BandEvent,
|
||||
type Hero as HeroData,
|
||||
type PostReaction,
|
||||
type ResWeatherToday,
|
||||
type TalkData,
|
||||
type TopIndex,
|
||||
type WeatherSlot,
|
||||
} from '../api/client/types.gen'
|
||||
import { cx } from '../lib/utils'
|
||||
import { cardBg, fall, kindOfHour, kst, type Load, loadOf, MEDALS, type TimeKind, WEEKDAYS } from './lib'
|
||||
import { PostCard, PostCardSkel } from './Post'
|
||||
import { FoliageCard } from './foliageMap'
|
||||
import { InstallBanner } from './installBanner'
|
||||
import { MyGakRow } from './myGak'
|
||||
import { fromShare } from './myGakState'
|
||||
import { PostCard, PostCardSkel, PostFrame } from './Post'
|
||||
import { usePinnedLike } from './pinnedLike'
|
||||
import { FeedComposer, TalkCard } from './talk'
|
||||
import { useFeedTalks } from './talkState'
|
||||
import { useRegion } from './regionContext'
|
||||
import { useSheet } from './sheetContext'
|
||||
import { useSky } from './skyContext'
|
||||
import { Ic, Rail, Sec, Skel, SkelRail, StateBox, Thumb } from './ui'
|
||||
import { DayShareCard, DayShareGrid, GakShareCard, type DayShare } from './shareCards'
|
||||
import { CommentIcon, HeartIcon, SendIcon } from './svg'
|
||||
import { Ic, Rail, Sec, Skel, StateBox, TAP44, Thumb } from './ui'
|
||||
import { deg, slotAt } from './weatherText'
|
||||
|
||||
type Mode = 'now' | TimeKind
|
||||
@@ -24,10 +44,24 @@ const PREVIEW: Record<TimeKind, { label: string; hour: number }> = {
|
||||
}
|
||||
|
||||
// 비·눈 줄기: 위치·주기를 엇갈려 고르게
|
||||
const DROPS = Array.from({ length: 22 }, (_, i) => ({ left: `${(i * 41) % 100}%`, '--top': `${(i * 29) % 90}%`, '--dl': `${((i * 37) % 100) / 100}s`, '--dur': `${0.55 + ((i * 13) % 5) / 10}s` }))
|
||||
const FLAKES = Array.from({ length: 16 }, (_, i) => ({ left: `${(i * 47) % 100}%`, '--top': `${(i * 31) % 90}%`, '--dl': `${((i * 53) % 100) / 25}s`, '--dur': `${3.2 + ((i * 7) % 5) / 2}s` }))
|
||||
const DROPS = Array.from({ length: 22 }, (_, i) => ({
|
||||
left: `${(i * 41) % 100}%`,
|
||||
'--top': `${(i * 29) % 90}%`,
|
||||
'--dl': `${((i * 37) % 100) / 100}s`,
|
||||
'--dur': `${0.55 + ((i * 13) % 5) / 10}s`,
|
||||
}))
|
||||
const FLAKES = Array.from({ length: 16 }, (_, i) => ({
|
||||
left: `${(i * 47) % 100}%`,
|
||||
'--top': `${(i * 31) % 90}%`,
|
||||
'--dl': `${((i * 53) % 100) / 25}s`,
|
||||
'--dur': `${3.2 + ((i * 7) % 5) / 2}s`,
|
||||
}))
|
||||
|
||||
const STARS = Array.from({ length: 26 }, (_, i) => ({ left: `${(i * 37) % 100}%`, top: `${(i * 53) % 60}%`, opacity: 0.4 + ((i * 7) % 6) / 10 }))
|
||||
const STARS = Array.from({ length: 26 }, (_, i) => ({
|
||||
left: `${(i * 37) % 100}%`,
|
||||
top: `${(i * 53) % 60}%`,
|
||||
opacity: 0.4 + ((i * 7) % 6) / 10,
|
||||
}))
|
||||
// 별똥별 셋: 위치·길이·주기를 엇갈려 하나씩 떨어지게
|
||||
const SHOOTS = [
|
||||
{ top: '6%', left: '80%', '--len': '90px', '--dur': '7s', '--dl': '1.5s' },
|
||||
@@ -65,7 +99,12 @@ function heroVal(load: Load, v: ReactNode, skel: string) {
|
||||
const failed = (load: Load) => load === 'error' || load === 'retrying'
|
||||
|
||||
// 미리보기 탭과 서버 구간 이름. 저녁 탭(노을 하늘)은 서버의 evening 구간
|
||||
const SLOT_KEY: Record<TimeKind, string> = { morning: 'morning', day: 'day', sunset: 'evening', night: 'night' }
|
||||
const SLOT_KEY: Record<TimeKind, string> = {
|
||||
morning: 'morning',
|
||||
day: 'day',
|
||||
sunset: 'evening',
|
||||
night: 'night',
|
||||
}
|
||||
|
||||
/** 미리보기 시간대면 서버가 해당 구간의 날씨·시간대 적합도로 계산한 점수·순위로 다시 줄 세운다. 구간 값이 없으면(예전 캐시) 그대로 */
|
||||
function atSlot(items: TopIndex[], kind: TimeKind | null): TopIndex[] {
|
||||
@@ -73,12 +112,27 @@ function atSlot(items: TopIndex[], kind: TimeKind | null): TopIndex[] {
|
||||
if (!k || !items.some((g) => Object.keys(g.slot_ranks ?? {}).length)) return items
|
||||
const on = items.filter((g) => g.slot_ranks?.[k] != null && g.slots?.[k] != null)
|
||||
return [
|
||||
...on.map((g) => ({ ...g, score: g.slots![k], rank: g.slot_ranks![k], active: true })).sort((a, b) => a.rank - b.rank),
|
||||
...on
|
||||
.map((g) => ({
|
||||
...g,
|
||||
score: g.slots![k],
|
||||
rank: g.slot_ranks![k],
|
||||
active: true,
|
||||
}))
|
||||
.sort((a, b) => a.rank - b.rank),
|
||||
...items.filter((g) => !on.includes(g)).map((g) => ({ ...g, active: false })),
|
||||
]
|
||||
}
|
||||
|
||||
type HeroProps = { hero?: HeroData | null; today?: ResWeatherToday; ranked: TopIndex[]; feedLoad: Load; todayLoad: Load }
|
||||
type HeroProps = {
|
||||
hero?: HeroData | null
|
||||
post?: PostReaction | null
|
||||
today?: ResWeatherToday
|
||||
ranked: TopIndex[]
|
||||
all: TopIndex[]
|
||||
feedLoad: Load
|
||||
todayLoad: Load
|
||||
}
|
||||
|
||||
type Weather = 'clear' | 'partly' | 'cloudy' | 'rain' | 'snow' | 'sleet'
|
||||
|
||||
@@ -91,26 +145,67 @@ function weatherOf(slot?: WeatherSlot): Weather {
|
||||
return slot?.sky === Sky.CLOUDY ? 'cloudy' : slot?.sky === Sky.PARTLY ? 'partly' : 'clear'
|
||||
}
|
||||
|
||||
const WEATHER_ICON: Record<Weather, string> = { clear: 'sun', partly: 'sun_cloud', cloudy: 'cloud', rain: 'rain', snow: 'snow', sleet: 'snow' }
|
||||
const WEATHER_ICON: Record<Weather, string> = {
|
||||
clear: 'sun',
|
||||
partly: 'sun_cloud',
|
||||
cloudy: 'cloud',
|
||||
rain: 'rain',
|
||||
snow: 'snow',
|
||||
sleet: 'snow',
|
||||
}
|
||||
// 구름 수: 구름 많음 둘, 흐림·비·눈 셋
|
||||
const CLOUDS = [
|
||||
{ cls: 'top-9 left-[5%] h-8 w-[84px]', d: '.1s', f: '6s' },
|
||||
{ cls: 'top-[96px] left-[63%] h-9 w-[96px]', d: '.25s', f: '6.4s' },
|
||||
{ cls: 'top-[30px] left-[72%] h-7 w-[64px]', d: '.4s', f: '5.4s' },
|
||||
]
|
||||
const CLOUD_N: Record<Weather, number> = { clear: 0, partly: 2, cloudy: 3, rain: 3, snow: 3, sleet: 3 }
|
||||
const CLOUD_N: Record<Weather, number> = {
|
||||
clear: 0,
|
||||
partly: 2,
|
||||
cloudy: 3,
|
||||
rain: 3,
|
||||
snow: 3,
|
||||
sleet: 3,
|
||||
}
|
||||
|
||||
function Hero({ hero, today, ranked, feedLoad, todayLoad }: HeroProps) {
|
||||
function Hero({ hero, post, today, ranked, all, feedLoad, todayLoad }: HeroProps) {
|
||||
const { open } = useSheet()
|
||||
const like = usePinnedLike('hero_post', post)
|
||||
const { region } = useRegion()
|
||||
const tplRef = useRef<HTMLDivElement>(null)
|
||||
const gridRef = useRef<HTMLDivElement>(null)
|
||||
// 내일 스위치: 내일 칸 날씨는 켤 때 받고, 시간대는 화면 전체 하늘과 따로 히어로 안에서만 고른다
|
||||
// 내일 날씨 페이지(/tomorrow/...)로 들어오면 내일이 켜진 채로
|
||||
const { pathname } = useLocation()
|
||||
const [tmr, setTmr] = useState(() => pathname.startsWith('/tomorrow/'))
|
||||
const [tmrKind, setTmrKind] = useState<TimeKind>('day')
|
||||
const tomorrowQ = useQuery({
|
||||
...getWeatherTodayOptions({
|
||||
query: { region: region.code, day: 'tomorrow' },
|
||||
}),
|
||||
enabled: tmr,
|
||||
})
|
||||
const ahead = hero?.tomorrow
|
||||
const share = () =>
|
||||
tplRef.current &&
|
||||
open({
|
||||
type: 'share',
|
||||
share: {
|
||||
title: `${region.name} ${tmr ? '내일' : '오늘'} 날씨`,
|
||||
slides: [tplRef.current],
|
||||
square: gridRef.current ? [gridRef.current] : undefined,
|
||||
},
|
||||
})
|
||||
const { preview, setServerKind, setPreview } = useSky()
|
||||
const mode: Mode = preview ?? 'now'
|
||||
const mode: Mode = tmr ? tmrKind : (preview ?? 'now')
|
||||
const clock = useNow()
|
||||
const t = kst(clock)
|
||||
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 ?? []
|
||||
const slots = (tmr ? tomorrowQ.data?.slots : today?.slots) ?? []
|
||||
const slotsLoad = tmr ? loadOf(tomorrowQ) : todayLoad
|
||||
// 그 시각 칸, 비어 있으면(지난 새벽 칸 등) 그 뒤 첫 예보 칸
|
||||
// 지금은 가장 가까운 3시간 칸(17시면 18시 칸). 시간대는 그 시각 칸, 비어 있으면(지난 새벽 칸 등) 그 뒤 첫 예보 칸
|
||||
const slotOf = (k: TimeKind | 'now') => {
|
||||
@@ -124,22 +219,78 @@ function Hero({ hero, today, ranked, feedLoad, todayLoad }: HeroProps) {
|
||||
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 moon = (kind === 'sunset' || kind === 'night') && hero?.moon_name && hero.moon_pct != null ? { name: hero.moon_name, pct: hero.moon_pct, waning: WANING.includes(hero.moon_name) } : null
|
||||
const moon =
|
||||
!tmr && (kind === 'sunset' || kind === 'night') && hero?.moon_name && hero.moon_pct != null
|
||||
? {
|
||||
name: hero.moon_name,
|
||||
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 bubble = tmr
|
||||
? top1
|
||||
? top1.score >= 70
|
||||
? `내일은 ${top1.name}!`
|
||||
: '내일은 쉬어 가요'
|
||||
: 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 rain = weather === 'rain' || weather === 'sleet'
|
||||
const snow = weather === 'snow' || weather === 'sleet'
|
||||
|
||||
// 공유 이미지: 아침~밤 네 시간대 모두. 점수는 시간대 점수, 각은 그 시간대 1등
|
||||
const days: DayShare[] = KINDS.map((k) => {
|
||||
const isNow = !tmr && k === nowKind
|
||||
const s = slotOf(isNow ? 'now' : k)
|
||||
const top = tmr ? ahead?.top1 : atSlot(all, k).find((g) => g.active)
|
||||
return {
|
||||
kind: k,
|
||||
label: PREVIEW[k].label,
|
||||
now: isNow,
|
||||
icon: k === 'night' && weatherOf(s) === 'clear' ? 'moon' : WEATHER_ICON[weatherOf(s)],
|
||||
temp: s?.temp_c != null ? deg(s.temp_c) : '–',
|
||||
score: (tmr ? ahead?.weather_slots : hero?.weather_slots)?.[SLOT_KEY[k]] ?? (isNow ? hero?.weather_score : null),
|
||||
gak: top ? { name: top.name, icon: top.icon } : null,
|
||||
}
|
||||
})
|
||||
|
||||
// 시안 D4-2: 가운데 해(점수)와 하늘 날씨, 결론 두 줄, 상태 한 줄, 아래 하루 흐름 칸(누르면 그 시간대 하늘로)
|
||||
return (
|
||||
<div className="b-hero relative mx-3 mt-1 overflow-hidden rounded-[28px] px-4 pt-3 pb-3" data-t={kind} data-sky={weather}>
|
||||
<DayShareCard days={days} ref={tplRef} />
|
||||
<DayShareGrid days={days} ref={gridRef} />
|
||||
<div className="b-stars pointer-events-none absolute inset-0" aria-hidden="true">
|
||||
{STARS.map((s, i) => (
|
||||
<i key={i} className="absolute size-[3px] rounded-full shadow-[0_0_6px_#fff]" style={s} />
|
||||
@@ -154,29 +305,109 @@ function Hero({ hero, today, ranked, feedLoad, todayLoad }: HeroProps) {
|
||||
{snow && FLAKES.map((s, i) => <i key={i} className="b-flake" style={s} />)}
|
||||
</div>
|
||||
)}
|
||||
<p className="relative z-[3] m-0 text-[14px] font-bold opacity-80">
|
||||
{t.mo}월 {t.d}일 {WEEKDAYS[t.wd]}요일
|
||||
</p>
|
||||
<div className="relative z-[3] flex items-center justify-between">
|
||||
<span className="flex items-center gap-2">
|
||||
<span className="b-strip grid grid-cols-2 rounded-full p-[3px]" role="radiogroup" aria-label="오늘 또는 내일 날씨">
|
||||
{(
|
||||
[
|
||||
[false, '오늘'],
|
||||
[true, '내일'],
|
||||
] as const
|
||||
).map(([v, l]) => (
|
||||
<button
|
||||
key={l}
|
||||
type="button"
|
||||
role="radio"
|
||||
aria-checked={tmr === v}
|
||||
onClick={() => setTmr(v)}
|
||||
className={cx('cursor-pointer rounded-full px-2.5 py-0.5 font-jua text-[13px]', tmr === v ? 'b-strip-on text-(--orange-deep)' : 'opacity-75')}
|
||||
>
|
||||
{l}
|
||||
</button>
|
||||
))}
|
||||
</span>
|
||||
<span className="text-[13px] font-bold opacity-80">
|
||||
{t.mo}월 {t.d}일 {WEEKDAYS[t.wd]}요일
|
||||
</span>
|
||||
</span>
|
||||
<span className="flex items-center gap-3 [&_svg]:size-[22px] [&_svg]:stroke-[2]">
|
||||
{post && (
|
||||
<>
|
||||
<button
|
||||
type="button"
|
||||
onClick={like.toggle}
|
||||
aria-pressed={like.liked}
|
||||
aria-label={like.failed ? '좋아요를 반영하지 못했어요. 다시 눌러 주세요' : '오늘 날씨 좋아요'}
|
||||
className={cx('relative flex cursor-pointer items-center gap-1 text-[13px] font-extrabold', TAP44, !like.liked && 'opacity-80')}
|
||||
>
|
||||
<HeartIcon className={like.liked ? 'fill-(--heart) stroke-(--heart)' : 'fill-none stroke-current'} />
|
||||
{like.count > 0 && like.count.toLocaleString()}
|
||||
</button>
|
||||
<button
|
||||
type="button"
|
||||
onClick={() => open({ type: 'comments', postId: post.post_id })}
|
||||
aria-label="오늘 날씨 댓글"
|
||||
className={cx('relative flex cursor-pointer items-center gap-1 text-[13px] font-extrabold opacity-80', TAP44)}
|
||||
>
|
||||
<CommentIcon className="fill-none stroke-current [stroke-linejoin:round]" />
|
||||
{post.comment_count > 0 && post.comment_count.toLocaleString()}
|
||||
</button>
|
||||
</>
|
||||
)}
|
||||
<button type="button" onClick={share} aria-label="오늘 날씨 보내기" className={cx('relative grid size-7 cursor-pointer place-items-center opacity-80', TAP44)}>
|
||||
<SendIcon className="fill-none stroke-current [stroke-linecap:round] [stroke-linejoin:round]" />
|
||||
</button>
|
||||
</span>
|
||||
</div>
|
||||
<div className="relative h-[146px]">
|
||||
{CLOUDS.slice(0, CLOUD_N[weather]).map((c) => (
|
||||
<span key={c.cls} className={cx('b-cloud b-fall z-[1]', c.cls)} style={fall(c.d, c.f)} aria-hidden="true" />
|
||||
))}
|
||||
<div className="b-sun b-fall absolute top-2 left-1/2 -ml-16 grid aspect-square w-32 place-items-center rounded-full text-center" style={fall('0s', '5.6s', '8px')}>
|
||||
{/* 안 보이는 쪽을 덮어 오늘 밤 달 모양으로 */}
|
||||
{moon && (
|
||||
<svg viewBox="-1 -1 2 2" className="pointer-events-none absolute inset-0 size-full" aria-hidden="true">
|
||||
<path d={moonPath(moon.pct, 1, false)} fill={kind === 'sunset' ? 'rgb(96 40 86 / .55)' : 'rgb(34 30 86 / .62)'} transform={moon.waning ? 'scale(-1,1)' : undefined} />
|
||||
</svg>
|
||||
)}
|
||||
<span className={cx('relative', moon && '[text-shadow:0_0_6px_#fff,0_0_12px_#fff]')}>
|
||||
<small className="block font-jua text-[12px]">{failed(feedLoad) ? '점수를 못 불러왔어요' : `${slotScore != null && mode !== 'now' ? PREVIEW[mode].label : '지금'} 날씨 점수`}</small>
|
||||
<b className="block font-bagel text-[52px] leading-[0.95] font-normal">{heroVal(feedLoad, score, 'w-[84px]')}</b>
|
||||
<span key={c.cls} className={cx('b-fall absolute z-[1]', c.cls)} style={fall(c.d, c.f)} aria-hidden="true">
|
||||
<span className="b-cloud b-bob inset-0" />
|
||||
</span>
|
||||
))}
|
||||
<div className="b-fall absolute top-2 left-1/2 -ml-16 aspect-square w-32" style={fall('0s', '5.6s')}>
|
||||
<div className="b-sun b-bob relative grid size-full place-items-center rounded-full text-center">
|
||||
{/* 안 보이는 쪽을 덮어 오늘 밤 달 모양으로 */}
|
||||
{moon && (
|
||||
<svg viewBox="-1 -1 2 2" className="pointer-events-none absolute inset-0 size-full" aria-hidden="true">
|
||||
<path d={moonPath(moon.pct, 1, false)} fill={kind === 'sunset' ? 'rgb(96 40 86 / .55)' : 'rgb(34 30 86 / .62)'} transform={moon.waning ? 'scale(-1,1)' : undefined} />
|
||||
</svg>
|
||||
)}
|
||||
<span className={cx('relative', moon && '[text-shadow:0_0_6px_#fff,0_0_12px_#fff]')}>
|
||||
<small className="block font-jua text-[12px]">
|
||||
{failed(feedLoad) ? '점수를 못 불러왔어요' : `${tmr && mode !== 'now' ? `내일 ${PREVIEW[mode].label}` : slotScore != null && mode !== 'now' ? PREVIEW[mode].label : '지금'} 날씨 점수`}
|
||||
</small>
|
||||
<b className="block font-bagel text-[52px] leading-[0.95] font-normal">{heroVal(feedLoad, score, 'w-[84px]')}</b>
|
||||
</span>
|
||||
{why && score != null && (
|
||||
<button
|
||||
type="button"
|
||||
onClick={() =>
|
||||
open({
|
||||
type: 'weatherWhy',
|
||||
why: { label: whyLabel, score, why },
|
||||
})
|
||||
}
|
||||
aria-label={`${whyLabel} 날씨 점수 ${score}점, 어떻게 나왔는지 보기`}
|
||||
className={cx(
|
||||
'absolute right-0 bottom-1 z-[2] grid size-7 cursor-pointer place-items-center rounded-full bg-white font-jua text-[16px] text-(--orange-deep) shadow-[0_2px_6px_rgb(40_48_74/0.25)]',
|
||||
TAP44,
|
||||
)}
|
||||
>
|
||||
?
|
||||
</button>
|
||||
)}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div className="relative z-[3] text-center">
|
||||
{top1 ? (
|
||||
<button type="button" onClick={() => open({ type: 'gak', indexId: top1.index_id })} aria-label={`${bubble ?? ''} 1위 ${top1.name} ${top1.score}점, 계산 근거 보기`} className="cursor-pointer font-jua text-[24px] leading-tight">
|
||||
<button
|
||||
type="button"
|
||||
onClick={() => open({ type: 'gak', indexId: top1.index_id })}
|
||||
aria-label={`${bubble ?? ''} 1위 ${top1.name} ${top1.score}점, 계산 근거 보기`}
|
||||
className="cursor-pointer font-jua text-[24px] leading-tight"
|
||||
>
|
||||
{bubble}
|
||||
</button>
|
||||
) : (
|
||||
@@ -188,7 +419,11 @@ function Hero({ hero, today, ranked, feedLoad, todayLoad }: HeroProps) {
|
||||
<p className="m-0 mt-1.5 flex flex-wrap justify-center gap-x-1.5 font-jua text-[14px]">
|
||||
{status.map((x, i) => (
|
||||
<Fragment key={x.label}>
|
||||
{i > 0 && <span className="opacity-30" aria-hidden="true">·</span>}
|
||||
{i > 0 && (
|
||||
<span className="opacity-30" aria-hidden="true">
|
||||
·
|
||||
</span>
|
||||
)}
|
||||
<span className={cx('whitespace-nowrap', x.tone === 'warn' && 'b-warn')}>
|
||||
<span className={cx(x.tone !== 'warn' && 'opacity-75')}>{x.label}</span> <b className="font-normal">{x.value}</b>
|
||||
</span>
|
||||
@@ -199,14 +434,21 @@ function Hero({ hero, today, ranked, feedLoad, todayLoad }: HeroProps) {
|
||||
</div>
|
||||
<div className="b-strip relative z-[3] mt-2.5 grid grid-cols-4 gap-1 rounded-[18px] p-[3px]" role="tablist" aria-label="하루 흐름, 누르면 그 시간대 하늘로">
|
||||
{KINDS.map((k) => {
|
||||
const isNow = k === nowKind
|
||||
const isNow = !tmr && k === nowKind
|
||||
const s = slotOf(isNow ? 'now' : k)
|
||||
const on = k === kind
|
||||
return (
|
||||
<button key={k} type="button" role="tab" aria-selected={on} onClick={() => setPreview(isNow ? null : k)} className={cx('flex cursor-pointer flex-col items-center rounded-[14px] py-1.5', on && 'b-strip-on')}>
|
||||
<button
|
||||
key={k}
|
||||
type="button"
|
||||
role="tab"
|
||||
aria-selected={on}
|
||||
onClick={() => (tmr ? setTmrKind(k) : setPreview(isNow ? null : k))}
|
||||
className={cx('flex cursor-pointer flex-col items-center rounded-[14px] py-1.5', on && 'b-strip-on')}
|
||||
>
|
||||
<span className={cx('text-[13px] font-bold', on ? 'text-(--orange-deep)' : 'opacity-75')}>{isNow ? '지금' : PREVIEW[k].label}</span>
|
||||
<Ic name={k === 'night' && weatherOf(s) === 'clear' ? 'moon' : WEATHER_ICON[weatherOf(s)]} className="my-0.5 h-[22px] w-[22px] object-contain" />
|
||||
<b className="font-jua text-[15px] font-normal">{heroVal(todayLoad, s?.temp_c != null ? deg(s.temp_c) : null, 'w-7')}</b>
|
||||
<b className="font-jua text-[15px] font-normal">{heroVal(slotsLoad, s?.temp_c != null ? deg(s.temp_c) : null, 'w-7')}</b>
|
||||
</button>
|
||||
)
|
||||
})}
|
||||
@@ -227,27 +469,42 @@ function moonPath(pct: number, r: number, lit: boolean) {
|
||||
return `M0,${-r} A${r},${r} 0 0 ${lit ? 1 : 0} 0,${r} ${edge}`
|
||||
}
|
||||
|
||||
function Stories({ items }: { items: TopIndex[] }) {
|
||||
function GakCard({ items, post, place, at }: { items: TopIndex[]; post?: PostReaction | null; place: string; at: string }) {
|
||||
const { open } = useSheet()
|
||||
const tplRef = useRef<HTMLDivElement>(null)
|
||||
const top = items.filter((g) => g.active).slice(0, 5)
|
||||
return (
|
||||
<Rail label="오늘의 각 순위">
|
||||
{items.map((g, i) => (
|
||||
<button key={g.index_id} type="button" onClick={() => open({ type: 'gak', indexId: g.index_id })} aria-label={g.active ? `${g.rank}위 ${g.name} ${g.score}점` : `${g.name}, 지금 시간대 아님`} className={cx('flex w-[72px] cursor-pointer flex-col items-center gap-1', !g.active && 'opacity-55')}>
|
||||
<span className={cx('relative size-[68px] rounded-full p-[3px]', !g.active || g.score < 50 ? 'bg-[#d6deea]' : 'b-ring')}>
|
||||
<i className="grid size-full place-items-center rounded-full border-[3px] border-(--page) bg-(--page)">
|
||||
<Ic name={g.icon} className="w-[42px]" />
|
||||
</i>
|
||||
{i < 3 && g.active && <Ic name={MEDALS[i]} className="absolute -right-1 -bottom-1 w-[25px]" />}
|
||||
</span>
|
||||
<b className="font-jua text-[13px] font-normal whitespace-nowrap">{g.name}</b>
|
||||
{g.active ? (
|
||||
<em className="font-bagel text-[12.5px] leading-none text-(--orange) not-italic">{g.score}</em>
|
||||
) : (
|
||||
<small className="text-[11px] leading-none font-extrabold text-(--ink3)">지금 아님</small>
|
||||
)}
|
||||
</button>
|
||||
))}
|
||||
</Rail>
|
||||
<PostFrame
|
||||
title={`오늘의 각 · ${place}`}
|
||||
account="오늘의 각"
|
||||
avatar="rabbit"
|
||||
more={<Link to="/gak">전체 보기</Link>}
|
||||
caption="누르면 계산 근거를 보여 줘요"
|
||||
shot={tplRef}
|
||||
pinned={{ key: 'gak_post', post }}
|
||||
>
|
||||
<GakShareCard items={top} title={`오늘의 각 · ${place} ${at}`} ref={tplRef} />
|
||||
<div className="b-band-2 px-4 pt-3.5 pb-3">
|
||||
<p className="m-0 font-jua text-[19px]">
|
||||
오늘의 각 · {place} {at}
|
||||
</p>
|
||||
<ol className="m-0 mt-2 grid list-none gap-1.5 p-0">
|
||||
{top.map((g, i) => (
|
||||
<li key={g.index_id}>
|
||||
<button type="button" onClick={() => open({ type: 'gak', indexId: g.index_id })} className="flex w-full cursor-pointer items-center gap-2.5 rounded-[18px] bg-white px-3 py-2 text-left shadow-[inset_0_-4px_0_var(--shade)]">
|
||||
{i < 3 ? <Ic name={MEDALS[i]} alt={`${i + 1}위`} className="w-[24px] shrink-0" /> : <span className="w-[24px] shrink-0 text-center font-jua text-(--ink3)">{i + 1}</span>}
|
||||
<Ic name={g.icon} className="w-[34px] shrink-0" />
|
||||
<span className="min-w-0 flex-1">
|
||||
<b className="block font-jua text-[16px] leading-tight font-normal">{g.name}</b>
|
||||
{g.summary && <small className="block truncate text-xs font-semibold text-(--ink2)">{g.summary}</small>}
|
||||
</span>
|
||||
<em className="font-bagel text-[22px] leading-none text-(--orange) not-italic">{g.score}</em>
|
||||
</button>
|
||||
</li>
|
||||
))}
|
||||
</ol>
|
||||
</div>
|
||||
</PostFrame>
|
||||
)
|
||||
}
|
||||
|
||||
@@ -260,27 +517,6 @@ function PostsSkel() {
|
||||
)
|
||||
}
|
||||
|
||||
const STORY_SKELS = Array.from({ length: 6 }, (_, i) => i)
|
||||
|
||||
/** Stories 와 같은 칸(68px 동그라미 + 이름 + 점수)을 6개 */
|
||||
function StoriesSkel() {
|
||||
return (
|
||||
<SkelRail>
|
||||
{STORY_SKELS.map((i) => (
|
||||
<span key={i} className="flex w-[72px] flex-col items-center gap-1">
|
||||
<Skel shape className="size-[68px] rounded-full" />
|
||||
<b className="font-jua text-[13px] font-normal">
|
||||
<Skel className="w-12" />
|
||||
</b>
|
||||
<em className="font-bagel text-[12.5px] leading-none not-italic">
|
||||
<Skel className="w-6" />
|
||||
</em>
|
||||
</span>
|
||||
))}
|
||||
</SkelRail>
|
||||
)
|
||||
}
|
||||
|
||||
function Band({ tone, title, sub, to, children }: { tone: 1 | 2 | 3; title: string; sub: string; to: string; children: ReactNode }) {
|
||||
return (
|
||||
<section className={cx('mt-3.5 pt-4 pb-3.5', `b-band-${tone}`)} aria-label={title}>
|
||||
@@ -309,25 +545,6 @@ function EventsBand({ events }: { events: BandEvent[] }) {
|
||||
)
|
||||
}
|
||||
|
||||
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) => (
|
||||
<button key={g.index_id} type="button" onClick={() => open({ type: 'gak', indexId: g.index_id })} className="relative flex w-[138px] cursor-pointer flex-col items-start gap-1 rounded-[22px] bg-white p-3 text-left shadow-[inset_0_-5px_0_var(--shade)]">
|
||||
{i < 3 ? <Ic name={MEDALS[i]} alt={`${i + 1}위`} className="absolute top-2 left-2 w-[26px]" /> : <span className="absolute top-2.5 left-3 font-jua text-(--ink3)">{i + 1}위</span>}
|
||||
<Ic name={g.icon} className="w-[58px] self-center" />
|
||||
<b className="font-jua text-base font-normal">{g.name}</b>
|
||||
<em className="font-bagel text-[22px] leading-none text-(--orange) not-italic">{g.score}</em>
|
||||
{g.summary && <small className="text-xs font-semibold text-(--ink2)">{g.summary}</small>}
|
||||
</button>
|
||||
))}
|
||||
</Rail>
|
||||
</Band>
|
||||
)
|
||||
}
|
||||
|
||||
function SeasonBand({ news }: { news: BandArticle[] }) {
|
||||
const { open } = useSheet()
|
||||
return (
|
||||
@@ -347,11 +564,14 @@ function SeasonBand({ news }: { news: BandArticle[] }) {
|
||||
)
|
||||
}
|
||||
|
||||
const TALK_EVERY = 3
|
||||
|
||||
export function TodayPage() {
|
||||
const { region } = useRegion()
|
||||
const feed = useQuery(getFeedOptions({ query: { region: region.code } }))
|
||||
const today = useQuery(getWeatherTodayOptions({ query: { region: region.code } }))
|
||||
const { preview } = useSky()
|
||||
const { open } = useSheet()
|
||||
const f = feed.data
|
||||
const posts = f?.posts ?? []
|
||||
const stories = atSlot(f?.stories ?? [], preview)
|
||||
@@ -359,25 +579,60 @@ export function TodayPage() {
|
||||
const bands = f?.bands
|
||||
const nowAt = f?.hero?.now_at
|
||||
const load = loadOf(feed)
|
||||
const [mine, setMine] = useState<TalkData[]>([])
|
||||
// 사람들이 쓴 글은 4·7·10번째 포스트 뒤에 하나씩(3번째 뒤 행사 띠와 안 붙게), 남은 글은 피드 끝에. 방금 올린 내 글은 글쓰기 칸 아래에 따로 있으니 빼고
|
||||
const feedTalks = useFeedTalks()
|
||||
const talks = feedTalks.talks.filter((t) => !mine.some((m) => m.talk_id === t.talk_id))
|
||||
const between = Math.max(0, Math.floor((posts.length - 1) / TALK_EVERY))
|
||||
const moreRef = useRef<HTMLDivElement>(null)
|
||||
const { more, loadMore } = feedTalks
|
||||
useEffect(() => {
|
||||
const el = moreRef.current
|
||||
if (!el || !more) return
|
||||
const io = new IntersectionObserver((es) => es.some((e) => e.isIntersecting) && loadMore(), { rootMargin: '600px' })
|
||||
io.observe(el)
|
||||
return () => io.disconnect()
|
||||
}, [more, loadMore])
|
||||
|
||||
useEffect(() => {
|
||||
window.scrollTo({ top: 0 })
|
||||
}, [region.code])
|
||||
|
||||
// 친구가 보낸 내 각 링크(/?my=...)로 들어오면 내 동네 기준으로 보여 준다
|
||||
useEffect(() => {
|
||||
const url = new URL(window.location.href)
|
||||
const code = url.searchParams.get('my')
|
||||
if (!code) return
|
||||
url.searchParams.delete('my')
|
||||
window.history.replaceState(window.history.state, '', url)
|
||||
const g = fromShare(code)
|
||||
if (g) open({ type: 'mix', shared: g })
|
||||
}, [open])
|
||||
|
||||
// 디자인대로 3·6·9번째 글 뒤에 띠를 넣고, 글이 모자라면 남은 띠는 맨 뒤에 붙인다
|
||||
const bandAt: [number, ReactNode][] = [
|
||||
[3, bands?.events?.length ? <EventsBand key="events" events={bands.events} /> : null],
|
||||
[6, bands?.top5?.length ? <TopBand key="top5" items={sloted ? stories.filter((g) => g.active) : bands.top5} sub={sloted ? `${PREVIEW[preview].label} 기준` : nowAt ? `${kst(nowAt).h}시 기준` : '오늘 기준'} /> : null],
|
||||
[9, bands?.season?.length ? <SeasonBand key="season" news={bands.season} /> : null],
|
||||
]
|
||||
|
||||
return (
|
||||
// 피드 칸은 전국 공통이라 지역이 바뀌어도 글 번호가 같다. 지역마다 새로 그려 넘긴 슬라이드·펼친 상태가 남지 않게 한다
|
||||
<section key={region.code} aria-label="오늘" aria-busy={load === 'loading'} className={cx('transition-opacity', feed.isPlaceholderData && 'opacity-60')}>
|
||||
<Hero hero={f?.hero} today={today.data} ranked={stories} feedLoad={load} todayLoad={loadOf(today)} />
|
||||
<Sec title="오늘의 각" sub="누르면 계산 근거를 보여 줘요" more={{ to: '/gak' }} />
|
||||
{/* 실패 안내는 여기 한 번만, 각 줄 스켈레톤과 같은 크기로 */}
|
||||
{stories.length ? <Stories items={stories} /> : load === 'loading' ? <StoriesSkel /> : <StateBox load={load} onRetry={() => feed.refetch()} empty="오늘 계산된 각이 없어요." hold={<StoriesSkel />} className="inset-x-3 top-3 bottom-1" />}
|
||||
<Hero hero={f?.hero} post={f?.hero_post} today={today.data} ranked={stories} all={f?.stories ?? []} feedLoad={load} todayLoad={loadOf(today)} />
|
||||
<FeedComposer onPosted={(t) => setMine((m) => [t, ...m])} />
|
||||
{mine.map((t) => (
|
||||
<TalkCard key={t.talk_id} t={t} onGone={() => setMine((m) => m.filter((x) => x.talk_id !== t.talk_id))} />
|
||||
))}
|
||||
<MyGakRow />
|
||||
{/* 실패 안내는 여기 한 번만, 각 카드 스켈레톤과 같은 크기로 */}
|
||||
{stories.some((g) => g.active) ? (
|
||||
<GakCard items={stories} post={f?.gak_post} place={region.name.split(' ').at(-1)!} at={sloted ? `${PREVIEW[preview].label} 기준` : nowAt ? `${kst(nowAt).h}시 기준` : '오늘 기준'} />
|
||||
) : load === 'loading' ? (
|
||||
<PostCardSkel />
|
||||
) : (
|
||||
<StateBox load={load} onRetry={() => feed.refetch()} empty="오늘 계산된 각이 없어요." hold={<PostCardSkel />} className="inset-x-3 top-3 bottom-1" />
|
||||
)}
|
||||
<InstallBanner />
|
||||
<div>
|
||||
{load === 'loading' && <PostsSkel />}
|
||||
{/* 글이 없거나 못 받아도 스켈레톤 두 장 자리는 그대로 둔다 */}
|
||||
@@ -387,10 +642,14 @@ export function TodayPage() {
|
||||
{posts.map((p, i) => (
|
||||
<Fragment key={p.post_id}>
|
||||
<PostCard post={p} />
|
||||
{i === 1 && <FoliageCard />}
|
||||
{i > 0 && i % TALK_EVERY === 0 && talks[i / TALK_EVERY - 1] && <TalkCard t={talks[i / TALK_EVERY - 1]} />}
|
||||
{bandAt.find(([at]) => at === i + 1)?.[1]}
|
||||
</Fragment>
|
||||
))}
|
||||
{feed.isSuccess && bandAt.filter(([at]) => at > posts.length).map(([at, node]) => <Fragment key={at}>{node}</Fragment>)}
|
||||
{load !== 'loading' && talks.slice(between).map((t) => <TalkCard key={t.talk_id} t={t} />)}
|
||||
<div ref={moreRef} aria-hidden />
|
||||
</div>
|
||||
</section>
|
||||
)
|
||||
|
||||
Reference in new issue
Block a user