89 lines
4.6 KiB
TypeScript
89 lines
4.6 KiB
TypeScript
import { useQuery } from '@tanstack/react-query'
|
||
import { Link, useLocation } from 'react-router'
|
||
import { getWeatherTodayOptions } from '@nalssigak/shared/api/client/@tanstack/react-query.gen'
|
||
import type { HeroTomorrow, HoursSlide, TomorrowEvent } from '@nalssigak/shared/api/client'
|
||
import { type Load, MEDALS } from '@nalssigak/shared/lib'
|
||
import { track } from '../lib/analytics'
|
||
import { PostCardSkel, PostFrame, SlideView } from './Post'
|
||
import { useRegion } from './regionContext'
|
||
import { Ic } from './ui'
|
||
|
||
const md = (d: string) => `${Number(d.slice(5, 7))}/${Number(d.slice(8, 10))}`
|
||
const days = (e: TomorrowEvent) => (e.start_date === e.end_date ? md(e.start_date) : `${md(e.start_date)}~${md(e.end_date)}`)
|
||
|
||
/** 내일 날씨 페이지(/tomorrow/...)의 히어로 아래. 오늘 피드 대신 내일 것만 둬서 오늘 페이지와 본문이 겹치지 않게 한다 */
|
||
export function TomorrowFeed({ tomorrow, load }: { tomorrow?: HeroTomorrow | null; load: Load }) {
|
||
const { region } = useRegion()
|
||
const { pathname } = useLocation()
|
||
const [sido] = region.name.split(' ')
|
||
const place = region.name.split(' ').at(-1)!
|
||
const w = useQuery(getWeatherTodayOptions({ query: { region: region.code, day: 'tomorrow' } })).data
|
||
const hours: HoursSlide | null =
|
||
w?.slots?.length && w.headline
|
||
? { kind: 'hours', eyebrow: '내일 하루 · 3시간마다', line: w.headline, hours: w.slots.map((s) => ({ label: s.label, icon: s.icon, temp_c: s.temp_c, tone: s.tone })) }
|
||
: null
|
||
const ranked = tomorrow?.ranked ?? []
|
||
const events = tomorrow?.events ?? []
|
||
|
||
return (
|
||
<div>
|
||
{ranked.length > 0 ? (
|
||
<PostFrame title={`내일의 각 · ${place}`} account="내일의 각" avatar="rabbit">
|
||
<div className="b-band-2 px-4 pt-3.5 pb-3">
|
||
<p className="m-0 font-jua text-[19px]">내일의 각 · {place} 하루 기준</p>
|
||
<ol className="m-0 mt-2 grid list-none gap-1.5 p-0">
|
||
{ranked.map((g, i) => (
|
||
<li key={g.index_id} className="flex items-center gap-2.5 rounded-[18px] bg-white px-3 py-2 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>
|
||
</li>
|
||
))}
|
||
</ol>
|
||
</div>
|
||
</PostFrame>
|
||
) : (
|
||
load === 'loading' && <PostCardSkel />
|
||
)}
|
||
{hours && (
|
||
<PostFrame title="내일 날씨" account="내일 날씨" avatar="sun">
|
||
<div className="relative flex aspect-[4/5] overflow-hidden">
|
||
<SlideView slide={hours} bg="sky" />
|
||
</div>
|
||
</PostFrame>
|
||
)}
|
||
{events.length > 0 && (
|
||
<PostFrame title={`내일 열리는 행사 · ${sido}`} account="주말·행사" avatar="concert" more={<Link to="/week">행사 더 보기 ›</Link>}>
|
||
<div className="b-band-3 px-4 pt-3.5 pb-3">
|
||
<p className="m-0 font-jua text-[19px]">내일 열리는 행사 · {sido}</p>
|
||
<ul className="m-0 mt-2 grid list-none gap-1.5 p-0">
|
||
{events.map((e) => (
|
||
<li key={e.event_id} className="flex items-center gap-2.5 rounded-[18px] bg-white px-3 py-2 shadow-[inset_0_-4px_0_var(--shade)]">
|
||
<Ic name={e.icon} className="w-[32px] shrink-0" />
|
||
<span className="min-w-0 flex-1">
|
||
<b className="block font-jua text-[16px] leading-tight font-normal">{e.name}</b>
|
||
<small className="block truncate text-xs font-semibold text-(--ink2)">
|
||
{e.place} · {days(e)}
|
||
</small>
|
||
</span>
|
||
</li>
|
||
))}
|
||
</ul>
|
||
</div>
|
||
</PostFrame>
|
||
)}
|
||
<Link
|
||
to={pathname.replace(/^\/tomorrow\//, '/today/')}
|
||
onClick={() => track('tomorrow_to_today', { region_name: region.name })}
|
||
className="mx-3 mt-4 mb-2 block rounded-full bg-white py-3 text-center font-jua text-[16px] shadow-[inset_0_-4px_0_var(--shade)]"
|
||
>
|
||
오늘 {place} 소식 보기 ›
|
||
</Link>
|
||
</div>
|
||
)
|
||
}
|