Files
o2o-weather/frontend/src/b/WeekPage.tsx
T
minaChoi 997a366e76 feat: 축제·전시·콘서트·팝업 7일마다 수집, 피드 행사 종류 섞기
- 행사 수집을 화면 요청에서 빼고 worker 가 월 04:00(켤 때 7일 기록 없으면 한 번) 전국 17개 시도를 받는다
- 문화정보원 음악/콘서트(B000) 추가, 쪽·시도 사이 1초 간격으로 초당 요청 제한 회피
- 팝가(popga.co.kr) 팝업스토어 수집: 사이트맵 + 상세 JSON-LD, 바뀐 페이지만 다시 읽음
- 수집이 끝나면 Teams Workflows webhook 으로 종류별 건수 알림 (TEAMS_WEBHOOK_URL)
- event.kind(1=축제 2=전시 3=콘서트 4=팝업) 칸과 종류별 아이콘 추가
- 피드 행사 카드·띠를 축제→팝업→전시→콘서트 차례로 섞음
- 포스트 종류별 내용·피드 기획 문서 갱신

같은 작업 폴더의 다른 작업(외부 API 가드, 노을·달 계산, 각 API, 문서 파일 이름 정리 등)도 함께 담김.
2026-10-07 12:03:48 +09:00

361 lines
17 KiB
TypeScript

import { useState, type ReactNode } from 'react'
import { useQuery } from '@tanstack/react-query'
import { getWeekOptions, getWeekRankingOptions, listEventsOptions, listPlacesOptions } from '../api/client/@tanstack/react-query.gen'
import { cx } from '../lib/utils'
import { cardBg, dateRange, loadOf, shortDay, sidoOf } from './lib'
import { useRegion } from './regionContext'
import { useSheet } from './sheetContext'
import { Arrows, Chips, Ic, MapLink, Rail, Sec, Skel, SkelRail, StateBox, Thumb } from './ui'
import { useCarousel } from './carousel'
const TEN = Array.from({ length: 10 }, (_, i) => i)
const THREE = [0, 1, 2]
const DAY_BTN = 'flex w-[calc((100%-24px)/7)] shrink-0 snap-start flex-col items-center gap-0.5 rounded-[18px] pt-[9px] pb-2 text-xs font-extrabold'
const PLACE_CARD = 'w-[178px] overflow-hidden rounded-[22px] bg-white text-left shadow-[inset_0_-5px_0_var(--shade),0_8px_16px_rgb(40_48_74/0.06)]'
const EVENT_CARD = 'mx-3 mt-2.5 grid grid-cols-[84px_1fr] items-center gap-3 rounded-[22px] bg-white p-3 shadow-[inset_0_-5px_0_var(--shade)]'
function DaysSkel() {
return (
<div className="flex gap-1 overflow-hidden px-3 pt-3" aria-hidden="true">
{TEN.map((i) => (
<span key={i} className={cx(DAY_BTN, 'bg-white shadow-[inset_0_-4px_0_var(--shade)]')}>
<span>
<Skel className="w-3" />
</span>
<Skel shape className="size-7 rounded-full" />
<b className="font-jua text-sm font-normal">
<Skel className="w-6" />
</b>
<span className="px-0.5 text-[9.5px]">
<Skel className="w-5" />
</span>
</span>
))}
</div>
)
}
function PickSkel() {
return (
<div className="mx-3 mt-3 flex items-center gap-3.5 rounded-3xl bg-white p-4 shadow-[inset_0_-5px_0_var(--shade)]" aria-hidden="true">
<Skel shape className="size-16 shrink-0 rounded-full" />
<div className="flex-1">
<b className="block font-jua text-[19px] font-normal">
<Skel className="w-32" />
</b>
<p className="mt-0.5 text-[13.5px] font-semibold">
<Skel className="w-4/5" />
</p>
<p className="mt-2 font-jua text-base">
<Skel className="w-36" />
</p>
</div>
</div>
)
}
function PlacesSkel() {
return (
<SkelRail>
{THREE.map((i) => (
<span key={i} className={PLACE_CARD}>
<Skel shape className="h-[104px]" />
<span className="block px-3 pt-2.5 pb-3">
<span className="text-[11.5px] font-extrabold">
<Skel className="w-16" />
</span>
<b className="block font-jua text-[16.5px] font-normal">
<Skel className="w-24" />
</b>
<small className="block text-[12.5px] leading-snug font-semibold">
<Skel className="w-full" />
<br />
<Skel className="w-20" />
</small>
</span>
</span>
))}
</SkelRail>
)
}
function EventSkel() {
return (
<div className={EVENT_CARD} aria-hidden="true">
<Skel shape className="h-[84px] rounded-2xl" />
<span className="min-w-0">
<b className="block h-[2lh] font-jua text-[17px] leading-snug font-normal">
<Skel className="w-40" />
<br />
<Skel className="w-20" />
</b>
<small className="block text-[12.5px] font-semibold">
<Skel className="w-44" />
</small>
<span className="mt-[5px] block h-[1lh] text-xs font-extrabold">
<Skel className="w-24" />
</span>
</span>
</div>
)
}
const RANK_ROW = 'grid grid-cols-[34px_1fr_auto] items-center gap-2.5 border-b-[1.5px] border-(--line) px-1 py-3 last:border-b-0'
// 불러오는 동안에도 탭 줄 높이를 지키려고 같은 칩을 미리 그린다
const RANK_TABS_HOLD = [
['토', '토요일'],
['일', '일요일'],
] as const
function RankSkel() {
return (
<ul className="mx-3 mt-1.5 flex flex-col" aria-hidden="true">
{TEN.map((i) => (
<li key={i} className={RANK_ROW}>
<span className="text-center font-bagel text-xl">
<Skel className="w-5" />
</span>
<span className="min-w-0">
<b className="block font-jua text-[17px] font-normal">
<Skel className="w-24" />
</b>
<small className="block text-[12.5px] font-semibold">
<Skel className="w-40" />
</small>
<Skel shape className="mt-[5px] h-1.5 rounded-full" />
</span>
<em className="flex items-center gap-1 font-jua text-base not-italic">
<Skel shape className="size-6 rounded-full" />
<Skel className="w-9" />
</em>
</li>
))}
</ul>
)
}
const PLACE_BG: Record<string, string> = { picnic: 'mint', walk: 'mint', sunset: 'dusk', chimaek: 'peach', photo: 'butter', bulb: 'lilac' }
export function WeekPage() {
const { region } = useRegion()
const { open } = useSheet()
const week = useQuery(getWeekOptions({ query: { region: region.code } }))
const days = week.data?.days ?? []
const [picked, setPicked] = useState<string | null>(null)
// 지역을 바꾸면 동네 고르기는 전체로 돌아간다
const [areaPick, setAreaPick] = useState({ region: region.code, area: '전체' })
const area = areaPick.region === region.code ? areaPick.area : '전체'
// 처음에는 이번 토요일을 고른다
const sel = days.find((d) => d.day === picked) ?? days.find((d) => d.weekday === '토') ?? days[0]
const places = useQuery({ ...listPlacesOptions({ query: { region: region.code, day: sel?.day, area: area === '전체' ? undefined : area } }), enabled: !!sel })
const events = useQuery(listEventsOptions({ query: { region: region.code } }))
const ranking = useQuery(getWeekRankingOptions())
const rankDays = ranking.data?.days ?? []
const [rankPick, setRankPick] = useState<string | null>(null)
const rankDay = rankDays.find((d) => d.day === rankPick) ?? rankDays[0]
const rankItems = (rankDay?.items ?? []).slice(0, 10)
const rankLoad = loadOf(ranking)
const sido = sidoOf(region.name)
const areas = places.data?.areas ?? []
const rainy = places.data?.rainy ?? sel?.is_rainy
const placeList = places.data?.places ?? []
const eventList = events.data?.events ?? []
const weekLoad = loadOf(week)
const eventLoad = loadOf(events)
// 날씨(고른 날)가 와야 명소를 부를 수 있다
const placeLoad = sel ? loadOf(places) : weekLoad === 'loading' ? 'loading' : 'ready'
const sendPlan = () => {
if (!sel) return
open({ type: 'share', share: { title: `${sel.weekday}요일 일정`, icon: 'calendar', bg: 'mint', messages: [`${sel.weekday}요일 이렇게 놀자! ${sel.pick} 😆`, '이번 주말 같이 놀자 🙌'] } })
}
return (
<section aria-label="주말·행사" aria-busy={weekLoad === 'loading'}>
<Sec title="열흘 날씨" sub="날짜를 누르면 그날 추천이 바뀌어요" />
{days.length ? (
<DayStrip dim={week.isPlaceholderData}>
{days.map((d) => {
const on = d.day === sel?.day
const weekend = d.weekday === '토' || d.weekday === '일' || !!d.holiday
return (
<button
key={d.day}
type="button"
aria-pressed={on}
onClick={() => setPicked(d.day)}
className={cx(DAY_BTN, 'cursor-pointer', on ? 'bg-(--ink) text-white' : cx('bg-white shadow-[inset_0_-4px_0_var(--shade)]', weekend ? 'text-[#d6457a]' : 'text-(--ink2)'))}
>
<span>{d.weekday}</span>
<Ic name={d.icon} className="w-7" />
<b className={cx('font-jua text-sm font-normal', on ? 'text-white' : 'text-(--ink)')}>{d.temp_max_c != null ? `${Math.round(d.temp_max_c)}°` : <span className="opacity-50" aria-label="기온 정보 없음">?</span>}</b>
<span className={cx('max-w-full truncate px-0.5 text-[9.5px]', on ? 'text-[#ffb3c4]' : 'text-[#d6457a]')}>{d.holiday ? d.holiday.replace(/\(.*\)/, '') : `${Number(d.day.slice(8))}일`}</span>
</button>
)
})}
</DayStrip>
) : weekLoad === 'loading' ? (
<>
<DaysSkel />
<PickSkel />
</>
) : (
<StateBox
load={weekLoad}
onRetry={() => week.refetch()}
empty="날씨가 아직 없어요."
hold={
<>
<DaysSkel />
<PickSkel />
</>
}
className="inset-x-3 top-3 bottom-0"
/>
)}
{sel && (
<div className="mx-3 mt-3 flex items-center gap-3.5 rounded-3xl bg-[linear-gradient(180deg,#e9fbf2,#fff)] p-4 shadow-[inset_0_-5px_0_var(--shade)]" aria-live="polite">
<Ic name={sel.icon} className="w-16" />
<div>
<b className="block font-jua text-[19px] font-normal">{sel.headline}</b>
<p className="mt-0.5 text-[13.5px] font-semibold text-(--ink2)">{sel.summary}</p>
<p className="mt-2 font-jua text-base text-(--ink)">{sel.pick}</p>
</div>
</div>
)}
{(sel || weekLoad !== 'ready') && (
<div className="mx-3 mt-3.5 flex items-center justify-between">
<label htmlFor="b-area" className="text-[13.5px] font-bold text-(--ink2)">
{sido} · 데이트 명소
</label>
<select id="b-area" value={area} onChange={(e) => setAreaPick({ region: region.code, area: e.target.value })} disabled={!areas.length} className="rounded-full bg-white px-3 py-[7px] font-bold text-(--ink) shadow-[inset_0_-3px_0_var(--shade)] disabled:opacity-60">
{['전체', ...areas].map((a) => (
<option key={a}>{a}</option>
))}
</select>
</div>
)}
<Sec title="날씨 맞춤 데이트 명소" sub={sel ? `${sel.weekday}요일은 ${rainy ? '비가 와서 실내 명소를 먼저' : sel.icon === 'sun' ? '맑아서 야외 명소를 먼저' : '비 소식이 없어 야외 명소를 먼저'} 보여 줘요` : weekLoad === 'loading' ? <Skel className="w-56" /> : '날씨에 맞춰 골라 보여 줘요'} className="pt-3" />
{placeList.length ? (
<Rail className={cx('transition-opacity', places.isPlaceholderData && 'opacity-60')}>
{placeList.map((p, i) => (
<div key={p.place_id} className={PLACE_CARD}>
<span className={cx('relative grid h-[104px] place-items-center', `b-bg-${PLACE_BG[p.icon] ?? (p.is_outdoor ? 'mint' : cardBg(p.icon, i))}`)}>
{p.is_good && <span className={cx('absolute top-2.5 left-2.5 rounded-full px-2 py-[3px] text-[11.5px] font-extrabold text-white', p.is_outdoor ? 'bg-[#1f9d62]' : 'bg-(--rain)')}>{p.is_outdoor ? '오늘 딱' : '비 와도 OK'}</span>}
<Ic name={p.icon} className="w-[62px]" />
</span>
<span className="block px-3 pt-2.5 pb-3">
<span className="text-[11.5px] font-extrabold text-(--ink3)">
{p.area} · {p.is_outdoor ? '야외' : '실내'}
</span>
<b className="block font-jua text-[16.5px] font-normal">
<MapLink place={p.name}>{p.name}</MapLink>
</b>
<small className="block text-[12.5px] leading-snug font-semibold text-(--ink2)">
{p.reason}
<br />
추천 {p.best_time}
</small>
</span>
</div>
))}
</Rail>
) : placeLoad === 'loading' ? (
<PlacesSkel />
) : (
<StateBox load={placeLoad} onRetry={() => places.refetch()} empty={sel ? `${sido} 데이트 명소는 아직 준비 중이에요.` : '날씨를 불러오면 명소를 골라 드려요.'} hold={<PlacesSkel />} className="inset-x-3 top-3 bottom-1" />
)}
<Sec title="이번 주말 전국 날씨 순위" sub="낮 10~17시 나들이 날씨 · 대표 지역 30곳 중 10위까지" className="pt-[18px]" />
{rankDays.length ? (
<Chips label="순위 볼 날" items={rankDays.map((d) => [d.day, `${d.weekday}요일 ${shortDay(d.day)}`] as const)} value={rankDay?.day ?? ''} onChange={setRankPick} />
) : (
<Chips label="순위 볼 날" items={RANK_TABS_HOLD} value="토" onChange={() => {}} />
)}
{rankItems.length ? (
<ul className={cx('mx-3 mt-1.5 flex flex-col transition-opacity', ranking.isPlaceholderData && 'opacity-60')}>
{rankItems.map((r) => {
const mine = r.region_code === region.code
return (
<li key={r.region_code} className={cx(RANK_ROW, mine && 'rounded-2xl bg-white')}>
<span className="text-center font-bagel text-xl text-(--orange)">{r.rank}</span>
<span className="min-w-0">
<b className="block truncate font-jua text-[17px] font-normal">
{r.name}
{mine && <small className="ml-1.5 font-sans text-xs font-extrabold text-(--rain)">내 지역</small>}
</b>
<small className="block truncate text-[12.5px] font-semibold text-(--ink2)">
{r.reason}
{r.estimated && ' · 예상'}
</small>
<span className="mt-[5px] block h-1.5 overflow-hidden rounded-full bg-[#eef1f6]">
<s className="block h-full bg-[linear-gradient(90deg,#9be7c4,#1f9d62)]" style={{ width: `${r.score}%` }} />
</span>
</span>
<em className="flex items-center gap-1 font-jua text-base not-italic">
<Ic name={r.icon} className="size-6" />
{r.score}점
</em>
</li>
)
})}
</ul>
) : rankLoad === 'loading' ? (
<RankSkel />
) : (
<StateBox load={rankLoad} onRetry={() => ranking.refetch()} empty="주말 예보가 아직 없어요." hold={<RankSkel />} className="inset-x-3 top-1.5 bottom-0" />
)}
<Sec title="가까운 축제·행사" sub="30km 안 · 앞으로 30일 · 그날 날씨까지 같이 봐요" className="pt-[18px]" />
{eventList.length ? (
eventList.map((e, i) => (
<div key={e.event_id} className={cx(EVENT_CARD, 'transition-opacity', events.isPlaceholderData && 'opacity-60')}>
<Thumb image={e.image} icon={e.icon} credit={e.image_credit} className={cx('h-[84px] rounded-2xl', `b-bg-${cardBg(e.icon, i)}`)} iconClassName="w-14" />
{/* 이름 두 줄·정보 한 줄·날씨 한 줄로 고정해 카드 높이가 데이터와 무관하게 같다 */}
<span className="min-w-0">
<b className="line-clamp-2 h-[2lh] font-jua text-[17px] leading-snug font-normal">
<span className={cx('mr-1.5 inline-block rounded-full px-[7px] py-0.5 align-[2px] font-sans text-[11px] leading-normal font-extrabold', e.status === 'live' ? 'bg-[#dff5ea] text-[#1f7a4f]' : 'bg-[#ffe8dc] text-[#c2471b]')}>{e.status_label}</span>
{e.name}
</b>
<small className="block truncate text-[12.5px] font-semibold text-(--ink2)">
{dateRange(e.start_date, e.end_date)}
{e.place_name && (
<>
{' · '}
<MapLink place={e.place_name}>{e.place_name}</MapLink>
</>
)}
{!e.is_confirmed && ' · 일정 확인 필요'}
</small>
<span className={cx('mt-[5px] block h-[1lh] text-xs font-extrabold', e.fit?.includes('비') ? 'text-[#d6457a]' : 'text-[#1f9d62]')}>{e.fit}</span>
</span>
</div>
))
) : eventLoad === 'loading' ? (
THREE.map((i) => <EventSkel key={i} />)
) : (
<StateBox load={eventLoad} onRetry={() => events.refetch()} empty="30km 안에 열리는 행사가 아직 없어요. 다른 지역을 골라 보세요." hold={THREE.map((i) => <EventSkel key={i} />)} className="inset-x-3 top-2.5 bottom-0" />
)}
{/* 행사 수가 정해진 뒤에 붙여 목록이 늘어날 때 밀리지 않게 */}
{eventLoad !== 'loading' && (
<button type="button" onClick={sendPlan} disabled={!sel} className="mx-3 mt-4 block w-[calc(100%-24px)] cursor-pointer rounded-full bg-(--orange) p-[13px] font-jua text-[17px] text-white shadow-[inset_0_-5px_0_var(--orange-deep)] disabled:opacity-60">
이번 주말 일정 보내기
</button>
)}
</section>
)
}
const DAY_STRIP = { align: 'start', dragFree: true, containScroll: 'trimSnaps' } as const
/** 열흘 날짜 줄: 손가락·마우스로 끌어 넘기고, PC 에선 화살표도 */
function DayStrip({ children, dim }: { children: ReactNode; dim: boolean }) {
const { ref, api, prev, next } = useCarousel(DAY_STRIP)
return (
<div className="relative" role="group" aria-label="날짜 고르기">
<div ref={ref} className="overflow-hidden">
<div className={cx('flex gap-1 px-3 pt-3 transition-opacity *:shrink-0', dim && 'opacity-60')}>{children}</div>
</div>
<Arrows api={api} prev={prev} next={next} />
</div>
)
}