feat: 로딩 스켈레톤·행사 사진·전시·주말 예상 점수·노을 탭 재정리 등 화면 전반 개선

- 화면 전체 스켈레톤, 로딩·완료·실패 사이 레이아웃 고정, 값 없음은 '?'
- 행사 사진·출처 표시, 문화정보 API 전시 연결, 행사 30km 거리 기준
- 각 상세 점수 칸 오늘/내일/토/일, 단기예보 밖 주말은 중기예보 예상 점수
- 6각 차트 축 이름을 좋은 방향으로, 계산 근거 문구 정리
- 아이콘 오용·뜻 모를 표시·빈 데이터·포스트 본문 반복 수정
- 미세먼지 별도 포스트, 노을 명소 전국 155곳 거리 기준, 노을 탭 결론 중심 재구성
- 밤 다크 테마·별똥별, 댓글·좋아요 대기·실패 표시
- 주말 전국 랭킹·당일치기 카드, 계절 이야기 사진 수집
- 문서: 포스트 타입별 내용, 각 데이터 정리, TODO 진행 순서
This commit is contained in:
minaChoi committed 2026-10-06 16:36:11 +09:00
1 parent 296a09d6db
commit ddf05aeb5c
97 files changed
+5475 -720

No files matched your search

+21 -7
View File
@@ -11,7 +11,7 @@ import { useSheet } from './sheetContext'
import { SheetProvider } from './Sheets'
import { SkyContext, useSky } from './skyContext'
import { PinIcon, TabIcon } from './svg'
import { Avatar } from './ui'
import { Avatar, Skel } from './ui'
const TABS = [
{ to: '/', key: 'today', label: '오늘', title: null },
@@ -23,9 +23,9 @@ const TABS = [
function TopBar() {
const { pathname } = useLocation()
const { region } = useRegion()
const { region, locateStatus } = useRegion()
const { open } = useSheet()
const { me } = useAuth()
const { me, mePending } = useAuth()
const tab = TABS.find((t) => t.to !== '/' && pathname.startsWith(t.to))
return (
@@ -35,12 +35,14 @@ function TopBar() {
type="button"
onClick={() => open({ type: 'region' })}
aria-label={`위치 바꾸기, 지금 ${region.name}`}
className="ml-auto flex cursor-pointer items-center gap-1 rounded-full bg-white px-3 py-1.5 text-[13.5px] font-bold shadow-[inset_0_-4px_0_var(--shade),0_6px_12px_rgb(40_48_74/0.07)]"
className="ml-auto flex cursor-pointer items-center gap-1 rounded-full bg-white px-3 pt-1 pb-2 text-[13.5px] font-bold shadow-[inset_0_-4px_0_var(--shade),0_6px_12px_rgb(40_48_74/0.07)]"
>
<PinIcon className="size-3.5" />
{region.name}
{locateStatus === 'locating' ? <Skel className="w-[72px]" /> : region.name}
</button>
{me ? (
{mePending ? (
<Skel shape className="size-9 shrink-0 rounded-full" />
) : me ? (
<button type="button" onClick={() => open({ type: 'me' })} aria-label={`내 정보, ${me.nickname}`} className="shrink-0 cursor-pointer rounded-full shadow-[0_6px_12px_rgb(40_48_74/0.12)]">
<Avatar character={me.character} color={me.color} mood={me.mood} size={36} />
</button>
@@ -61,6 +63,16 @@ const STARS = Array.from({ length: 46 }, (_, i) => ({
'--dl': `-${(i * 0.7) % 6}s`,
}))
// 별똥별: 위치·길이·주기를 엇갈려 몇 초마다 하나씩 떨어지게
const SHOOTS = [
{ top: '8%', left: '78%', '--len': '110px', '--dur': '7s', '--dl': '1s' },
{ top: '22%', left: '46%', '--len': '80px', '--dur': '9s', '--dl': '3.5s' },
{ top: '5%', left: '30%', '--len': '95px', '--dur': '8s', '--dl': '5.5s' },
{ top: '36%', left: '88%', '--len': '70px', '--dur': '10s', '--dl': '2.2s' },
{ top: '52%', left: '62%', '--len': '90px', '--dur': '11s', '--dl': '7s' },
{ top: '14%', left: '96%', '--len': '120px', '--dur': '12s', '--dl': '9s' },
]
/** 화면 전체 하늘: 시간대별 색, 아주 느리게 일렁이는 색 덩어리, 밤에는 별 */
function SkyBg() {
const { kind } = useSky()
@@ -82,7 +94,9 @@ function SkyBg() {
{STARS.map((s, i) => (
<i key={i} style={s} />
))}
<span className="b-shoot" />
{SHOOTS.map((s, i) => (
<span key={i} className="b-shoot" style={s} />
))}
</div>
</div>
)
+71 -16
View File
@@ -3,10 +3,10 @@ import { useQuery } from '@tanstack/react-query'
import { listArticlesOptions, listIndicesOptions } from '../api/client/@tanstack/react-query.gen'
import { ArticleCategory, IndexCategory } from '../api/client/types.gen'
import { cx } from '../lib/utils'
import { MEDALS } from './lib'
import { loadOf, MEDALS } from './lib'
import { useRegion } from './regionContext'
import { useSheet } from './sheetContext'
import { Chips, Ic, Sec, StateBox } from './ui'
import { Chips, Ic, Sec, Skel, StateBox } from './ui'
type Cat = 'all' | 'out' | 'food' | 'home' | 'life' | 'core'
@@ -21,6 +21,54 @@ const CATS = [
const CAT_PARAM: Partial<Record<Cat, IndexCategory>> = { out: IndexCategory.OUTSIDE, food: IndexCategory.FOOD, home: IndexCategory.HOME, life: IndexCategory.LIFE }
const GRID_SKELS = Array.from({ length: 9 }, (_, i) => i)
/** 1~3위 받침대와 같은 칸(가운데가 높은 3칸)의 스켈레톤 */
function PodiumSkel() {
return (
<div className="grid grid-cols-[1fr_1.15fr_1fr] items-end gap-1.5 px-3 pt-3" aria-hidden="true">
{[1, 0, 2].map((k) => (
<span key={k} className={cx('flex flex-col items-center rounded-3xl bg-white px-1.5 text-center shadow-[inset_0_-6px_0_var(--shade)]', k === 0 ? 'py-4' : 'py-3')}>
<Skel shape className={cx('aspect-square rounded-full', k === 0 ? 'w-20' : 'w-[62px]')} />
<b className="mt-1.5 font-jua text-base font-normal">
<Skel className="w-16" />
</b>
<em className="font-bagel text-[30px] leading-[1.05] not-italic">
<Skel className="w-10" />
</em>
<small className="w-full text-[11.5px] font-semibold">
<Skel className="w-full" />
</small>
</span>
))}
</div>
)
}
function GakCellSkel() {
return (
<span className="flex flex-col items-center rounded-[22px] bg-white px-1.5 pt-3 pb-2.5 shadow-[inset_0_-5px_0_var(--shade)]" aria-hidden="true">
<Skel shape className="aspect-square w-[50px] rounded-full" />
<b className="mt-1 font-jua text-[15px] font-normal">
<Skel className="w-14" />
</b>
<em className="font-bagel text-[22px] leading-[1.1] not-italic">
<Skel className="w-8" />
</em>
</span>
)
}
function GridSkel() {
return (
<div className="grid grid-cols-3 gap-2 p-3">
{GRID_SKELS.map((i) => (
<GakCellSkel key={i} />
))}
</div>
)
}
export function GakPage() {
const { region } = useRegion()
const { open } = useSheet()
@@ -29,13 +77,20 @@ export function GakPage() {
const top = q.data?.top3 ?? []
const items = q.data?.items ?? []
const day = q.data?.day?.split('-').map(Number)
const load = loadOf(q)
const howto = useQuery(listArticlesOptions({ query: { category: ArticleCategory.GAK } })).data?.articles?.find((a) => a.code === 'howgak')
return (
<section aria-label="각">
<Sec title="오늘 1~3위" sub={`${day ? `${day[1]}월 ${day[2]}일 기준 · ` : ''}${region.name} · 칸 아래 막대는 오늘·내일·모레 점수`} />
{top.length === 3 && (
<div className="grid grid-cols-[1fr_1.15fr_1fr] items-end gap-1.5 px-3 pt-3">
<section aria-label="각" aria-busy={load === 'loading'}>
<Sec title="오늘 1~3위" sub={`${day ? `${day[1]}월 ${day[2]}일 기준 · ` : ''}${region.name}`} />
{top.length !== 3 ? (
load === 'loading' ? (
<PodiumSkel />
) : (
<StateBox load={load} onRetry={() => q.refetch()} empty="오늘 1~3위를 아직 못 정했어요." hold={<PodiumSkel />} className="inset-x-3 top-3 bottom-0" />
)
) : (
<div className={cx('grid grid-cols-[1fr_1.15fr_1fr] items-end gap-1.5 px-3 pt-3 transition-opacity', q.isPlaceholderData && 'opacity-60')}>
{[1, 0, 2].map((k) => {
const g = top[k]
return (
@@ -60,11 +115,14 @@ export function GakPage() {
</div>
)}
<Chips items={CATS} value={cat} onChange={setCat} label="분야" />
<StateBox loading={q.isPending} error={q.error} onRetry={() => q.refetch()} empty={q.isSuccess && !items.length ? '이 분야는 오늘 계산된 각이 없어요.' : undefined} />
<div className="grid grid-cols-3 gap-2 p-3">
{load === 'loading' ? (
<GridSkel />
) : !items.length ? (
// 실패 안내·다시 시도는 위 받침대 자리에 한 번만
<StateBox load="ready" empty={load === 'ready' ? '이 분야는 오늘 계산된 각이 없어요.' : '각 목록을 불러오지 못했어요.'} hold={<GridSkel />} className="inset-3" />
) : (
<div className={cx('grid grid-cols-3 gap-2 p-3 transition-opacity', q.isPlaceholderData && 'opacity-60')}>
{items.map((g) => {
const trend = g.trend ?? []
const mx = Math.max(1, ...trend.map((t) => t.score))
return (
<button key={g.index_id} type="button" onClick={() => open({ type: 'gak', indexId: g.index_id })} aria-label={`${g.rank}위 ${g.name} ${g.score}점`} className="relative flex cursor-pointer flex-col items-center rounded-[22px] bg-white px-1.5 pt-3 pb-2.5 shadow-[inset_0_-5px_0_var(--shade)]">
<span className="absolute top-[7px] left-[9px] font-jua text-[13px] text-(--ink3)">{g.rank}</span>
@@ -72,16 +130,13 @@ export function GakPage() {
<Ic name={g.icon} className="w-[50px]" />
<b className="mt-1 font-jua text-[15px] font-normal">{g.name}</b>
<em className={cx('font-bagel text-[22px] leading-[1.1] not-italic', g.score < 50 ? 'text-(--ink3)' : 'text-(--orange)')}>{g.score}</em>
<span className="mt-1 flex h-[18px] items-end gap-[3px]" aria-hidden="true">
{trend.map((t, j) => (
<i key={t.day} className={cx('w-[9px] rounded-[3px]', j ? 'bg-[#dbe4ef]' : 'bg-(--orange)')} style={{ height: Math.max(4, (t.score / mx) * 18) }} />
))}
</span>
</button>
)
})}
</div>
{howto && (
)}
{/* 목록 칸 수가 정해진 뒤에 붙여 목록이 늘어날 때 밀리지 않게 */}
{howto && load !== 'loading' && (
<button type="button" onClick={() => open({ type: 'article', articleId: howto.article_id })} className="mx-3 mt-1.5 flex w-[calc(100%-24px)] cursor-pointer items-center gap-3 rounded-[22px] bg-[#ece7ff] p-3.5 text-left">
<Ic name="bulb" className="w-11" />
<span>
+131 -55
View File
@@ -1,32 +1,34 @@
import { useRef, useState, type CSSProperties, type MouseEvent, type ReactNode } from 'react'
import { PostType, SlotTone, type GakSlide, type HoursSlide, type PostData, type ResFeed, type RowsSlide, type SunsetSlide, type WeekSlide } from '../api/client/types.gen'
import { useEffect, useRef, useState, type CSSProperties, type MouseEvent, type ReactNode } from 'react'
import { PostType, SlotTone, type GakSlide, type HoursSlide, type PlanSlide, type PostData, type ResFeed, type RowsSlide, type SunsetSlide, type WeekSlide } from '../api/client/types.gen'
import { cx } from '../lib/utils'
import { cardBg, clockShort, fall } from './lib'
import type { SlideBg } from './types'
import { deg } from './weatherText'
import { useMutation, useQueryClient, type QueryClient } from '@tanstack/react-query'
import { likePostMutation, savePostMutation, unlikePostMutation, unsavePostMutation } from '../api/client/@tanstack/react-query.gen'
import { likePostMutation, unlikePostMutation } from '../api/client/@tanstack/react-query.gen'
import { useAuth } from './authContext'
import { useRegion } from './regionContext'
import { useSheet } from './sheetContext'
import { CommentIcon, HeartIcon, MoreIcon, SaveIcon, SendIcon } from './svg'
import { CommentIcon, HeartIcon, SendIcon } from './svg'
import { useCarousel } from './carousel'
import { Arrows, Ic, Rows } from './ui'
import { Arrows, Credit, Ic, Rows, Skel, Thumb } from './ui'
const ACCOUNTS: Record<PostType, readonly [string, string]> = {
[PostType.WEATHER]: ['오늘 날씨', 'sun'],
[PostType.GAK]: ['오늘의 각', 'rabbit'],
[PostType.SUNSET]: ['노을', 'sunset'],
[PostType.SEASON]: ['계절 소식', 'maple'],
[PostType.EVENT]: ['행사', 'fireworks'],
[PostType.EVENT]: ['가까운 행사', 'fireworks'],
[PostType.TIP]: ['날씨 상식', 'bulb'],
[PostType.WEEK]: ['주말 추천', 'calendar'],
[PostType.WEEK]: ['주말 예보', 'calendar'],
[PostType.ALERT]: ['생활 알림', 'umbrella'],
[PostType.TOMORROW]: ['내일 미리보기', 'moon'],
[PostType.QUOTE]: ['오늘의 한 문장', 'letter'],
[PostType.WEEKEND_PLAN]: ['주말 플랜', 'calendar'],
[PostType.AIR]: ['미세먼지', 'vent'],
[PostType.DAY_TRIP]: ['당일치기', 'picnic'],
}
type Slide = HoursSlide | RowsSlide | GakSlide | SunsetSlide | WeekSlide
type Slide = HoursSlide | RowsSlide | GakSlide | SunsetSlide | WeekSlide | PlanSlide
const GAK_BG: SlideBg[] = ['butter', 'peach', 'lilac']
const ROW_ICON_BG: Record<string, SlideBg> = { umbrella: 'lilac', vent: 'mint', sunset: 'peach', thermo: 'sky', maple: 'peach' }
@@ -36,9 +38,12 @@ function slideBg(post: PostData, slide: Slide): SlideBg {
if (slide.kind === 'hours') return 'sky'
if (slide.kind === 'sunset') return 'dusk'
if (slide.kind === 'week') return 'mint'
if (slide.kind === 'plan') return slide.eyebrow.startsWith('일') ? 'peach' : 'butter'
if (slide.kind === 'gak') return GAK_BG[post.post_id % GAK_BG.length]
if (post.post_type === PostType.EVENT) return 'night'
if (post.post_type === PostType.TIP) return 'sky'
if (post.post_type === PostType.AIR) return slide.icon === 'vent' ? 'mint' : 'lilac'
if (post.post_type === PostType.DAY_TRIP) return slide.image ? 'night' : 'mint'
return ROW_ICON_BG[slide.icon] ?? cardBg(slide.icon, post.post_id)
}
@@ -73,7 +78,10 @@ const slideBase = 'relative flex h-full w-full shrink-0 flex-col px-5 py-[22px]'
function SlideView({ slide, bg }: { slide: Slide; bg: SlideBg }) {
const { open } = useSheet()
if (slide.kind === 'hours')
if (slide.kind === 'hours') {
const temps = slide.hours.flatMap((h) => (h.temp_c == null ? [] : [h.temp_c]))
const lo = Math.min(...temps)
const span = Math.max(...temps) - lo || 1
return (
<div className={cx(slideBase, 'b-bg-sky')}>
<Eyebrow>{slide.eyebrow}</Eyebrow>
@@ -85,10 +93,13 @@ function SlideView({ slide, bg }: { slide: Slide; bg: SlideBg }) {
<div
key={h.label}
className={cx(
'flex flex-col items-center justify-between rounded-[18px] px-1 pt-2.5 pb-[9px] text-xs font-bold text-(--ink2)',
'relative flex flex-col items-center justify-between overflow-hidden rounded-[18px] px-1 pt-2.5 pb-[9px] text-xs font-bold text-(--ink2) [&>*]:relative',
h.tone === SlotTone.NIGHT ? 'bg-[#e3e7ff] shadow-[inset_0_-5px_0_#c7cff5]' : h.tone === SlotTone.SUNSET ? 'bg-[#ffe3d2] shadow-[inset_0_-5px_0_#ffc19f]' : 'bg-white shadow-[inset_0_-5px_0_var(--shade)]',
)}
>
{h.temp_c != null && (
<i className="absolute! inset-x-0 bottom-0 bg-linear-to-t from-[rgb(255_122_69/0.34)] to-[rgb(255_122_69/0.1)]" style={{ height: `${20 + ((h.temp_c - lo) / span) * 70}%` }} aria-hidden="true" />
)}
<span>{h.label}</span>
<Ic name={h.icon} className="w-[34px]" />
<b className="font-bagel text-[21px] font-normal text-(--ink)">{deg(h.temp_c)}</b>
@@ -97,6 +108,7 @@ function SlideView({ slide, bg }: { slide: Slide; bg: SlideBg }) {
</div>
</div>
)
}
if (slide.kind === 'gak')
return (
<div className={cx(slideBase, `b-bg-${bg}`)}>
@@ -107,14 +119,14 @@ function SlideView({ slide, bg }: { slide: Slide; bg: SlideBg }) {
<p className="m-0 font-jua text-[29px] leading-tight">{slide.name}</p>
<Eyebrow className="mt-1">{slide.summary}</Eyebrow>
<button type="button" onClick={() => open({ type: 'gak', indexId: slide.index_id })} className="mt-3 cursor-pointer self-start rounded-full bg-(--orange) px-4 py-[9px] font-jua text-[15px] text-white shadow-[inset_0_-5px_0_var(--orange-deep)]">
계산 근거 보기 ⬡
계산 근거 보기
</button>
</div>
)
if (slide.kind === 'sunset')
return (
<div className={cx(slideBase, 'b-bg-dusk')}>
<Eyebrow className="opacity-90">{slide.eyebrow}</Eyebrow>
<Eyebrow>{slide.eyebrow}</Eyebrow>
<Big>
<Lines text={slide.line} />
</Big>
@@ -140,15 +152,59 @@ function SlideView({ slide, bg }: { slide: Slide; bg: SlideBg }) {
</Big>
<div className="mt-auto grid grid-cols-2 gap-2.5">
{slide.days.map((d) => (
<div key={d.day} className="rounded-[18px] bg-white/80 px-3 py-2.5 shadow-[inset_0_-5px_0_rgb(217_229_244/0.9)]">
<Ic name={d.icon} className="w-[38px]" />
<b className="block font-jua text-lg font-normal">
<div key={d.day} className="flex flex-col gap-0.5 rounded-[18px] bg-white/85 px-3 py-2.5 shadow-[inset_0_-5px_0_rgb(217_229_244/0.9)]">
<Ic name={d.icon} className="w-[34px]" />
<b className="font-jua text-lg font-normal">
{d.weekday} {d.day.split('-').slice(1).map(Number).join('.')}
</b>
<small className="text-[12.5px] font-bold text-(--ink2)">{d.text}</small>
<span className="font-jua text-[22px]">
<span className="text-(--rain)">{deg(d.temp_min_c)}</span> → <span className="text-(--orange)">{deg(d.temp_max_c)}</span>
</span>
<small className="text-xs font-bold text-(--ink2)">
비 {d.rain_prob ?? '?'}%{d.temp_min_c != null && d.temp_max_c != null && ` · 일교차 ${Math.round(d.temp_max_c - d.temp_min_c)}°`}
</small>
</div>
))}
</div>
{slide.tip && <p className="mt-3 rounded-[14px] bg-(--ink) px-3 py-2.5 text-[13px] leading-snug font-bold text-white">{slide.tip}</p>}
</div>
)
if (slide.kind === 'plan') {
const credits = [...new Set(slide.steps.flatMap((st) => (st.image && st.image_credit ? [st.image_credit] : [])))]
return (
<div className={cx(slideBase, `b-bg-${bg}`)}>
<Eyebrow>{slide.eyebrow}</Eyebrow>
<Big className="text-[24px]!">
<Lines text={slide.line} />
</Big>
<ol className="mt-auto flex flex-col gap-2">
{slide.steps.map((st, i) => (
<li key={i} className="grid grid-cols-[52px_26px_minmax(0,1fr)_auto] items-center gap-1.5 rounded-[14px] bg-white/80 px-2 py-1.5">
<time className="font-jua text-sm text-(--ink2) tabular-nums">{st.time}</time>
<Ic name={st.icon} className="w-[22px] justify-self-center" />
<span className="min-w-0">
<b className="block truncate text-[13.5px]">{st.title}</b>
<small className="block truncate text-[11.5px] font-semibold text-(--ink2)">{st.sub}</small>
</span>
{st.image && <Thumb image={st.image} icon={st.icon} className="size-[46px] rounded-[10px]" iconClassName="w-[26px]" />}
</li>
))}
</ol>
{credits.length > 0 && <small className="mt-1.5 block text-right text-[10px] font-semibold text-(--ink2)">사진 {credits.join(' · ')}</small>}
</div>
)
}
if (slide.kind === 'rows' && slide.image)
return (
<div className={'relative flex h-full w-full shrink-0 flex-col justify-end bg-cover bg-center text-white'} style={{ backgroundImage: `url(${slide.image})` }}>
{slide.image_credit && <Credit text={slide.image_credit} className="top-2.5 right-2.5" />}
<div className="bg-linear-to-b from-transparent via-[rgb(16_20_34/0.55)] via-35% to-[rgb(16_20_34/0.85)] px-5 pt-20 pb-3.5">
<Eyebrow>{slide.eyebrow}</Eyebrow>
<Big>
<Lines text={slide.line} />
</Big>
<Rows rows={slide.rows ?? []} dark />
</div>
</div>
)
return (
@@ -176,7 +232,7 @@ const BURST: [number, number, number, string][] = [
[52, -100, 12, '#ffc86e'],
]
/** 받아 둔 피드 데이터에도 좋아요·저장을 반영한다. 안 하면 다른 탭에 다녀왔을 때 예전 값으로 다시 그려진다 */
/** 받아 둔 피드 데이터에도 좋아요를 반영한다. 안 하면 다른 탭에 다녀왔을 때 예전 값으로 다시 그려진다 */
function patchFeed(queryClient: QueryClient, postId: number, patch: Partial<PostData>) {
queryClient.setQueriesData<ResFeed>({ predicate: (q) => (q.queryKey[0] as { _id?: string } | undefined)?._id === 'getFeed' }, (feed) =>
feed?.posts ? { ...feed, posts: feed.posts.map((p) => (p.post_id === postId ? { ...p, ...patch } : p)) } : feed,
@@ -202,58 +258,88 @@ export function PostCard({ post }: PostProps) {
return post.size === 'line' ? <LineCard post={post} /> : <FullCard post={post} />
}
/** FullCard 와 같은 틀(머리줄·4:5 그림·버튼줄·글 한 줄)의 스켈레톤 */
export function PostCardSkel() {
return (
<div className="mt-3.5 border-y border-(--line) bg-white" aria-hidden="true">
<div className="flex items-center gap-2.5 px-3 py-2.5">
<Skel shape className="size-[34px] shrink-0 rounded-full" />
<span>
<b className="block text-sm leading-tight font-extrabold">
<Skel className="w-12" />
</b>
<small className="text-xs font-semibold">
<Skel className="w-16" />
</small>
</span>
</div>
<Skel shape className="aspect-[4/5]" />
<div className="flex items-center gap-3.5 px-3 pt-2.5 pb-1">
<Skel shape className="size-7 rounded-full" />
<Skel shape className="size-7 rounded-full" />
<Skel shape className="size-7 rounded-full" />
</div>
<p className="px-3 py-0.5 text-sm">
<Skel className="w-20" />
</p>
<p className="px-3 py-0.5 text-sm">
<Skel className="w-4/5" />
</p>
<p className="px-3 pt-[3px] text-sm">
<Skel className="w-32" />
</p>
<p className="px-3 pt-1 pb-3 text-[11.5px]">
<Skel className="w-8" />
</p>
</div>
)
}
function FullCard({ post }: PostProps) {
const { open } = useSheet()
const { region } = useRegion()
const { loggedIn } = useAuth()
const liked = !!post.liked
const likeCount = post.like_count
const saved = !!post.saved
const queryClient = useQueryClient()
const like = useMutation(likePostMutation())
const unlike = useMutation(unlikePostMutation())
const save = useMutation(savePostMutation())
const unsave = useMutation(unsavePostMutation())
const { ref: sliderRef, api: slider, prev: canPrev, next: canNext, index } = useCarousel({ align: 'start' })
const { ref: sliderRef, api: slider, prev: canPrev, next: canNext, index } = useCarousel({ align: 'start', active: post.slides.length > 1 })
const [pop, setPop] = useState(0)
const [likeFailed, setLikeFailed] = useState(0)
const lastTap = useRef(0)
const cardRef = useRef<HTMLDivElement>(null)
const [account, avatar] = ACCOUNTS[post.post_type]
const n = post.slides.length
const bgs = post.slides.map((sl) => slideBg(post, sl))
const accountName = post.post_type === PostType.EVENT ? `${region.name.split(' ')[0]} ${account}` : account
const share = () => open({ type: 'share', share: { title: post.title, icon: post.icon, bg: bgs[0] ?? 'sky', messages: post.share_messages ?? [], card: cardRef.current } })
const comments = () => open({ type: 'comments', postId: post.post_id })
const patch = (values: Partial<PostData>) => patchFeed(queryClient, post.post_id, values)
useEffect(() => {
if (!likeFailed) return
const t = setTimeout(() => setLikeFailed(0), 2500)
return () => clearTimeout(t)
}, [likeFailed])
// 화면을 먼저 바꾸고, 실패하면 되돌린다 (서버는 실패도 200 + result.success=false 로 준다)
const setLike = (on: boolean) => {
if (!loggedIn) return open({ type: 'login' })
if (on === liked || like.isPending || unlike.isPending) return
if (on) setPop((p) => p + 1)
setLikeFailed(0)
patch({ liked: on, like_count: likeCount + (on ? 1 : -1) })
const revert = () => {
patch({ liked, like_count: likeCount })
setLikeFailed(Date.now())
}
;(on ? like : unlike).mutate(
{ path: { post_id: post.post_id } },
{
onSuccess: (res) =>
res.result?.success
? patch({ liked: res.liked ?? on, ...(res.like_count != null ? { like_count: res.like_count } : {}) })
: patch({ liked, like_count: likeCount }),
onError: () => patch({ liked, like_count: likeCount }),
},
)
}
const toggleSave = () => {
if (!loggedIn) return open({ type: 'login' })
if (save.isPending || unsave.isPending) return
const on = !saved
patch({ saved: on })
;(on ? save : unsave).mutate(
{ path: { post_id: post.post_id } },
{
onSuccess: (res) => patch({ saved: res.result?.success ? (res.saved ?? on) : saved }),
onError: () => patch({ saved }),
: revert(),
onError: revert,
},
)
}
@@ -278,11 +364,8 @@ function FullCard({ post }: PostProps) {
</span>
<span>
<b className="block text-sm leading-tight font-extrabold">날씨각</b>
<small className="text-xs font-semibold text-(--ink2)">{accountName}</small>
<small className="text-xs font-semibold text-(--ink2)">{account}</small>
</span>
<button type="button" onClick={share} aria-label="더 보기" className="ml-auto grid size-7 cursor-pointer place-items-center text-(--ink)">
<MoreIcon />
</button>
</div>
<div ref={cardRef} className="relative aspect-[4/5] overflow-hidden" onClick={onTap}>
{n > 1 && (
@@ -327,8 +410,11 @@ function FullCard({ post }: PostProps) {
<span className="b-like-toast absolute top-[62%] rounded-full bg-white px-4 py-2 font-jua text-[17px] text-(--heart) opacity-0 shadow-[0_8px_18px_rgb(40_48_74/0.18)]">좋아요했어요!</span>
</div>
)}
<p data-noshot role="status" className="pointer-events-none absolute inset-x-0 bottom-4 z-[5] m-0 flex justify-center px-4">
{likeFailed > 0 && <span className="rounded-full bg-[rgb(30_36_56/0.82)] px-3.5 py-2 text-[13px] font-bold text-white">{liked ? '좋아요를 취소하지 못했어요' : '좋아요를 반영하지 못했어요'}. 다시 해 주세요.</span>}
</p>
</div>
<div className="relative flex items-center gap-3.5 px-3 pt-2.5 pb-1 [&_svg]:size-[26px] [&_svg]:stroke-[1.9]">
<div className="flex items-center gap-3.5 px-3 pt-2.5 pb-1 [&_svg]:size-[26px] [&_svg]:stroke-[1.9]">
<button type="button" onClick={() => setLike(!liked)} aria-pressed={liked} aria-label="좋아요" className="grid size-7 cursor-pointer place-items-center">
<HeartIcon className={liked ? 'fill-(--heart) stroke-(--heart)' : 'fill-none stroke-(--ink)'} />
</button>
@@ -338,16 +424,6 @@ function FullCard({ post }: PostProps) {
<button type="button" onClick={share} aria-label="보내기" className="grid size-7 cursor-pointer place-items-center">
<SendIcon className="fill-none stroke-(--ink) [stroke-linecap:round] [stroke-linejoin:round]" />
</button>
{n > 1 && (
<span className="absolute left-1/2 flex -translate-x-1/2 gap-1" aria-hidden="true">
{post.slides.map((_, k) => (
<i key={k} className={cx('size-1.5 rounded-full', k === index ? 'bg-(--rain)' : 'bg-[#cfd8e6]')} />
))}
</span>
)}
<button type="button" onClick={toggleSave} aria-pressed={saved} aria-label="저장" className="ml-auto grid size-7 cursor-pointer place-items-center">
<SaveIcon className={cx('stroke-(--ink) [stroke-linejoin:round]', saved ? 'fill-(--ink)' : 'fill-none')} />
</button>
</div>
<p className="px-3 py-0.5 text-sm font-extrabold">좋아요 {likeCount.toLocaleString()}개</p>
<p className="px-3 py-0.5 text-sm">
+62 -9
View File
@@ -3,9 +3,9 @@ import { useQuery } from '@tanstack/react-query'
import { getSeasonWeekOptions, listArticlesOptions } from '../api/client/@tanstack/react-query.gen'
import { ArticleCategory } from '../api/client/types.gen'
import { cx } from '../lib/utils'
import { ARTICLE_CAT, cardBg, fall, shortDay } from './lib'
import { ARTICLE_CAT, cardBg, dateRange, fall, loadOf, shortDay } from './lib'
import { useSheet } from './sheetContext'
import { Chips, Ic, StateBox } from './ui'
import { Chips, Ic, Skel, StateBox } from './ui'
const CATS = [
['all', '전체'],
@@ -16,6 +16,54 @@ const CATS = [
const CAT_PARAM = { season: ArticleCategory.SEASON, tip: ArticleCategory.TIP, gak: ArticleCategory.GAK } as const
const HEAD_BOX = 'relative mx-3 mt-3 flex min-h-[250px] w-[calc(100%-24px)] flex-col overflow-hidden rounded-[28px] p-5 text-left'
const ROW = 'grid w-full grid-cols-[1fr_84px] items-center gap-3 border-b-[1.5px] border-(--line) px-4 py-3.5 text-left'
const ROW_SKELS = [0, 1, 2, 3]
/** 특집 상자와 같은 틀: 머리말 · 제목 두 줄 · 시 한 줄 · 절기 막대 (최소 높이 250px 안) */
function HeadSkel() {
return (
<div className={cx(HEAD_BOX, 'bg-white')} aria-hidden="true">
<p className="m-0 text-[13px] font-extrabold">
<Skel className="w-36" />
</p>
<p className="mt-1 max-w-[62%] font-jua text-[29px] leading-tight">
<Skel className="w-full" />
<br />
<Skel className="w-2/3" />
</p>
<p className="mt-auto max-w-[72%] pt-3 font-batang text-[22px] leading-[1.7]">
<Skel className="w-full" />
</p>
<div className="mt-2.5 max-w-[70%]">
<div className="text-xs font-extrabold">
<Skel className="w-full" />
</div>
<Skel shape className="mt-1 h-[7px] rounded-full" />
</div>
</div>
)
}
function RowSkel() {
return (
<div className={ROW} aria-hidden="true">
<span>
<span className="text-xs font-extrabold">
<Skel className="w-12" />
</span>
<b className="mt-0.5 block font-jua text-[17.5px] leading-snug font-normal">
<Skel className="w-48" />
</b>
<small className="mt-1 block text-xs font-semibold">
<Skel className="w-14" />
</small>
</span>
<Skel shape className="h-[84px] rounded-[18px]" />
</div>
)
}
export function SeasonPage() {
const { open } = useSheet()
const [cat, setCat] = useState<(typeof CATS)[number][0]>('all')
@@ -24,12 +72,14 @@ export function SeasonPage() {
const w = week.data
const list = arts.data?.articles ?? []
const progress = Math.round((w?.progress ?? 0) * 100)
const weekLoad = loadOf(week)
const artLoad = loadOf(arts)
return (
<section aria-label="계절·상식">
<section aria-label="계절·상식" aria-busy={weekLoad === 'loading' || artLoad === 'loading'}>
{w?.headline ? (
<button type="button" onClick={() => open({ type: 'seasonWeek' })} className="relative mx-3 mt-3 flex min-h-[250px] w-[calc(100%-24px)] cursor-pointer flex-col overflow-hidden rounded-[28px] bg-[linear-gradient(180deg,#ffd2bb,#fff2ea)] p-5 text-left">
<p className="m-0 text-[13px] font-extrabold opacity-75">이번 주 특집 · {w.week}번째 주</p>
<button type="button" onClick={() => open({ type: 'seasonWeek' })} className={cx(HEAD_BOX, 'cursor-pointer bg-[linear-gradient(180deg,#ffd2bb,#fff2ea)]')}>
<p className="m-0 text-[13px] font-extrabold opacity-75">이번 주 특집{w.start && w.end ? ` · ${dateRange(w.start, w.end)}` : ''}</p>
<p className="mt-1 max-w-[62%] font-jua text-[29px] leading-tight">{w.headline}</p>
<span className="b-fall pointer-events-none absolute top-[18%] right-3.5 w-[38%]" style={fall('.1s')}>
<Ic name="maple" className="w-full drop-shadow-[0_16px_18px_rgb(40_48_74/0.18)]" />
@@ -60,14 +110,17 @@ export function SeasonPage() {
</div>
)}
</button>
) : weekLoad === 'loading' ? (
<HeadSkel />
) : (
<StateBox loading={week.isPending} error={week.error} onRetry={() => week.refetch()} empty="이번 주 특집이 아직 없어요." />
<StateBox load={weekLoad} onRetry={() => week.refetch()} empty="이번 주 특집이 아직 없어요." hold={<HeadSkel />} className="inset-x-3 top-3 bottom-0" />
)}
<Chips items={CATS} value={cat} onChange={setCat} label="분류" />
<div className="mt-1.5">
<StateBox loading={arts.isPending} error={arts.error} onRetry={() => arts.refetch()} empty={arts.isSuccess && !list.length ? '읽을거리가 아직 없어요.' : undefined} />
<div className={cx('mt-1.5 transition-opacity', arts.isPlaceholderData && 'opacity-60')}>
{artLoad === 'loading' && ROW_SKELS.map((i) => <RowSkel key={i} />)}
{artLoad !== 'loading' && !list.length && <StateBox load={artLoad} onRetry={() => arts.refetch()} empty="읽을거리가 아직 없어요." hold={ROW_SKELS.map((i) => <RowSkel key={i} />)} className="inset-3" />}
{list.map((a) => (
<button key={a.article_id} type="button" onClick={() => open({ type: 'article', articleId: a.article_id })} className="grid w-full cursor-pointer grid-cols-[1fr_84px] items-center gap-3 border-b-[1.5px] border-(--line) px-4 py-3.5 text-left">
<button key={a.article_id} type="button" onClick={() => open({ type: 'article', articleId: a.article_id })} className={cx(ROW, 'cursor-pointer')}>
<span>
<span className={cx('text-xs font-extrabold', ARTICLE_CAT[a.category]?.[1])}>{ARTICLE_CAT[a.category]?.[0]}</span>
<b className="mt-0.5 block font-jua text-[17.5px] leading-snug font-normal">{a.title}</b>
+224 -59
View File
@@ -1,4 +1,4 @@
import { useInfiniteQuery, useMutation, useQuery, useQueryClient } from '@tanstack/react-query'
import { useInfiniteQuery, useMutation, useQuery, useQueryClient, type InfiniteData } from '@tanstack/react-query'
import { useCallback, useDeferredValue, useEffect, useMemo, useRef, useState, type FormEvent, type ReactNode } from 'react'
import { setTokens, subscribeAuth } from '../api/auth'
import {
@@ -18,16 +18,16 @@ import {
unlikeCommentMutation,
updateMeMutation,
} from '../api/client/@tanstack/react-query.gen'
import type { CommentData, Factor, ResAuth, ResIndexDetail } from '../api/client/types.gen'
import type { CommentData, Factor, ResAuth, ResCommentList, ResIndexDetail } from '../api/client/types.gen'
import { cx } from '../lib/utils'
import { useAuth } from './authContext'
import { AVATAR_COLORS, ago, ARTICLE_CAT, articleMeta, cardBg, CHARACTERS, dayLabel, MOODS, shortDay } from './lib'
import { ago, ARTICLE_CAT, articleMeta, AVATAR_COLORS, cardBg, CHARACTERS, dateRange, loadOf, MOODS, shortDay } from './lib'
import { useRegion } from './regionContext'
import { useSky } from './skyContext'
import { storyImage } from './storyImage'
import { SheetContext, useSheet, type SharePayload, type SheetState } from './sheetContext'
import { HeartIcon } from './svg'
import { Avatar, Ic, StateBox } from './ui'
import { Avatar, Ic, Skel, StateBox } from './ui'
export function SheetProvider({ children }: { children: ReactNode }) {
const [state, setState] = useState<SheetState>(null)
@@ -112,10 +112,151 @@ function Body({ children, className }: { children: ReactNode; className?: string
return <div className={cx('flex-1 overflow-auto overscroll-contain px-4 pt-3.5 pb-[18px]', className)}>{children}</div>
}
/** 문구를 모두 같은 칸에 겹쳐 두고 하나만 보인다: 대기 문구로 바뀌어도 버튼 크기가 그대로다 */
function Swap({ labels, at }: { labels: readonly ReactNode[]; at: number }) {
return (
<span className="inline-grid [&>*]:col-start-1 [&>*]:row-start-1">
{labels.map((l, i) => (
<span key={i} className={cx(i !== at && 'invisible')}>
{l}
</span>
))}
</span>
)
}
/* ---------- 시트 스켈레톤: 완료 화면과 같은 틀·같은 줄 높이 ---------- */
const N3 = [0, 1, 2]
const N4 = [0, 1, 2, 3]
const N6 = [0, 1, 2, 3, 4, 5]
const N14 = Array.from({ length: 14 }, (_, i) => i)
function GakSkel() {
return (
<div aria-hidden="true">
<div className="flex items-center gap-3">
<Skel shape className="size-[58px] shrink-0 rounded-full" />
<div className="flex-1">
<h4 className="m-0 font-jua text-[22px] font-normal">
<Skel className="w-28" />
</h4>
<p className="mt-0.5 text-[13.5px] font-semibold">
<Skel className="w-4/5" />
</p>
</div>
<b className="ml-auto font-bagel text-[42px] font-normal">
<Skel className="w-14" />
</b>
</div>
<Skel shape className="mx-auto mt-2 aspect-square w-full max-w-[250px] rounded-full" />
<div className="mt-2.5 grid grid-cols-4 gap-1.5">
{N4.map((i) => (
<div key={i} className="rounded-2xl bg-[#f3f6fb] px-1 py-2.5 text-center">
<small className="block text-xs font-extrabold">
<Skel className="w-8" />
</small>
<b className="block font-bagel text-2xl font-normal">
<Skel className="w-9" />
</b>
<small className="block text-[11px] leading-4 font-extrabold">
<Skel className="w-6" />
</small>
</div>
))}
</div>
<div className="mt-3.5 flex flex-col gap-2.5">
{N6.map((i) => (
<div key={i} className="grid grid-cols-[84px_1fr_52px] items-center gap-x-2.5 text-[13.5px] font-bold">
<span>
<Skel className="w-12" />
</span>
<Skel shape className="h-[9px] rounded-full" />
<em className="text-right text-xs not-italic">
<Skel className="w-10" />
</em>
<p className="col-start-2 col-end-4 -mt-0.5 text-[12.5px] font-semibold">
<Skel className="w-3/4" />
</p>
</div>
))}
</div>
<div className="mt-3.5 flex flex-col gap-1.5 text-[13px] font-semibold">
<span>
<Skel className="w-full" />
<br />
<Skel className="w-1/2" />
</span>
<span>
<Skel className="w-4/5" />
</span>
</div>
</div>
)
}
/** 읽을거리·이번 주 특집: 그림 150px · 머리말 · 제목 · 본문 */
function ArticleSkel() {
return (
<div aria-hidden="true">
<Skel shape className="mb-3.5 h-[150px] rounded-[20px]" />
<p className="text-[13px] font-extrabold">
<Skel className="w-24" />
</p>
<h4 className="mt-1.5 mb-2.5 font-jua text-2xl leading-tight font-normal">
<Skel className="w-4/5" />
</h4>
{N3.map((k) => (
<p key={k} className="mb-2.5 text-[15px] leading-[1.7]">
<Skel className="w-full" />
<br />
<Skel className="w-2/3" />
</p>
))}
</div>
)
}
function CommentsSkel() {
return (
<div aria-hidden="true">
{N3.map((i) => (
<div key={i} className="grid grid-cols-[34px_1fr_24px] items-start gap-2.5 py-2">
<Skel shape className="size-[34px] rounded-full" />
<div>
<p className="m-0 text-sm">
<Skel className="w-3/4" />
</p>
<small className="mt-0.5 block text-xs font-bold">
<Skel className="w-24" />
</small>
</div>
</div>
))}
</div>
)
}
function RegionsSkel() {
return (
<ul className="mt-2 flex flex-col" aria-hidden="true">
{N14.map((i) => (
<li key={i} className="border-b-[1.5px] border-(--line) px-1 py-3 font-jua text-[17px]">
<Skel className="w-28" />
</li>
))}
</ul>
)
}
/* ---------- 각 계산 근거 ---------- */
const labelLines = (label: string) => {
const cut = label.indexOf(' ')
return cut < 0 ? [label] : [label.slice(0, cut), label.slice(cut + 1)]
}
function Radar({ name, factors, size = 250 }: { name: string; factors: Factor[]; size?: number }) {
const c = size / 2
const r = size / 2 - 34
const r = size / 2 - 40
const n = factors.length
const pt = (i: number, v: number) => {
const a = -Math.PI / 2 + (i * 2 * Math.PI) / n
@@ -135,8 +276,12 @@ function Radar({ name, factors, size = 250 }: { name: string; factors: Factor[];
<circle key={f.axis} cx={pt(i, f.value / 100)[0]} cy={pt(i, f.value / 100)[1]} r="4.5" fill="#fff" stroke="#ff7a45" strokeWidth="2.5" />
))}
{factors.map((f, i) => (
<text key={f.axis} x={pt(i, 1.2)[0]} y={pt(i, 1.2)[1]} textAnchor="middle" dominantBaseline="middle" fontFamily="Jua,sans-serif" fontSize="14" fill="#28304a">
{f.label}
<text key={f.axis} x={pt(i, 1.24)[0]} y={pt(i, 1.24)[1]} textAnchor="middle" dominantBaseline="middle" fontFamily="Jua,sans-serif" fontSize="13" fill="#28304a">
{labelLines(f.label).map((line, k, all) => (
<tspan key={k} x={pt(i, 1.24)[0]} dy={k === 0 ? `${-(all.length - 1) * 0.55}em` : '1.1em'}>
{line}
</tspan>
))}
</text>
))}
</svg>
@@ -153,7 +298,8 @@ function GakSheet({ indexId, onTitle }: { indexId: number; onTitle: (t: string)
onTitle(g ? `${g.rank}위 ${g.name}` : '계산 근거')
}, [g, onTitle])
if (!g) return <Body>{<StateBox loading={q.isPending} error={q.error} onRetry={() => q.refetch()} empty="이 각의 계산 근거가 아직 없어요." className="mx-0" />}</Body>
const load = loadOf(q)
if (!g) return <Body>{load === 'loading' ? <GakSkel /> : <StateBox load={load} onRetry={() => q.refetch()} empty="이 각의 계산 근거가 아직 없어요." hold={<GakSkel />} className="inset-0" />}</Body>
const factors = d.factors ?? []
return (
<Body>
@@ -167,18 +313,19 @@ function GakSheet({ indexId, onTitle }: { indexId: number; onTitle: (t: string)
</div>
{factors.length > 2 && <Radar name={g.name} factors={factors} />}
{g.trend && g.trend.length > 0 && (
<div className="mt-2.5 grid grid-cols-3 gap-2">
{g.trend.map((t, j) => (
<div key={t.day} className="rounded-2xl bg-[#f3f6fb] p-2.5 text-center">
<small className="text-xs font-extrabold text-(--ink2)">{dayLabel(t.day, j)}</small>
<div className="mt-2.5 grid grid-cols-4 gap-1.5">
{g.trend.map((t) => (
<div key={t.day} className="rounded-2xl bg-[#f3f6fb] px-1 py-2.5 text-center">
<small className="block text-xs font-extrabold whitespace-nowrap text-(--ink2)">{t.label}</small>
<b className="block font-bagel text-2xl font-normal text-(--orange)">{t.score}</b>
<small className={cx('block text-[11px] leading-4 font-extrabold text-(--ink2)', !t.estimated && 'invisible')}>예상</small>
</div>
))}
</div>
)}
<div className="mt-3.5 flex flex-col gap-2.5">
{factors.map((f) => (
<div key={f.axis} className="grid grid-cols-[50px_1fr_52px] items-center gap-x-2.5 text-[13.5px] font-bold">
<div key={f.axis} className="grid grid-cols-[84px_1fr_52px] items-center gap-x-2.5 text-[13.5px] font-bold">
<span>{f.label}</span>
<i className="block h-[9px] overflow-hidden rounded-full bg-[#e3eaf4]">
<s className="block h-full bg-[linear-gradient(90deg,#ffc86e,var(--orange))]" style={{ width: `${f.value}%` }} />
@@ -191,12 +338,17 @@ function GakSheet({ indexId, onTitle }: { indexId: number; onTitle: (t: string)
<div className="mt-3.5 flex flex-col gap-1.5 text-[13px] font-semibold text-(--ink2)">
{d.zero_reason && (
<span>
<b className="text-(--heart)">오늘 0점인 이유:</b> {d.zero_reason}
<b className="text-(--heart)">오늘 걸린 조건:</b> {d.zero_reason}
</span>
)}
{factors.length > 0 && (
<span>
<b className="text-(--ink)">계산 방법:</b> 요소 점수에 비중을 곱해 더하고, 가장 낮은 요소가 낮을수록 최대 25%까지 더 깎아요
</span>
)}
{d.zero_rules && (
<span>
<b className="text-(--ink)">바로 0점:</b> {d.zero_rules}
<b className="text-(--ink)">점수 깎이는 조건:</b> {d.zero_rules}
</span>
)}
{d.limit && (
@@ -218,7 +370,8 @@ function ArticleSheet({ articleId, onTitle }: { articleId: number; onTitle: (t:
onTitle(a ? (ARTICLE_CAT[a.category]?.[0] ?? '') : '')
}, [a, onTitle])
if (!a) return <Body>{<StateBox loading={q.isPending} error={q.error} onRetry={() => q.refetch()} empty="글을 찾지 못했어요." className="mx-0" />}</Body>
const load = loadOf(q)
if (!a) return <Body>{load === 'loading' ? <ArticleSkel /> : <StateBox load={load} onRetry={() => q.refetch()} empty="글을 찾지 못했어요." hold={<ArticleSkel />} className="inset-0" />}</Body>
return (
<Body>
<div className={cx('mb-3.5 grid h-[150px] place-items-center rounded-[20px]', `b-bg-${cardBg(a.icon, a.article_id)}`)}>
@@ -240,13 +393,14 @@ function SeasonWeekSheet() {
const { open } = useSheet()
const q = useQuery(getSeasonWeekOptions())
const w = q.data
if (!w?.headline) return <Body>{<StateBox loading={q.isPending} error={q.error} onRetry={() => q.refetch()} empty="이번 주 특집이 아직 없어요." className="mx-0" />}</Body>
const load = loadOf(q)
if (!w?.headline) return <Body>{load === 'loading' ? <ArticleSkel /> : <StateBox load={load} onRetry={() => q.refetch()} empty="이번 주 특집이 아직 없어요." hold={<ArticleSkel />} className="inset-0" />}</Body>
return (
<Body>
<div className="mb-3.5 grid h-[150px] place-items-center rounded-[20px] b-bg-peach">
<Ic name="maple" className="w-24" />
</div>
<p className="text-[13px] font-extrabold text-(--ink2)">이번 주 특집 · {w.week}번째 주</p>
<p className="text-[13px] font-extrabold text-(--ink2)">{w.start && w.end ? dateRange(w.start, w.end) : '이번 주'}</p>
<h4 className="mt-1.5 mb-2.5 font-jua text-2xl leading-tight font-normal">{w.headline}</h4>
{(w.poem_lines ?? []).length > 0 && (
<p className="mb-2.5 font-batang text-[17px] leading-[1.7]">
@@ -280,7 +434,7 @@ function ShareSheet({ share }: { share: SharePayload }) {
const msg = isMine ? mine : opts[pick]
const url = window.location.origin
const text = `${msg} — ${share.title} · 날씨각`
const text = msg.trim() ? `${msg} — ${share.title} · 날씨각` : `${share.title} · 날씨각`
const { kind } = useSky()
const [image, setImage] = useState<{ blob: Blob; src: string } | null>(null)
const [imageError, setImageError] = useState(false)
@@ -450,22 +604,29 @@ function CommentRow({ c, postId }: { c: CommentData; postId: number }) {
)
}
const del = () =>
// 지우는 동안은 흐리게 두고, 성공하면 다시 받기 전에 목록 캐시에서 바로 뺀다
const del = () => {
setRemoveFailed(false)
remove.mutate(
{ path: { comment_id: c.comment_id } },
{
onSuccess: (res) => {
setRemoveFailed(!res.result?.success)
if (!res.result?.success) return
queryClient.invalidateQueries({ queryKey: listCommentsInfiniteQueryKey({ path: { post_id: postId } }) })
onSuccess: async (res) => {
if (!res.result?.success) return setRemoveFailed(true)
const key = listCommentsInfiniteQueryKey({ path: { post_id: postId } })
await queryClient.cancelQueries({ queryKey: key })
queryClient.setQueryData<InfiniteData<ResCommentList>>(key, (data) =>
data ? { ...data, pages: data.pages.map((p) => ({ ...p, comments: p.comments?.filter((x) => x.comment_id !== c.comment_id) })) } : data,
)
queryClient.invalidateQueries({ queryKey: key })
queryClient.invalidateQueries({ queryKey: getFeedQueryKey({ query: { region: region.code } }) })
},
onError: () => setRemoveFailed(true),
},
)
}
return (
<div className="grid grid-cols-[34px_1fr_24px] items-start gap-2.5 py-2">
<div className={cx('grid grid-cols-[34px_1fr_24px] items-start gap-2.5 py-2 transition-opacity', remove.isPending && 'opacity-50')} aria-busy={remove.isPending}>
<Avatar character={c.character} color={c.color} mood={c.mood} />
<div>
<p className="m-0 text-sm">
@@ -477,13 +638,12 @@ function CommentRow({ c, postId }: { c: CommentData; postId: number }) {
{c.mine && (
<>
{' · '}
<button type="button" onClick={del} disabled={remove.isPending} className="cursor-pointer font-bold text-(--ink3) underline-offset-2 hover:underline">
지우기
<button type="button" onClick={del} disabled={remove.isPending} className={cx('cursor-pointer text-left font-bold underline-offset-2 hover:underline', removeFailed && !remove.isPending ? 'text-(--heart)' : 'text-(--ink3)')}>
<Swap labels={['지우기', '지우는 중…', '못 지웠어요 · 다시']} at={remove.isPending ? 1 : removeFailed ? 2 : 0} />
</button>
</>
)}
</small>
{removeFailed && <small className="block text-xs font-bold text-(--heart)">지우지 못했어요. 다시 해 주세요.</small>}
</div>
<button type="button" onClick={toggle} aria-pressed={liked} aria-label="댓글 좋아요" className="cursor-pointer pt-1">
<HeartIcon className={cx('size-4 stroke-2', liked ? 'fill-(--heart) stroke-(--heart)' : 'fill-none stroke-(--ink3)')} />
@@ -512,7 +672,8 @@ function CommentsSheet({ postId }: { postId: number }) {
e.preventDefault()
if (!loggedIn) return open({ type: 'login' })
const body = text.trim()
if (!body) return
if (!body || add.isPending) return
setAddFailed(false)
add.mutate(
{ path: { post_id: postId }, body: { body } },
{
@@ -541,21 +702,19 @@ function CommentsSheet({ postId }: { postId: number }) {
</button>
)}
</>
) : list.isSuccess ? (
<p className="my-6 text-center font-semibold text-(--ink3)">
아직 댓글이 없어요.
<br />첫 댓글을 남겨 보세요.
</p>
) : loadOf(list) === 'loading' ? (
<CommentsSkel />
) : (
<StateBox loading={list.isPending} error={list.error} onRetry={() => list.refetch()} className="mx-0" />
<StateBox load={loadOf(list)} onRetry={() => list.refetch()} empty="아직 댓글이 없어요. 첫 댓글을 남겨 보세요." hold={<CommentsSkel />} className="inset-0" />
)}
</Body>
<div className="flex justify-around pt-1 pb-2 text-[22px]" role="group" aria-label="빠른 이모지">
<div className="flex justify-around pt-1 text-[22px]" role="group" aria-label="빠른 이모지">
{EMOJIS.map((e) => (
<button
key={e}
type="button"
className="cursor-pointer"
disabled={add.isPending}
className="cursor-pointer disabled:opacity-40"
onClick={() => {
setText((t) => (t + e).slice(0, 60))
inputRef.current?.focus()
@@ -565,15 +724,13 @@ function CommentsSheet({ postId }: { postId: number }) {
</button>
))}
</div>
{addFailed && (
<p className="px-4 pb-1 text-center text-xs font-bold text-(--heart)" role="alert">
댓글을 올리지 못했어요. 다시 해 주세요.
</p>
)}
<p className="h-4 px-4 text-center text-xs leading-4 font-bold text-(--heart)" role="alert">
{addFailed && '댓글을 올리지 못했어요. 다시 해 주세요.'}
</p>
<form onSubmit={submit} className="flex items-center gap-2.5 border-t border-(--line) px-3 pt-2.5 pb-[calc(10px+env(safe-area-inset-bottom,0px))]">
<input ref={inputRef} value={text} onChange={(e) => setText(e.target.value)} maxLength={60} placeholder={me ? `${me.nickname}(으)로 댓글 달기…` : '댓글 달기…'} aria-label="댓글" className="flex-1 rounded-full border border-[#dfe5ee] bg-[#f7f9fc] px-3.5 py-2.5" />
<input ref={inputRef} value={text} onChange={(e) => setText(e.target.value)} readOnly={add.isPending} maxLength={60} placeholder={me ? `${me.nickname}(으)로 댓글 달기…` : '댓글 달기…'} aria-label="댓글" className="min-w-0 flex-1 rounded-full border border-[#dfe5ee] bg-[#f7f9fc] px-3.5 py-2.5" />
<button type="submit" disabled={add.isPending || (loggedIn && !text.trim())} className="cursor-pointer font-extrabold text-(--rain) disabled:opacity-40">
게시
<Swap labels={['게시', '올리는 중…']} at={add.isPending ? 1 : 0} />
</button>
</form>
</>
@@ -621,7 +778,7 @@ function LoginSheet({ onDone }: { onDone: () => void }) {
return (
<Body>
<form onSubmit={submit} className="flex flex-col gap-2.5">
<p className="text-center text-sm font-semibold text-(--ink2)">좋아요·저장·댓글은 로그인한 뒤에 할 수 있어요.</p>
<p className="text-center text-sm font-semibold text-(--ink2)">좋아요·댓글은 로그인한 뒤에 할 수 있어요.</p>
<div className="grid grid-cols-2 gap-1 rounded-full bg-[#f3f6fb] p-1" role="group" aria-label="로그인 또는 가입">
{(
[
@@ -641,7 +798,7 @@ function LoginSheet({ onDone }: { onDone: () => void }) {
{error}
</p>
<button type="submit" disabled={pending} className="cursor-pointer rounded-[14px] bg-(--orange) p-[13px] font-jua text-[17px] text-white shadow-[inset_0_-5px_0_var(--orange-deep)] disabled:opacity-60">
{mode === 'login' ? '로그인' : '가입하고 시작하기'}
<Swap labels={mode === 'login' ? ['로그인', '로그인 중…'] : ['가입하고 시작하기', '가입하는 중…']} at={pending ? 1 : 0} />
</button>
<button type="button" onClick={onDone} className="cursor-pointer rounded-[14px] p-[13px] text-[15px] font-extrabold text-(--ink2)">
나중에 할게요
@@ -676,6 +833,12 @@ function MeSheet({ onDone }: { onDone: () => void }) {
)
}
// 저장하는 동안은 고른 값을 바로 선택으로 보여 준다. 실패하면 me 값으로 돌아간다
const saving = update.isPending ? update.variables?.body : undefined
const character = saving?.character ?? me.character
const color = saving?.color ?? me.color
const mood = saving?.mood ?? me.mood
return (
<Body className="flex flex-col gap-3">
<div className="flex flex-col items-center gap-1.5">
@@ -690,10 +853,10 @@ function MeSheet({ onDone }: { onDone: () => void }) {
key={key}
type="button"
role="radio"
aria-checked={me.character === key}
aria-checked={character === key}
disabled={update.isPending}
onClick={() => save({ character: key })}
className={cx('flex cursor-pointer flex-col items-center gap-1 rounded-[18px] border-2 bg-[#f7f9fc] py-2.5 font-jua text-[15px]', me.character === key ? 'border-(--orange) text-(--orange)' : 'border-transparent text-(--ink)')}
className={cx('flex cursor-pointer flex-col items-center gap-1 rounded-[18px] border-2 bg-[#f7f9fc] py-2.5 font-jua text-[15px]', character === key ? 'border-(--orange) text-(--orange)' : 'border-transparent text-(--ink)')}
>
<Ic name={key} className="w-12" />
{label}
@@ -709,11 +872,11 @@ function MeSheet({ onDone }: { onDone: () => void }) {
key={key}
type="button"
role="radio"
aria-checked={me.color === key}
aria-checked={color === key}
aria-label={key}
disabled={update.isPending}
onClick={() => save({ color: key })}
className={cx('size-9 cursor-pointer rounded-full border-[3px]', me.color === key ? 'border-(--ink)' : 'border-white shadow-[0_0_0_1px_var(--line)]')}
className={cx('size-9 cursor-pointer rounded-full border-[3px]', color === key ? 'border-(--ink)' : 'border-white shadow-[0_0_0_1px_var(--line)]')}
style={{ background: hex }}
/>
))}
@@ -727,10 +890,10 @@ function MeSheet({ onDone }: { onDone: () => void }) {
key={key}
type="button"
role="radio"
aria-checked={me.mood === key}
aria-checked={mood === key}
disabled={update.isPending}
onClick={() => save({ mood: me.mood === key ? '' : key })}
className={cx('flex cursor-pointer flex-col items-center gap-0.5 rounded-[14px] border-2 bg-[#f7f9fc] py-2 text-xs font-bold', me.mood === key ? 'border-(--orange) text-(--orange)' : 'border-transparent text-(--ink2)')}
onClick={() => save({ mood: mood === key ? '' : key })}
className={cx('flex cursor-pointer flex-col items-center gap-0.5 rounded-[14px] border-2 bg-[#f7f9fc] py-2 text-xs font-bold', mood === key ? 'border-(--orange) text-(--orange)' : 'border-transparent text-(--ink2)')}
>
<span className="text-[22px] leading-none">{emoji}</span>
{label}
@@ -748,11 +911,11 @@ function MeSheet({ onDone }: { onDone: () => void }) {
>
<input value={nickname} onChange={(e) => setNickname(e.target.value)} required minLength={2} maxLength={12} aria-label="닉네임" placeholder="닉네임 (2~12자)" className="flex-1 rounded-[14px] border border-[#dfe5ee] bg-[#f7f9fc] px-3.5 py-3" />
<button type="submit" disabled={update.isPending || nickname.trim() === me.nickname} className="cursor-pointer rounded-[14px] bg-(--ink) px-4 py-3 text-sm font-extrabold text-white disabled:opacity-40">
바꾸기
<Swap labels={['바꾸기', '저장 중…']} at={saving?.nickname != null ? 1 : 0} />
</button>
</form>
<p className="m-0 min-h-5 text-center text-[13px] font-bold text-(--heart)" aria-live="polite">
{error}
<p className={cx('m-0 min-h-5 text-center text-[13px] font-bold', saving ? 'text-(--ink2)' : 'text-(--heart)')} aria-live="polite">
{saving ? (saving.nickname == null ? '저장 중…' : '') : error}
</p>
<button
type="button"
@@ -779,6 +942,7 @@ function RegionSheet({ onDone }: { onDone: () => void }) {
const deferred = useDeferredValue(q.trim())
const list = useQuery(listRegionsOptions(deferred ? { query: { q: deferred } } : undefined))
const regions = list.data?.regions ?? []
const listLoad = loadOf(list)
return (
<Body>
@@ -789,8 +953,9 @@ function RegionSheet({ onDone }: { onDone: () => void }) {
{LOCATE_TEXT[locateStatus]}
</p>
<input value={q} onChange={(e) => setQ(e.target.value)} placeholder="구 이름으로 찾기 (예: 마포)" aria-label="구 이름으로 찾기" className="mt-1 w-full rounded-full border border-[#dfe5ee] bg-[#f7f9fc] px-3.5 py-2.5" />
<StateBox loading={list.isPending} error={list.error} onRetry={() => list.refetch()} empty={list.isSuccess && !regions.length ? '찾는 구가 없어요.' : undefined} className="mx-0" />
<ul className="mt-2 flex flex-col">
{listLoad === 'loading' && <RegionsSkel />}
{listLoad !== 'loading' && !regions.length && (listLoad === 'ready' ? <StateBox load={listLoad} empty="찾는 구가 없어요." className="mt-3" /> : <StateBox load={listLoad} onRetry={() => list.refetch()} hold={<RegionsSkel />} className="inset-x-0 top-2 bottom-0" />)}
<ul className={cx('mt-2 flex flex-col transition-opacity', list.isPlaceholderData && 'opacity-60')}>
{regions.map((r) => (
<li key={r.code}>
<button
@@ -809,7 +974,7 @@ function RegionSheet({ onDone }: { onDone: () => void }) {
))}
</ul>
<p className="mt-4 flex items-center justify-center gap-2 text-[13px] font-bold text-(--ink2)">
{me ? `${me.nickname}(으)로 로그인했어요` : '로그인하면 좋아요·저장·댓글을 쓸 수 있어요'}
{me ? `${me.nickname}(으)로 로그인했어요` : '로그인하면 좋아요·댓글을 쓸 수 있어요'}
<button type="button" onClick={me ? logout : () => open({ type: 'login' })} className="cursor-pointer font-extrabold text-(--rain)">
{me ? '로그아웃' : '로그인'}
</button>
+170 -74
View File
@@ -1,10 +1,11 @@
import { useQuery } from '@tanstack/react-query'
import type { ReactNode } from 'react'
import { getSkyOptions, getSkyRankingOptions } from '../api/client/@tanstack/react-query.gen'
import type { RegionData, SpotData } from '../api/client/types.gen'
import type { BestTime, RegionData, SkyPlanData, SpotData } from '../api/client/types.gen'
import { cx } from '../lib/utils'
import { clockShort, dayLabel, timeWords } from './lib'
import { clockShort, compass, dayLabel, loadOf } from './lib'
import { useRegion } from './regionContext'
import { Rail, Sec, StateBox } from './ui'
import { Sec, Skel, StateBox } from './ui'
const W = 400
const H = 260
@@ -45,7 +46,7 @@ function SpotMap({ region, spots, azimuth }: { region: RegionData; spots: SpotDa
<path d={`M${cx0} ${cy0} L${dir(260, -0.3).join(' ')} L${dir(260, 0.3).join(' ')} Z`} fill="#ff8e4e" opacity=".18" />
<path d={`M${cx0} ${cy0} L${tip.join(' ')}`} stroke="#ff7a45" strokeWidth="3" strokeDasharray="7 6" />
<text x={Math.min(W - 110, Math.max(8, label[0] - 50))} y={label[1] + 26} fontFamily="Jua,sans-serif" fontSize="14" fill="#d4552a">
해 지는 쪽 {azimuth}°
해 지는 {compass(azimuth)}쪽
</text>
</>
)}
@@ -67,21 +68,124 @@ function SpotMap({ region, spots, azimuth }: { region: RegionData; spots: SpotDa
)
}
function Li({ no, title, sub, right, meter, mine = false }: { no: number; title: string; sub?: string | null; right: string; meter?: number; mine?: boolean }) {
function LiSkel({ ghost = false }: { ghost?: boolean }) {
return (
<li className={cx('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', ghost && 'invisible')} aria-hidden="true">
<span className="text-center font-bagel text-xl">
<Skel className="w-5" />
</span>
<span>
<b className="block font-jua text-[17px] font-normal">
<Skel className="w-24" />
</b>
<small className="block truncate text-[12.5px] font-semibold">
<Skel className="w-40" />
</small>
</span>
<em className="font-jua text-base not-italic">
<Skel className="w-9" />
</em>
</li>
)
}
const HERO = 'relative mx-3 mt-1 min-h-[350px] overflow-hidden rounded-[32px] bg-[linear-gradient(180deg,#7e6fe6,#f08aa2_58%,#ffc28a)] px-5 pt-5 pb-16 text-white'
const THREE = [0, 1, 2]
const FOUR = [0, 1, 2, 3]
const RANK_SKELS = Array.from({ length: 8 }, (_, i) => i)
/** 결론 → 왜 → 몇 시에 어디로 → 점수(보조). 글자 줄 수를 고정해 스켈레톤과 크기가 같다 */
function HeroBody({ plan }: { plan?: SkyPlanData }) {
const v = (node: ReactNode, w: string) => (plan ? node : <Skel className={w} />)
const place = plan && (plan.spot ? `${plan.spot.name} · ${plan.spot.distance_km}km` : plan.verdict === 'rest' ? '오늘은 나가지 않아도 돼요' : '30km 안에 등록된 명소가 없어요')
return (
<div aria-hidden={plan ? undefined : true}>
<p className="relative m-0 mt-1.5 font-jua text-[38px] leading-[1.1]">{v(plan?.headline, 'w-[200px]')}</p>
<div className="relative z-[1] mt-3 rounded-[20px] bg-[rgb(45_36_64/0.55)] px-4 py-3">
<p className="m-0 line-clamp-2 h-[2lh] text-[14.5px] leading-snug font-bold">{v(plan?.reason, 'w-[250px]')}</p>
<div className="mt-2.5 grid grid-cols-[auto_1fr] items-center gap-x-3 border-t border-white/25 pt-2.5">
<b className="row-span-2 font-bagel text-[30px] leading-none font-normal">{v(plan?.best_at && clockShort(plan.best_at), 'w-[76px]')}</b>
<span className="text-[13px] font-extrabold">{v(plan && '가장 붉을 때', 'w-20')}</span>
<span className="truncate text-[13px] font-bold">{v(place, 'w-36')}</span>
</div>
<p className="m-0 mt-2.5 border-t border-white/25 pt-2 text-[12.5px] leading-snug font-bold">
{v(plan && `노을 점수 ${plan.score}점 · ${plan.grade_label}`, 'w-32')}
<small className="block text-[12px] font-semibold">{v(plan && '해 지는 쪽 구름 높이·양으로 매겨요. 60점부터 나가 볼 만해요', 'w-56')}</small>
</p>
</div>
</div>
)
}
/** 일몰 전 골든아워 → 해 짐 → 가장 붉을 때 → 블루아워, 한 줄 */
function Timeline({ rows }: { rows?: BestTime[] }) {
return (
<ol className="relative mx-3 mt-3 grid grid-cols-4 rounded-[22px] bg-white px-2 pt-4 pb-3 shadow-[inset_0_-5px_0_var(--shade)]" aria-hidden={rows ? undefined : true}>
<span className="absolute inset-x-[12.5%] top-[22px] h-0.5 bg-(--line)" aria-hidden="true" />
{(rows ?? FOUR.map(() => undefined)).map((t, i) => (
<li key={t?.kind ?? i} className="relative flex flex-col items-center text-center">
<span className={cx('size-3 rounded-full border-2 border-(--line) bg-white', t?.kind === 'peak' && 'border-[#d6457a] bg-[#d6457a]')} />
<b className={cx('mt-1.5 font-bagel text-lg leading-tight font-normal', t?.kind === 'peak' && 'text-[#d6457a]')}>{t ? clockShort(t.at) : <Skel className="w-12" />}</b>
<span className="text-[12px] font-bold text-(--ink2)">{t ? t.label : <Skel className="w-11" />}</span>
</li>
))}
</ol>
)
}
function SpotsSkel() {
return (
<>
<Skel shape className="mx-3 mt-3 aspect-[400/260] rounded-[26px]" />
<ul className="mx-3 mt-1.5 flex flex-col">
{THREE.map((i) => (
<LiSkel key={i} />
))}
</ul>
</>
)
}
function DaysSkel() {
return (
<div className="grid grid-cols-3 gap-2 p-3" aria-hidden="true">
{THREE.map((i) => (
<div key={i} className="rounded-[20px] bg-white p-3 text-center shadow-[inset_0_-5px_0_var(--shade)]">
<small className="block text-[12.5px] font-extrabold">
<Skel className="w-10" />
</small>
<b className="block font-bagel text-[30px] font-normal">
<Skel className="w-10" />
</b>
<span className="block text-xs font-bold">
<Skel className="w-12" />
</span>
</div>
))}
</div>
)
}
function RankSkel() {
return (
<ul className="mx-3 mt-1.5 flex flex-col" aria-hidden="true">
{RANK_SKELS.map((i) => (
<LiSkel key={i} />
))}
</ul>
)
}
function Li({ no, title, sub, right, mine = false }: { no: number; title: string; sub?: string | null; right: string; mine?: boolean }) {
return (
<li className={cx('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', mine && 'rounded-2xl bg-white')}>
<span className="text-center font-bagel text-xl text-(--orange)">{no}</span>
<span>
<span className="min-w-0">
<b className="block font-jua text-[17px] font-normal">
{title}
{mine && <small className="ml-1.5 font-sans text-xs font-extrabold text-(--rain)">내 지역</small>}
</b>
{sub && <small className="text-[12.5px] font-semibold text-(--ink2)">{sub}</small>}
{meter != null && (
<span className="mt-[5px] block h-1.5 overflow-hidden rounded-full bg-[#eef1f6]">
<s className="block h-full bg-[linear-gradient(90deg,#ffc86e,#ff6f8e)]" style={{ width: `${meter}%` }} />
</span>
)}
<small className="block truncate text-[12.5px] font-semibold text-(--ink2)">{sub || '\u00a0'}</small>
</span>
<em className="font-jua text-base not-italic">{right}</em>
</li>
@@ -92,57 +196,54 @@ export function SkyPage() {
const { region } = useRegion()
const sky = useQuery(getSkyOptions({ query: { region: region.code } }))
const ranking = useQuery(getSkyRankingOptions())
const s = sky.data?.sunset
const times = s?.best_times ?? []
const peak = times.find((t) => t.kind === 'peak')
const spots = sky.data?.spots ?? []
const load = loadOf(sky)
const rankLoad = loadOf(ranking)
const plan = sky.data?.plan ?? undefined
const spots = (sky.data?.spots ?? []).slice(0, 3)
const days = sky.data?.days ?? []
const items = (ranking.data?.items ?? []).slice(0, 8)
const target = Math.max(0, days.findIndex((d) => d.day === plan?.day))
const best = days.reduce<number>((b, d, i) => (d.score > days[b].score ? i : b), target)
// 서버 outlook 과 같은 기준: 10점 넘게 나을 때만 더 나은 날로 표시
const better = days.length > 0 && days[best].score - days[target].score > 10 ? best : -1
return (
<section aria-label="노을">
{s ? (
<div className="relative mx-3 mt-1 min-h-[300px] overflow-hidden rounded-[32px] bg-[linear-gradient(180deg,#7e6fe6,#f08aa2_58%,#ffc28a)] px-5 pt-5 pb-16 text-white">
<div className="b-skyline pointer-events-none absolute inset-0 [--sky-h:22%]" aria-hidden="true" />
<p className="relative m-0 text-[13px] font-extrabold opacity-90">오늘 노을 · {region.name}</p>
<b className="relative mt-1.5 block font-bagel text-[96px] leading-[0.9] font-normal">{s.score}</b>
<p className="relative m-0 font-jua text-[29px] leading-tight">
{s.grade_label}
{peak && ` · ${timeWords(peak.at)}이 절정`}
</p>
{times.length > 0 && (
<div className="relative z-[1] mt-[18px]">
<div className="h-2.5 rounded-full bg-[linear-gradient(90deg,#ffd27a,#ff7a6e_50%,#6a5bd6)]" />
<div className="mt-1.5 flex justify-between text-[12.5px] font-extrabold">
{times.map((t, i) => (
<span key={t.kind} className={cx(i === 1 && 'text-center', i === times.length - 1 && i > 0 && 'text-right')}>
<b className="block font-bagel text-lg font-normal">{clockShort(t.at)}</b>
{t.label}
</span>
))}
</div>
</div>
)}
</div>
<section aria-label="노을" aria-busy={load === 'loading'} className={cx('transition-opacity', sky.isPlaceholderData && 'opacity-60')}>
{/* 히어로 상자는 불러오는 중·실패·빈 값 모두 같은 크기 */}
<div className={HERO}>
<div className="b-skyline pointer-events-none absolute inset-0 [--sky-h:16%]" aria-hidden="true" />
<p className="relative m-0 text-[13px] font-extrabold">
{plan?.when ?? '오늘'} 노을 · {region.name}
</p>
{plan || load === 'loading' ? (
<HeroBody plan={plan} />
) : (
<StateBox load={load} onRetry={() => sky.refetch()} empty="오늘 노을 정보가 없어요." hold={<HeroBody />} className="inset-x-0 top-1.5 bottom-0" />
)}
</div>
<Sec title="언제 보면 좋을까" sub={plan ? `${plan.when} 해 지는 시간 기준` : '\u00a0'} />
{plan?.timeline?.length || load === 'loading' ? (
<Timeline rows={plan?.timeline} />
) : (
<StateBox loading={sky.isPending} error={sky.error} onRetry={() => sky.refetch()} empty="오늘 노을 정보가 없어요." />
<StateBox load="ready" empty={load === 'ready' ? '노을 시간 정보가 없어요.' : '노을 시간을 불러오지 못했어요.'} hold={<Timeline />} className="inset-x-3 top-3 bottom-0" />
)}
{times.length > 0 && (
<>
<Sec title="오늘의 노을 3컷" sub="옆으로 넘겨 보세요" />
<Rail label="오늘의 노을 3컷">
{times.map((t, i) => (
<div key={t.kind} className={cx('b-skyline relative h-[150px] w-[230px] overflow-hidden rounded-[22px] px-3.5 py-2.5 font-bagel text-2xl text-white [--sky-h:30%]', `b-cut-${Math.min(i + 1, 3)}`)}>
<span className="relative z-[1]">
{clockShort(t.at)}
<small className="block font-jua text-sm">{t.label}</small>
</span>
</div>
))}
</Rail>
</>
<Sec title="내일·모레가 더 나을까" sub={plan?.outlook || '\u00a0'} />
{days.length > 0 ? (
<div className="grid grid-cols-3 gap-2 p-3">
{days.map((d, i) => (
<div key={d.day} className={cx('rounded-[20px] bg-white p-3 text-center shadow-[inset_0_-5px_0_var(--shade)]', i === better && 'ring-2 ring-[#d6457a] ring-inset')}>
<small className="block text-[12.5px] font-extrabold text-(--ink2)">{dayLabel(d.day, i)}</small>
<b className={cx('block font-bagel text-[30px] font-normal', d.score < 60 ? 'text-(--ink2)' : 'text-[#d6457a]')}>{d.score}</b>
<span className="block text-xs font-bold text-(--ink2)">{d.grade_label}</span>
</div>
))}
</div>
) : load === 'loading' ? (
<DaysSkel />
) : (
<StateBox load="ready" empty={load === 'ready' ? '앞으로 3일 노을 정보가 없어요.' : '앞으로 3일 노을을 불러오지 못했어요.'} hold={<DaysSkel />} className="inset-3" />
)}
<Sec title="가까운 노을 명소" sub={sky.data?.sunset_azimuth != null ? `해 지는 쪽 ${sky.data.sunset_azimuth}° · 서쪽이 트인 곳` : '서쪽이 트인 곳'} />
<Sec title="가까운 노을 명소" sub={sky.data?.sunset_azimuth != null ? `해 지는 ${compass(sky.data.sunset_azimuth)}쪽이 트인 곳, 가까운 순` : '서쪽이 트인 곳, 가까운 순'} />
{spots.length ? (
<>
<SpotMap region={region} spots={spots} azimuth={sky.data?.sunset_azimuth} />
@@ -150,34 +251,29 @@ export function SkyPage() {
{spots.map((p) => (
<Li key={p.no} no={p.no} title={p.name} sub={p.description} right={`${p.distance_km}km`} />
))}
{/* 3곳이 안 되면 빈 줄로 스켈레톤 높이를 지켜 아래 순위가 밀리지 않게 */}
{THREE.slice(spots.length).map((i) => (
<LiSkel key={`ghost-${i}`} ghost />
))}
</ul>
</>
) : load === 'loading' ? (
<SpotsSkel />
) : (
<StateBox loading={sky.isPending} error={sky.error} empty="이 지역은 아직 등록된 노을 명소가 없어요." />
// 실패 안내·다시 시도는 위 히어로에 한 번만. 여기는 지도·목록 자리만 지킨다
<StateBox load="ready" empty={load === 'ready' ? '근처에 등록된 노을 명소가 없어요.' : '명소 정보를 불러오지 못했어요.'} hold={<SpotsSkel />} className="inset-x-3 top-3 bottom-0" />
)}
<Sec title="전국 노을 순위" sub={items[0] ? `오늘 기준 · 1위 ${items[0].name} ${items[0].score}점` : '오늘 기준'} />
<Sec title="전국 노을 순위" sub="오늘 기준" />
{items.length ? (
<ul className="mx-3 mt-1.5 flex flex-col">
{items.map((r) => (
<Li key={r.region_code} no={r.rank} title={r.name} sub={r.note} right={String(r.score)} meter={r.score} mine={r.region_code === region.code} />
<Li key={r.region_code} no={r.rank} title={r.name} sub={r.note} right={`${r.score}점`} mine={r.region_code === region.code} />
))}
</ul>
) : rankLoad === 'loading' ? (
<RankSkel />
) : (
<StateBox loading={ranking.isPending} error={ranking.error} onRetry={() => ranking.refetch()} empty="순위가 아직 없어요." />
)}
{days.length > 0 && (
<>
<Sec title="앞으로 3일" />
<div className="grid grid-cols-3 gap-2 p-3">
{days.map((d, i) => (
<div key={d.day} className="rounded-[20px] bg-white p-3 text-center shadow-[inset_0_-5px_0_var(--shade)]">
<small className="text-[12.5px] font-extrabold text-(--ink2)">{dayLabel(d.day, i)}</small>
<b className={cx('block font-bagel text-[30px] font-normal', d.score < 50 ? 'text-(--ink3)' : 'text-[#d6457a]')}>{d.score}</b>
<span className="text-xs font-bold text-(--ink2)">{d.grade_label}</span>
</div>
))}
</div>
</>
<StateBox load={rankLoad} onRetry={() => ranking.refetch()} empty="순위가 아직 없어요." hold={<RankSkel />} className="inset-x-3 top-1.5 bottom-0" />
)}
</section>
)
+128 -78
View File
@@ -4,18 +4,18 @@ import { useQuery } from '@tanstack/react-query'
import { getFeedOptions, getWeatherTodayOptions } from '../api/client/@tanstack/react-query.gen'
import type { BandArticle, BandEvent, Hero as HeroData, ResWeatherToday, TopIndex } from '../api/client/types.gen'
import { cx } from '../lib/utils'
import { cardBg, fall, kindOfHour, kst, MEDALS, sidoOf, WEEKDAYS, type TimeKind } from './lib'
import { PostCard } from './Post'
import { cardBg, kindOfHour, kst, type Load, loadOf, MEDALS, type TimeKind, WEEKDAYS } from './lib'
import { PostCard, PostCardSkel } from './Post'
import { useRegion } from './regionContext'
import { useSheet } from './sheetContext'
import { useSky } from './skyContext'
import { Ic, Rail, Sec, StateBox } from './ui'
import { Ic, Rail, Sec, Skel, SkelRail, StateBox, Thumb } from './ui'
import { deg, skyText, slotAt } from './weatherText'
type Mode = 'now' | TimeKind
const MODES: [Mode, string][] = [
['now', '지금 시간'],
['now', '지금'],
['morning', '아침'],
['day', '낮'],
['sunset', '저녁'],
@@ -30,8 +30,8 @@ const PREVIEW: Record<TimeKind, { label: string; clock: string; hour: number }>
night: { label: '밤', clock: '22:10', hour: 22 },
}
const STARS = Array.from({ length: 26 }, (_, i) => ({ left: `${(i * 37) % 100}%`, top: `${(i * 53) % 60}%`, opacity: 0.4 + ((i * 7) % 6) / 10 }))
const ORB_POS = { left: '66%', top: '6px', d: '.5s', f: '4.4s' }
// 불쾌지수는 6~9월에만 뜻이 있고, 그 밖엔 늘 '쾌적'이라 하루 최저·최고(일교차)를 보여 준다
const isMuggySeason = (month: number) => month >= 6 && month <= 9
function useNow(ms = 20000) {
const [now, setNow] = useState(() => new Date())
@@ -42,9 +42,27 @@ function useNow(ms = 20000) {
return now
}
type HeroProps = { hero?: HeroData | null; today?: ResWeatherToday }
// 값이 오기 전엔 그 글자 자리(같은 줄 높이)에 스켈레톤, 못 불러왔거나 값이 없으면 같은 글꼴의 '?'
function heroVal(load: Load, v: ReactNode, skel: string) {
if (v != null) return v
if (load === 'loading')
return (
<>
<Skel className={skel} />
<span className="sr-only">불러오는 중</span>
</>
)
return (
<>
<span className="opacity-50" aria-hidden="true">?</span>
<span className="sr-only">{load === 'ready' ? '정보 없음' : '못 불러왔어요'}</span>
</>
)
}
function Hero({ hero, today }: HeroProps) {
type HeroProps = { hero?: HeroData | null; today?: ResWeatherToday; feedLoad: Load; todayLoad: Load }
function Hero({ hero, today, feedLoad, todayLoad }: HeroProps) {
const { open } = useSheet()
const [mode, setMode] = useState<Mode>('now')
const clock = useNow()
@@ -61,87 +79,85 @@ function Hero({ hero, today }: HeroProps) {
const temp = mode === 'now' && hero ? hero.temp_c : slot?.temp_c
const feels = mode === 'now' && hero ? hero.feels_c : slot?.feels_c
const top1 = hero?.top1
const who = kind === 'night' ? 'bear' : 'rabbit'
const tempLoad = mode === 'now' ? feedLoad : todayLoad
const temps = slots.flatMap((s) => (s.temp_c == null ? [] : [s.temp_c]))
const muggy = isMuggySeason(t.mo)
const feelsLine = temp != null ? `체감 ${deg(feels)}${slot ? ` · ${skyText(slot)}` : ''}` : tempLoad === 'loading' ? null : '체감 ?°'
// 1위 각 이름·점수는 바로 아래 '오늘의 각' 줄에 있으니 히어로는 결론 한 줄만
const gakLine = hero?.bubble ?? (hero ? '오늘은 쉬어 가요' : null)
// 글자 크기는 64(기온)·40(점수)·16(값)·13(라벨) 네 단계. 모든 값은 한 줄이라 로딩·완료·실패 높이가 같다
return (
<div className="b-hero relative mx-3 mt-1 overflow-hidden rounded-[32px] px-[18px] pt-4 pb-[18px]" data-t={kind}>
<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 bg-white shadow-[0_0_6px_#fff]" style={s} />
))}
</div>
<div className="relative z-[3] flex flex-wrap gap-1.5" role="group" aria-label="시간대 배경 미리보기">
<div className="b-hero mx-3 mt-1 rounded-[28px] px-4 pt-3.5 pb-4" data-t={kind}>
<div className="b-seg flex rounded-full p-[3px]" role="group" aria-label="시간대 배경 미리보기">
{MODES.map(([m, l]) => (
<button key={m} type="button" aria-pressed={mode === m} onClick={() => setMode(m)} className={cx('cursor-pointer rounded-full px-2.5 py-[5px] text-xs font-bold', mode === m ? 'bg-(--ink) text-white' : 'bg-white/55 text-(--ink)')}>
<button key={m} type="button" aria-pressed={mode === m} onClick={() => setMode(m)} className="flex-1 cursor-pointer rounded-full py-1 text-[13px] font-bold">
{l}
</button>
))}
</div>
<div className="relative z-[3] mt-3 flex items-end justify-between">
<div>
<p className="mb-1 text-[13.5px] font-bold opacity-85">
{t.mo}월 {t.d}일 {WEEKDAYS[t.wd]}요일 · {mode === 'now' ? '지금' : `${PREVIEW[mode].label} 미리보기`}
<div className="mt-4 flex items-center justify-between gap-3 px-1">
<div className="min-w-0">
<p className="text-[13px] font-bold">
{t.mo}월 {t.d}일 {WEEKDAYS[t.wd]}요일 · {mode === 'now' ? `${String(t.h).padStart(2, '0')}:${String(t.mi).padStart(2, '0')}` : `${PREVIEW[mode].label} ${PREVIEW[mode].clock} 예보`}
</p>
<div className="font-bagel text-[60px] leading-none">{mode === 'now' ? `${String(t.h).padStart(2, '0')}:${String(t.mi).padStart(2, '0')}` : PREVIEW[mode].clock}</div>
<b className="block font-bagel text-[64px] leading-[1.1] font-normal">{heroVal(tempLoad, temp != null ? deg(temp) : null, 'w-[112px]')}</b>
<p className="truncate font-jua text-base">{feelsLine ?? <Skel className="w-[112px]" />}</p>
</div>
<div className="text-right">
<b className="font-bagel text-[42px] leading-none font-normal">{temp != null ? deg(temp) : '--°'}</b>
<span className="block text-[12.5px] font-bold opacity-85">{temp != null ? `체감 ${deg(feels)}${slot ? ` · ${skyText(slot)}` : ''}` : '날씨를 불러오는 중'}</span>
</div>
</div>
<div className="relative z-[3] mt-3 grid grid-cols-2 gap-2.5">
<div className="b-stat flex items-center gap-2.5 rounded-[20px] px-3 py-[9px]">
<Ic name="thermo" className="w-9" />
<div>
<small className="block text-xs font-bold opacity-80">불쾌지수</small>
<b className="font-jua text-lg font-normal">{hero?.discomfort != null ? `${hero.discomfort} · ${hero.discomfort_label ?? ''}` : '-'}</b>
</div>
</div>
<div className="b-stat flex items-center gap-2.5 rounded-[20px] px-3 py-[9px]">
<Ic name="umbrella" className="w-9" />
<div>
<small className="block text-xs font-bold opacity-80">지금 비</small>
<b className="font-jua text-lg font-normal">{hero?.will_rain_2h == null ? '-' : hero.will_rain_2h ? '2시간 안에 비' : '2시간 없음'}</b>
</div>
</div>
</div>
<div className="relative mt-5 h-[286px]">
<span className="b-cloud b-fall top-6 left-[6%] h-[30px] w-[84px]" style={fall('.1s', '6s')} aria-hidden="true" />
<div className="b-sun b-fall absolute top-10 left-1/2 -ml-[82px] grid aspect-square w-[164px] place-items-center rounded-full text-center" style={fall('0s', '5.6s', '8px')}>
<div className="b-sun b-bob grid size-[112px] shrink-0 place-items-center rounded-full text-center">
<span>
<b className="block font-bagel text-[56px] leading-[0.9] font-normal">{hero?.weather_score ?? '-'}</b>
<small className="mt-0.5 block font-jua text-[14.5px]">오늘 날씨 점수</small>
<b className="block font-bagel text-[40px] leading-[1.1] font-normal">{heroVal(feedLoad, hero?.weather_score, 'w-[52px]')}</b>
<small className="block text-[13px] font-bold">날씨 점수</small>
</span>
</div>
<span className="b-cloud b-fall top-[188px] left-[54%] h-10 w-[118px]" style={fall('.25s', '6.4s')} aria-hidden="true" />
{top1 && (
<button
type="button"
onClick={() => open({ type: 'gak', indexId: top1.index_id })}
aria-label={`1위 ${top1.name} ${top1.score}점, 계산 근거 보기`}
className="b-fall absolute z-[2] flex w-24 cursor-pointer flex-col items-center"
style={{ left: ORB_POS.left, top: ORB_POS.top, ...fall(ORB_POS.d, ORB_POS.f) }}
>
<span className="relative w-[78px]">
<Ic name={top1.icon} className="w-full drop-shadow-[0_10px_12px_rgb(40_48_74/0.16)]" />
<Ic name={MEDALS[0]} className="absolute -top-2 -left-3.5 w-[30px]" />
</span>
<span className="b-orb-label font-jua text-sm whitespace-nowrap">
1위 {top1.name} <em className="font-bagel text-(--orange) not-italic">{top1.score}</em>
</div>
<div className="b-stat mt-4 grid grid-cols-2 rounded-[20px]">
<HeroStat icon="umbrella" label="앞으로 2시간">
{heroVal(feedLoad, hero?.will_rain_2h == null ? null : hero.will_rain_2h ? '비, 우산 챙겨요' : '비 안 와요', 'w-[72px]')}
</HeroStat>
<HeroStat icon="thermo" label={muggy ? '불쾌지수' : '오늘 최저·최고'} className="border-l border-current/10">
{muggy
? heroVal(feedLoad, hero?.discomfort != null ? `${hero.discomfort} · ${hero.discomfort_label ?? ''}` : null, 'w-[72px]')
: heroVal(todayLoad, temps.length ? `${deg(Math.min(...temps))} ~ ${deg(Math.max(...temps))}` : null, 'w-[72px]')}
</HeroStat>
{top1 ? (
<button type="button" onClick={() => open({ type: 'gak', indexId: top1.index_id })} aria-label={`오늘의 1위 ${top1.name} ${top1.score}점, 계산 근거 보기`} className="col-span-2 flex cursor-pointer items-center gap-2 border-t border-current/10 px-3.5 py-2.5 text-left">
<HeroGak line={gakLine} load={feedLoad} />
<span className="shrink-0 text-[13px] font-bold opacity-75" aria-hidden="true">
근거 보기 ›
</span>
</button>
) : (
<div className="col-span-2 flex items-center gap-2 border-t border-current/10 px-3.5 py-2.5">
<HeroGak line={gakLine} load={feedLoad} />
</div>
)}
</div>
{hero?.bubble && (
<div className="relative z-[3] flex items-end gap-2">
<Ic name={who} alt={who === 'rabbit' ? '토끼' : '곰'} className="w-[50px] drop-shadow-[0_8px_10px_rgb(40_48_74/0.15)]" />
<span className="mb-3 rounded-[20px_20px_20px_6px] bg-white px-3.5 py-[9px] font-jua text-base text-(--ink) shadow-[0_8px_16px_rgb(40_48_74/0.1)]">{hero.bubble}</span>
</div>
)}
</div>
)
}
function HeroStat({ icon, label, className, children }: { icon: string; label: string; className?: string; children: ReactNode }) {
return (
<div className={cx('flex min-w-0 items-center gap-2.5 px-3.5 py-2.5', className)}>
<Ic name={icon} className="w-7 shrink-0" />
<div className="min-w-0">
<small className="block text-[13px] font-bold opacity-75">{label}</small>
<b className="block truncate font-jua text-base font-normal">{children}</b>
</div>
</div>
)
}
function HeroGak({ line, load }: { line: string | null; load: Load }) {
return (
<span className="min-w-0 flex-1">
<small className="block text-[13px] font-bold opacity-75">오늘의 각</small>
<b className="block truncate font-jua text-base font-normal">{heroVal(load, line, 'w-[128px]')}</b>
</span>
)
}
function Stories({ items }: { items: TopIndex[] }) {
const { open } = useSheet()
return (
@@ -162,6 +178,36 @@ function Stories({ items }: { items: TopIndex[] }) {
)
}
function PostsSkel() {
return (
<>
<PostCardSkel />
<PostCardSkel />
</>
)
}
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}>
@@ -172,16 +218,14 @@ function Band({ tone, title, sub, to, children }: { tone: 1 | 2 | 3; title: stri
}
function EventsBand({ events }: { events: BandEvent[] }) {
const { region } = useRegion()
return (
<Band tone={1} title={`이번 주 ${sidoOf(region.name)} 행사`} sub="날씨까지 같이 보고 골라요" to="/week">
<Band tone={1} title="이번 주 가까운 행사" sub="30km 안 · 날씨까지 같이 보고 골라요" to="/week">
<Rail>
{events.map((e, i) => (
<Link key={e.event_id} to="/week" className="w-[200px] overflow-hidden rounded-[22px] bg-white shadow-[inset_0_-5px_0_var(--shade),0_8px_16px_rgb(40_48_74/0.06)]">
<span className={cx('relative grid h-[116px] place-items-center', `b-bg-${cardBg(e.icon, i)}`)}>
<Thumb image={e.image} icon={e.icon} credit={e.image_credit} className={cx('h-[116px]', `b-bg-${cardBg(e.icon, i)}`)} iconClassName="w-[76px]">
<span className={cx('absolute top-2.5 left-2.5 rounded-full px-2 py-[3px] text-[11.5px] font-extrabold text-white', e.status_label === '진행 중' ? 'bg-[#1f9d62]' : 'bg-(--orange)')}>{e.status_label}</span>
<Ic name={e.icon} className="w-[76px]" />
</span>
</Thumb>
<span className="block px-3 pt-2.5 pb-3">
<b className="block font-jua text-[16.5px] leading-snug font-normal">{e.name}</b>
</span>
@@ -241,6 +285,7 @@ export function TodayPage() {
const stories = f?.stories ?? []
const bands = f?.bands
const nowAt = f?.hero?.now_at
const load = loadOf(feed)
// 디자인대로 3·6·9번째 글 뒤에 띠를 넣고, 글이 모자라면 남은 띠는 맨 뒤에 붙인다
const bandAt: [number, ReactNode][] = [
@@ -250,12 +295,17 @@ export function TodayPage() {
]
return (
<section aria-label="오늘">
<Hero hero={f?.hero} today={today.data} />
<section aria-label="오늘" aria-busy={load === 'loading'} className={cx('transition-opacity', feed.isPlaceholderData && 'opacity-60')}>
<Hero hero={f?.hero} today={today.data} feedLoad={load} todayLoad={loadOf(today)} />
<Sec title="오늘의 각" sub="누르면 계산 근거를 보여 줘요" more={{ to: '/gak' }} />
{stories.length ? <Stories items={stories} /> : <StateBox loading={feed.isPending} error={feed.error} onRetry={() => feed.refetch()} empty="오늘 계산된 각이 없어요." />}
<StateBox loading={feed.isPending} error={feed.error} onRetry={() => feed.refetch()} empty={feed.isSuccess && !posts.length ? '오늘 올라온 글이 아직 없어요.' : undefined} />
{/* 실패 안내는 여기 한 번만, 각 줄 스켈레톤과 같은 크기로 */}
{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" />}
<div>
{load === 'loading' && <PostsSkel />}
{/* 글이 없거나 못 받아도 스켈레톤 두 장 자리는 그대로 둔다 */}
{load !== 'loading' && !posts.length && (
<StateBox load="ready" empty={load === 'ready' ? '오늘 올라온 글이 아직 없어요.' : '글을 불러오지 못했어요.'} hold={<PostsSkel />} className="inset-x-3 top-3.5 bottom-auto" />
)}
{posts.map((p, i) => (
<Fragment key={p.post_id}>
<PostCard post={p} />
+226 -27
View File
@@ -1,11 +1,137 @@
import { useState } from 'react'
import { useQuery } from '@tanstack/react-query'
import { getWeekOptions, listEventsOptions, listPlacesOptions } from '../api/client/@tanstack/react-query.gen'
import { getWeekOptions, getWeekRankingOptions, listEventsOptions, listPlacesOptions } from '../api/client/@tanstack/react-query.gen'
import { cx } from '../lib/utils'
import { cardBg, dateRange, sidoOf } from './lib'
import { cardBg, dateRange, loadOf, shortDay, sidoOf } from './lib'
import { useRegion } from './regionContext'
import { useSheet } from './sheetContext'
import { Ic, Rail, Sec, StateBox } from './ui'
import { Chips, Ic, Rail, Sec, Skel, SkelRail, StateBox, Thumb } from './ui'
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' }
@@ -22,11 +148,21 @@ export function WeekPage() {
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
@@ -34,10 +170,10 @@ export function WeekPage() {
}
return (
<section aria-label="주말·행사">
<section aria-label="주말·행사" aria-busy={weekLoad === 'loading'}>
<Sec title="열흘 날씨" sub="날짜를 누르면 그날 추천이 바뀌어요" />
{days.length ? (
<div className="flex snap-x gap-1 overflow-x-auto px-3 pt-3 [scrollbar-width:none]" role="group" aria-label="날짜 고르기">
<div className={cx('flex snap-x gap-1 overflow-x-auto px-3 pt-3 transition-opacity [scrollbar-width:none]', week.isPlaceholderData && 'opacity-60')} role="group" aria-label="날짜 고르기">
{days.map((d) => {
const on = d.day === sel?.day
const weekend = d.weekday === '토' || d.weekday === '일' || !!d.holiday
@@ -47,18 +183,34 @@ export function WeekPage() {
type="button"
aria-pressed={on}
onClick={() => setPicked(d.day)}
className={cx('flex w-[calc((100%-24px)/7)] shrink-0 cursor-pointer snap-start flex-col items-center gap-0.5 rounded-[18px] pt-[9px] pb-2 text-xs font-extrabold', on ? 'bg-(--ink) text-white' : cx('bg-white shadow-[inset_0_-4px_0_var(--shade)]', weekend ? 'text-[#d6457a]' : 'text-(--ink2)'))}
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)}°` : '-'}</b>
<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>
)
})}
</div>
) : weekLoad === 'loading' ? (
<>
<DaysSkel />
<PickSkel />
</>
) : (
<StateBox loading={week.isPending} error={week.error} onRetry={() => week.refetch()} empty="날씨가 아직 없어요." />
<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">
@@ -66,27 +218,27 @@ export function WeekPage() {
<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>
<p className="mt-2 font-jua text-base text-(--ink)">{sel.pick}</p>
</div>
</div>
)}
{areas.length > 0 && (
{(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 })} className="rounded-full bg-white px-3 py-[7px] font-bold text-(--ink) shadow-[inset_0_-3px_0_var(--shade)]">
<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 ? '비가 와서 실내 명소를 먼저' : '맑아서 야외 명소를 먼저'} 보여 줘요` : undefined} className="pt-3" />
<Sec title="날씨 맞춤 데이트 명소" sub={sel ? `${sel.weekday}요일은 ${rainy ? '비가 와서 실내 명소를 먼저' : sel.icon === 'sun' ? '맑아서 야외 명소를 먼저' : '비 소식이 없어 야외 명소를 먼저'} 보여 줘요` : weekLoad === 'loading' ? <Skel className="w-56" /> : '날씨에 맞춰 골라 보여 줘요'} className="pt-3" />
{placeList.length ? (
<Rail>
<Rail className={cx('transition-opacity', places.isPlaceholderData && 'opacity-60')}>
{placeList.map((p, i) => (
<div key={p.place_id} className="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)]">
<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]" />
@@ -105,33 +257,80 @@ export function WeekPage() {
</div>
))}
</Rail>
) : placeLoad === 'loading' ? (
<PlacesSkel />
) : (
<StateBox loading={places.isPending && !!sel} error={places.error} onRetry={() => places.refetch()} empty={`${sido} 데이트 명소는 아직 준비 중이에요.`} />
<StateBox load={placeLoad} onRetry={() => places.refetch()} empty={sel ? `${sido} 데이트 명소는 아직 준비 중이에요.` : '날씨를 불러오면 명소를 골라 드려요.'} hold={<PlacesSkel />} className="inset-x-3 top-3 bottom-1" />
)}
<Sec title={`${sido} 축제·행사`} sub="앞으로 30일 · 그날 날씨까지 같이 봐요" className="pt-[18px]" />
<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="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)]">
<span className={cx('grid h-[84px] place-items-center rounded-2xl', `b-bg-${cardBg(e.icon, i)}`)}>
<Ic name={e.icon} className="w-14" />
</span>
<span>
<span className={cx('mr-1.5 inline-block rounded-full px-[7px] py-0.5 align-[2px] text-[11px] font-extrabold', e.status === 'live' ? 'bg-[#dff5ea] text-[#1f7a4f]' : 'bg-[#ffe8dc] text-[#c2471b]')}>{e.status_label}</span>
<b className="inline font-jua text-[17px] leading-snug font-normal">{e.name}</b>
<small className="block text-[12.5px] font-semibold text-(--ink2)">
{dateRange(e.start_date, e.end_date)} · {e.place_name}
<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].filter(Boolean).join(' · ')}
{!e.is_confirmed && ' · 일정 확인 필요'}
</small>
{e.fit && <span className={cx('mt-[5px] inline-block text-xs font-extrabold', e.fit.includes('비') ? 'text-[#d6457a]' : 'text-[#1f9d62]')}>{e.fit}</span>}
<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 loading={events.isPending} error={events.error} onRetry={() => events.refetch()} empty="이 지역 행사는 아직 없어요. 다른 지역을 골라 보세요." />
<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>
)
}
+3 -2
View File
@@ -17,9 +17,10 @@ export function AuthProvider({ children }: { children: ReactNode }) {
const queryClient = useQueryClient()
const me = useQuery({ ...meOptions(), enabled: !!token })
// 로그인·로그아웃하면 좋아요·저장 여부가 달라지니 받아 둔 데이터를 다시 받는다
// 로그인·로그아웃하면 좋아요 여부가 달라지니 받아 둔 데이터를 다시 받는다
useEffect(() => subscribeAuth((reason) => reason === 'change' && queryClient.invalidateQueries()), [queryClient])
const api = useMemo(() => ({ loggedIn: !!token, me: (token && me.data?.me) || null, logout }), [token, me.data])
const mePending = !!token && me.isPending
const api = useMemo(() => ({ loggedIn: !!token, me: (token && me.data?.me) || null, mePending, logout }), [token, me.data, mePending])
return <AuthContext value={api}>{children}</AuthContext>
}
+2 -1
View File
@@ -1,7 +1,8 @@
import { createContext, use } from 'react'
import type { Me } from '../api/client/types.gen'
export type AuthApi = { loggedIn: boolean; me: Me | null; logout: () => void }
/** mePending: 토큰은 있고 내 정보를 받는 중 (아바타 자리를 비워 두지 않으려고) */
export type AuthApi = { loggedIn: boolean; me: Me | null; mePending: boolean; logout: () => void }
export const AuthContext = createContext<AuthApi | null>(null)
+131 -83
View File
@@ -11,6 +11,8 @@
--orange-deep: #d4552a;
--rain: #4f97e3;
--heart: #ff3b5c;
/* 스켈레톤: 그 자리 글자색을 옅게 써서 낮·밤·노을 어디서든 보이게 */
--skel: color-mix(in oklab, currentColor 13%, transparent);
font-size: 15px;
line-height: 1.5;
}
@@ -140,99 +142,80 @@
}
}
/* 히어로 시간대 배경 */
/* 히어로 시간대 배경 (글자 대비 AA: 저녁은 위쪽을 깊은 보라로) */
.b-hero {
transition: background 0.6s;
}
.b-hero[data-t='morning'] {
background: linear-gradient(180deg, #ffd9b8, #ffe9d4 40%, #dff0ff);
background: linear-gradient(180deg, #ffd9b8, #ffe9d4 45%, #dff0ff);
}
.b-hero[data-t='day'] {
background: linear-gradient(180deg, #9fd3ff, #cfe9ff 55%, #f1f8ff);
}
.b-hero[data-t='sunset'] {
background: linear-gradient(180deg, #8e7cf0, #f28aa0 48%, #ffc38a);
background: linear-gradient(180deg, #5d4fc4, #8b56b8 50%, #e27a8f);
color: #fff;
}
.b-hero[data-t='night'] {
background: linear-gradient(180deg, #141b3d, #27306a 60%, #3d3f86);
color: #fff;
}
.b-hero .b-stars {
opacity: 0;
transition: opacity 0.6s;
/* 시간대 미리보기: 한 줄 트랙, 고른 칸만 흰 알약 */
.b-seg {
background: rgb(255 255 255 / 0.45);
}
.b-hero[data-t='night'] .b-stars {
opacity: 1;
.b-hero:is([data-t='sunset'], [data-t='night']) .b-seg {
background: rgb(0 0 0 / 0.2);
}
.b-stat {
background: rgb(255 255 255 / 0.72);
color: var(--ink);
box-shadow: inset 0 -5px 0 rgb(217 229 244 / 0.9);
}
.b-hero[data-t='night'] .b-stat,
.b-hero[data-t='sunset'] .b-stat {
background: rgb(255 255 255 / 0.18);
color: #fff;
box-shadow: inset 0 -5px 0 rgb(255 255 255 / 0.12);
}
.b-orb-label {
text-shadow: 0 2px 0 rgb(255 255 255 / 0.7);
}
.b-hero[data-t='night'] .b-orb-label,
.b-hero[data-t='sunset'] .b-orb-label {
text-shadow: 0 2px 0 rgb(0 0 0 / 0.2);
.b-seg [aria-pressed='true'] {
background: #fff;
color: #28304a;
box-shadow: 0 1px 4px rgb(40 48 74 / 0.16);
}
.b-sun {
background: radial-gradient(circle at 34% 30%, #fff5cf, #ffc86e 30%, #ff8e4e 68%, #ee6436);
box-shadow:
inset -18px -24px 40px rgb(170 50 20 / 0.34),
inset 16px 18px 28px rgb(255 255 255 / 0.55),
0 30px 56px rgb(240 106 58 / 0.32);
/* 비·기온·오늘의 각 카드: 저녁도 밝은 카드라 진한 글자 */
.b-stat {
background: rgb(255 255 255 / 0.72);
color: #28304a;
box-shadow: inset 0 -4px 0 rgb(217 229 244 / 0.9);
}
.b-hero[data-t='sunset'] .b-stat {
background: rgb(255 255 255 / 0.88);
box-shadow: inset 0 -4px 0 rgb(255 255 255 / 0.4);
}
.b-hero[data-t='night'] .b-stat {
background: rgb(255 255 255 / 0.12);
color: #fff;
box-shadow: inset 0 -4px 0 rgb(255 255 255 / 0.08);
}
/* 히어로에서 유일하게 강조하는 장식: 점수를 담은 해(밤엔 달) */
.b-sun {
background: radial-gradient(circle at 34% 30%, #fff5cf, #ffc86e 34%, #ff9a58 72%, #f07a45);
box-shadow:
inset -12px -16px 28px rgb(170 50 20 / 0.28),
inset 10px 12px 20px rgb(255 255 255 / 0.55),
0 16px 36px rgb(240 106 58 / 0.3);
color: #28304a;
}
.b-hero[data-t='night'] .b-sun {
background: radial-gradient(circle at 34% 30%, #fff, #e7e3ff 35%, #b9b0f2 72%, #8f86d9);
color: #2b2a5c;
box-shadow:
inset -18px -24px 40px rgb(60 50 140 / 0.3),
inset 16px 18px 28px rgb(255 255 255 / 0.6),
0 0 60px rgb(190 180 255 / 0.45);
inset -12px -16px 28px rgb(60 50 140 / 0.26),
inset 10px 12px 20px rgb(255 255 255 / 0.6),
0 0 44px rgb(190 180 255 / 0.4);
}
.b-cloud {
position: absolute;
border-radius: 999px;
background: #fff;
box-shadow:
inset 0 -12px 18px rgb(160 190 230 / 0.45),
0 16px 28px rgb(40 70 120 / 0.13);
.b-bob {
--amp: 4px;
--tilt: 0deg;
animation: b-float 6s ease-in-out infinite;
}
.b-cloud::before,
.b-cloud::after {
content: '';
position: absolute;
border-radius: 999px;
background: #fff;
box-shadow: inset 0 -10px 16px rgb(160 190 230 / 0.35);
}
.b-cloud::before {
left: 16%;
top: -58%;
width: 46%;
aspect-ratio: 1;
}
.b-cloud::after {
left: 50%;
top: -36%;
width: 36%;
aspect-ratio: 1;
}
.b-hero[data-t='night'] .b-cloud,
.b-hero[data-t='night'] .b-cloud::before,
.b-hero[data-t='night'] .b-cloud::after {
background: #c9cdf0;
@media (prefers-reduced-motion: reduce) {
.b-bob {
animation: none;
}
}
/* 이야기 고리 */
@@ -423,19 +406,17 @@
}
.b-shoot {
position: absolute;
top: 14%;
left: 70%;
width: 90px;
width: var(--len, 90px);
height: 1.5px;
border-radius: 2px;
background: linear-gradient(90deg, rgb(255 255 255 / 0), #fff);
opacity: 0;
animation: b-shoot 14s ease-in 6s infinite;
animation: b-shoot var(--dur, 8s) ease-in var(--dl, 0s) infinite;
}
@keyframes b-shoot {
0%, 92% { opacity: 0; transform: rotate(-24deg) translateX(0); }
94% { opacity: 1; }
100% { opacity: 0; transform: rotate(-24deg) translateX(-220px); }
0%, 86% { opacity: 0; transform: rotate(-24deg) translateX(0); }
89% { opacity: 1; }
100% { opacity: 0; transform: rotate(-24deg) translateX(-240px); }
}
.b-paused * {
animation-play-state: paused !important;
@@ -467,18 +448,85 @@
border-color: rgb(255 255 255 / 0.08);
}
/* 밤: 하늘 위 글자는 밝게, 카드 안은 원래 색 */
/* ===== 밤: 화면 전체를 어두운 테마로 (글자 대비 WCAG AA 4.5:1 이상) ===== */
.b-app[data-t='night'] {
--ink: #f1f3ff;
--ink2: #bcc3ea;
--ink3: #a3abdc;
}
.b-app[data-t='night'] :is(article, .bg-white, [class*='bg-white/'], [class*='b-bg-'], .b-stat, .b-sheet) {
--ink: #28304a;
--ink2: #5a6380;
--ink3: #8a92aa;
--ink: #eef1ff;
--ink2: #c3c9ec;
--ink3: #a1a9db;
--line: rgb(255 255 255 / 0.1);
--page: #1a2150;
--shade: #141a42;
--orange: #ff8a57;
--heart: #ff6b85;
--card: #222a5c;
--chip: #2b3470;
--skel: color-mix(in oklab, currentColor 17%, transparent);
color-scheme: dark;
}
.b-app[data-t='night'] .b-tabbar {
--ink: #fff;
--ink3: #9aa2d4;
}
.b-app[data-t='night'] .bg-white {
background-color: var(--card);
}
.b-app[data-t='night'] [class*='bg-white/'] {
background-color: rgb(34 42 92 / 0.85);
}
.b-app[data-t='night'] :is([class*='bg-[#f'], [class*='bg-[#e'], [class*='bg-[#d'], [class*='bg-[#c'], [class*='bg-[linear-gradient']) {
background: var(--chip);
}
.b-app[data-t='night'] [class*='border-[#dfe5ee]'] {
border-color: rgb(255 255 255 / 0.12);
}
.b-app[data-t='night'] [class*='rgb(217_229_244'] {
box-shadow: inset 0 -5px 0 var(--shade);
}
.b-app[data-t='night'] .bg-\(--ink\) {
background-color: #4b56b5;
color: #fff;
}
.b-app[data-t='night'] .bg-\(--ink\) .text-\[\#ffb3c4\] {
color: #ffd0dc;
}
.b-app[data-t='night'] .text-\[\#28304a\] {
color: var(--ink);
}
.b-app[data-t='night'] :is(.text-\[\#1f9d62\], .text-\[\#1f7a4f\]) {
color: #4fd39a;
}
.b-app[data-t='night'] .text-\[\#d6457a\] {
color: #ff8db5;
}
.b-app[data-t='night'] .text-\[\#c2471b\] {
color: #ffab85;
}
.b-app[data-t='night'] .bg-\[\#dff5ea\] {
background: rgb(79 211 154 / 0.16);
}
.b-app[data-t='night'] .bg-\[\#ffe8dc\] {
background: rgb(255 138 87 / 0.16);
}
.b-app[data-t='night'] .b-bg-sky {
background: linear-gradient(180deg, #2a4384, #1f2c62);
}
.b-app[data-t='night'] .b-bg-butter {
background: linear-gradient(180deg, #4d4128, #2c2a3e);
}
.b-app[data-t='night'] .b-bg-peach {
background: linear-gradient(180deg, #553632, #2e2840);
}
.b-app[data-t='night'] .b-bg-mint {
background: linear-gradient(180deg, #1f4a45, #1d2d4a);
}
.b-app[data-t='night'] .b-bg-lilac {
background: linear-gradient(180deg, #3d3480, #262a5e);
}
.b-app[data-t='night'] .b-band-1 {
background: linear-gradient(180deg, rgb(255 160 110 / 0.12), rgb(255 255 255 / 0));
}
.b-app[data-t='night'] .b-band-2 {
background: linear-gradient(180deg, rgb(255 214 110 / 0.12), rgb(255 255 255 / 0));
}
.b-app[data-t='night'] .b-band-3 {
background: linear-gradient(180deg, rgb(110 230 180 / 0.12), rgb(255 255 255 / 0));
}
+20 -4
View File
@@ -3,8 +3,9 @@ import type { CSSProperties } from 'react'
const SHARED = new Set(['bear', 'bike', 'bronze', 'camping', 'carwash', 'chimaek', 'cloud', 'coldwind', 'delivery', 'dog', 'garden', 'glasses', 'gold', 'hiking', 'iced_hot', 'jjamppong', 'laundry', 'letter', 'makeup', 'makgeolli', 'maple', 'moon', 'muggy', 'naengmyeon', 'photo', 'picnic', 'rabbit', 'rain', 'running', 'silver', 'snow', 'stars', 'sun_cloud', 'sun', 'sunset', 'taxi', 'umbrella', 'vent', 'walk', 'yajang', 'baseball', 'study', 'netflix', 'chestnut', 'peanut', 'tangerine', 'sweet_potato', 'fallen_leaf', 'kimchi', 'apple'])
const OWN = new Set(['fireworks', 'bulb', 'calendar', 'thermo', 'sheaf'])
/** 아이콘 이름 → 파일 경로 (공용 public/icons, B 전용 public/b/icons) */
/** 아이콘 이름 → 파일 경로 (공용 public/icons, B 전용 public/b/icons). 'none'(데이터 없는 칸)은 그림 없음 */
export function iconSrc(name: string) {
if (name === 'none') return null
if (OWN.has(name)) return `/b/icons/${name}.png`
return `/icons/${SHARED.has(name) ? name : 'sun_cloud'}.png`
}
@@ -27,7 +28,7 @@ export const AVATAR_COLORS: Record<string, string> = { orange: '#ff8e4e', blue:
/** 오늘 기분 (백엔드 MOODS 와 같아야 한다) */
export const MOODS = [
['clear', '☀️', '맑음'],
['partly', '⛅', '구름조금'],
['partly', '⛅', '구름 조금'],
['cloudy', '☁️', '흐림'],
['rain', '🌧️', '비'],
['thunder', '⚡', '번개'],
@@ -53,12 +54,17 @@ export function kst(input: string | Date) {
const h12 = (h: number) => h % 12 || 12
/** 18:25 → "6:25" */
/** 18:25 → "18:25" (포스트·플랜과 같은 24시간제) */
export function clockShort(iso: string) {
const t = kst(iso)
return `${h12(t.h)}:${String(t.mi).padStart(2, '0')}`
return `${t.h}:${String(t.mi).padStart(2, '0')}`
}
const COMPASS = ['북', '북북동', '북동', '동북동', '동', '동남동', '남동', '남남동', '남', '남남서', '남서', '서남서', '서', '서북서', '북서', '북북서']
/** 방위각 → 16방위 이름. 263 → "서" */
export const compass = (deg: number) => COMPASS[Math.round(deg / 22.5) % 16]
/** 18:30 → "6시 반", 18:25 → "6시 25분" */
export function timeWords(iso: string) {
const t = kst(iso)
@@ -119,3 +125,13 @@ export const ARTICLE_CAT: Record<number, [string, string]> = { 1: ['계절 소
/** 읽을거리 한 줄 정보: "계절 소식 · 3분" */
export const articleMeta = (a: { category: number; read_minutes: number }) => `${ARTICLE_CAT[a.category]?.[0] ?? '읽을거리'} · ${a.read_minutes}분`
export type Load = 'loading' | 'error' | 'retrying' | 'ready'
type QueryLike = { data?: unknown; isPending: boolean; isError: boolean; isFetching: boolean; errorUpdateCount: number }
/** 데이터가 있으면 ready. 실패 뒤 다시 받는 중(retrying)은 처음 불러오기(loading)와 구분한다 */
export function loadOf(q: QueryLike): Load {
if (q.data !== undefined) return 'ready'
if (q.isError) return q.isFetching ? 'retrying' : 'error'
return q.isFetching && q.errorUpdateCount > 0 ? 'retrying' : 'loading'
}
-18
View File
@@ -26,24 +26,6 @@ export function SendIcon({ className }: P) {
)
}
export function SaveIcon({ className }: P) {
return (
<svg viewBox="0 0 24 24" className={className} aria-hidden="true">
<path d="M19 21l-7-5-7 5V4.5A1.5 1.5 0 0 1 6.5 3h11A1.5 1.5 0 0 1 19 4.5z" />
</svg>
)
}
export function MoreIcon({ className }: P) {
return (
<svg viewBox="0 0 24 24" width="20" height="20" fill="currentColor" className={className} aria-hidden="true">
<circle cx="5" cy="12" r="1.8" />
<circle cx="12" cy="12" r="1.8" />
<circle cx="19" cy="12" r="1.8" />
</svg>
)
}
export function PinIcon({ className }: P) {
return (
<svg viewBox="0 0 24 24" {...line} strokeWidth="2.2" className={className} aria-hidden="true">
+76 -12
View File
@@ -1,13 +1,35 @@
import type { CSSProperties, ReactNode } from 'react'
import { useState, type CSSProperties, type ReactNode } from 'react'
import { Link } from 'react-router'
import { cx } from '../lib/utils'
import { useCarousel, type Carousel } from './carousel'
import { AVATAR_COLORS, iconSrc, moodEmoji } from './lib'
import { AVATAR_COLORS, iconSrc, moodEmoji, type Load } from './lib'
type IcProps = { name: string; className?: string; alt?: string; style?: CSSProperties }
export function Ic({ name, className, alt = '', style }: IcProps) {
return <img src={iconSrc(name)} alt={alt} className={cx('block', className)} style={style} decoding="async" />
const src = iconSrc(name)
if (!src) return <span aria-hidden className={cx('block', className)} style={style} />
return <img src={src} alt={alt} className={cx('block', className)} style={style} decoding="async" />
}
/** 사진 출처 표기 (공공누리 조건). 사진 위에서도 읽히게 반투명 배경. 위치는 className 으로 */
export function Credit({ text, className = 'right-1 bottom-1' }: { text: string; className?: string }) {
return <small className={cx('pointer-events-none absolute z-[1] rounded-[5px] bg-[rgb(16_20_34/0.5)] px-1 py-px text-[9px] leading-tight font-semibold whitespace-nowrap text-white', className)}>{text}</small>
}
type ThumbProps = { image?: string | null; icon: string; credit?: string | null; className?: string; iconClassName?: string; children?: ReactNode }
/** 사진이 있으면 사진(+출처), 없거나 못 불러오면 아이콘 */
export function Thumb({ image, icon, credit, className, iconClassName, children }: ThumbProps) {
const [failed, setFailed] = useState<string | null>(null)
const photo = image && image !== failed ? image : null
return (
<span className={cx('relative grid place-items-center overflow-hidden', className)}>
{photo ? <img src={photo} alt="" loading="lazy" decoding="async" onError={() => setFailed(photo)} className="absolute inset-0 size-full object-cover" /> : <Ic name={icon} className={iconClassName} />}
{photo && credit && <Credit text={credit} />}
{children}
</span>
)
}
type AvatarProps = { character: string; color?: string | null; mood?: string | null; size?: number; className?: string }
@@ -66,6 +88,15 @@ export function Arrows({ api, prev, next, className }: { api: Carousel; prev: bo
const STRIP = { align: 'start', dragFree: true, containScroll: 'trimSnaps' } as const
/** Rail 과 같은 틀(여백·간격)로 스켈레톤 칸을 늘어놓는다. 넘기기·화살표는 없음 */
export function SkelRail({ children, className }: { children: ReactNode; className?: string }) {
return (
<div className="overflow-hidden" aria-hidden="true">
<div className={cx('flex gap-2.5 px-4 pt-3 pb-1 *:shrink-0', className)}>{children}</div>
</div>
)
}
export function Rail({ children, className, label }: { children: ReactNode; className?: string; label?: string }) {
const { ref, api, prev, next } = useCarousel(STRIP)
return (
@@ -110,22 +141,55 @@ function ChipStrip({ children, label }: { children: ReactNode; label: string })
)
}
type StateProps = { loading?: boolean; error?: unknown; onRetry?: () => void; empty?: string; className?: string }
type SkelProps = { className?: string; shape?: boolean; style?: CSSProperties }
/** 불러오는 중·실패·빈 목록 안내 */
export function StateBox({ loading, error, onRetry, empty, className }: StateProps) {
const text = loading ? '불러오는 중이에요…' : error ? '정보를 불러오지 못했어요.' : empty
if (!text) return null
/**
* 불러오는 동안 자리만 잡는 막대. 기본은 글자 자리: 감싼 글자 요소 안에 넣으면 그 줄 높이(1lh)를 그대로 차지한다.
* shape 면 className 으로 준 크기의 블록(사진·동그라미 자리).
*/
export function Skel({ className, shape = false, style }: SkelProps) {
return (
<div className={cx('mx-3 mt-3 flex flex-col items-center gap-2 rounded-[22px] bg-white px-4 py-6 text-center text-[13.5px] font-semibold text-(--ink2) shadow-[inset_0_-5px_0_var(--shade)]', className)} role={error ? 'alert' : 'status'}>
<span
aria-hidden="true"
style={style}
className={cx('bg-(--skel) motion-safe:animate-pulse', shape ? 'block' : 'inline-block h-[1lh] max-w-full rounded-full bg-clip-content py-[0.22lh] align-top', className)}
/>
)
}
type StateProps = { load: Load; onRetry?: () => void; empty?: string; className?: string; hold?: ReactNode }
/**
* 실패·빈 목록 안내. 불러오는 중엔 그리지 않는다(그 자리는 스켈레톤).
* hold 에 스켈레톤을 주면 그 크기를 보이지 않게 깔고 안내를 그 위에 띄운다 — 로딩·실패·빈 상태의 자리 크기가 같다.
* 이때 className 은 안내 상자의 위치(스켈레톤 바깥 여백만큼 inset).
*/
export function StateBox({ load, onRetry, empty, className, hold }: StateProps) {
const failed = load === 'error' || load === 'retrying'
const text = failed ? '정보를 불러오지 못했어요.' : load === 'ready' ? empty : undefined
if (!text) return null
const box = (
<div
className={cx('flex flex-col items-center justify-center gap-2 rounded-[22px] bg-white px-4 py-6 text-center text-[13.5px] font-semibold text-(--ink2) shadow-[inset_0_-5px_0_var(--shade)]', hold ? cx('absolute', className ?? 'inset-x-3 top-3 bottom-0') : (className ?? 'mx-3 mt-3'))}
role={load === 'error' ? 'alert' : 'status'}
>
<span>{text}</span>
{error != null && onRetry && (
<button type="button" onClick={onRetry} className="cursor-pointer rounded-full bg-(--ink) px-4 py-1.5 text-[13px] font-bold text-white">
다시 시도
{failed && onRetry && (
<button type="button" onClick={onRetry} disabled={load === 'retrying'} className="cursor-pointer rounded-full bg-(--ink) px-4 py-1.5 text-[13px] font-bold text-white disabled:cursor-default disabled:opacity-60">
{load === 'retrying' ? '다시 불러오는 중…' : '다시 시도'}
</button>
)}
</div>
)
if (!hold) return box
return (
<div className="relative flow-root">
<div className="invisible" aria-hidden="true" inert>
{hold}
</div>
{box}
</div>
)
}
/** 줄 목록 (라벨 · 값) */
+1 -1
View File
@@ -16,4 +16,4 @@ export function slotAt(slots: WeatherSlot[], hour: number) {
return pick ?? slots[0]
}
export const deg = (v: number | null | undefined) => (v == null ? '-' : `${Math.round(v)}°`)
export const deg = (v: number | null | undefined) => (v == null ? '?°' : `${Math.round(v)}°`)