feat: 시안 B 화면을 기본 화면으로, Hey API로 백엔드 연결

- 예전 화면(/, /a)과 목업 데이터를 지우고 시안 B 를 / 로
- @hey-api/openapi-ts 로 타입·TanStack Query 함수 생성, 토큰·401 갱신 처리
- 공유는 기본 공유창, 없으면 링크 복사

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
minaChoiandClaude Opus 5.5 committed 2026-10-02 11:32:22 +09:00
1 parent e134295ce5
commit f8b47f064a
147 files changed
+12350

No files matched your search

+303
View File
@@ -0,0 +1,303 @@
import { useRef, useState, type MouseEvent, type ReactNode } from 'react'
import { PostType, SlotTone, type GakSlide, type HoursSlide, type PostData, type RowsSlide, type SunsetSlide, type WeekSlide } from '../api/client/types.gen'
import { cx } from '../lib/utils'
import { ago, cardBg, clockShort, fall } from './lib'
import type { SlideBg } from './types'
import { deg } from './weatherText'
import { useMutation } from '@tanstack/react-query'
import { likePostMutation, savePostMutation, unlikePostMutation, unsavePostMutation } 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 { Ic, Rows } 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.TIP]: ['날씨 상식', 'bulb'],
[PostType.WEEK]: ['주말 추천', 'calendar'],
}
type Slide = HoursSlide | RowsSlide | GakSlide | SunsetSlide | WeekSlide
const GAK_BG: SlideBg[] = ['butter', 'peach', 'lilac']
const ROW_ICON_BG: Record<string, SlideBg> = { umbrella: 'lilac', vent: 'mint', sunset: 'peach', thermo: 'sky', maple: 'peach' }
/** 배경색은 API에 없어 글 종류·아이콘으로 고른다 */
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 === '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'
return ROW_ICON_BG[slide.icon] ?? cardBg(slide.icon, post.post_id)
}
const DARK = new Set<SlideBg>(['dusk', 'night'])
function Lines({ text }: { text: string }) {
return text.split('\n').map((t, i) => (
<span key={i}>
{i > 0 && <br />}
{t}
</span>
))
}
function Eyebrow({ children, className }: { children: ReactNode; className?: string }) {
return <p className={cx('m-0 text-[13px] font-extrabold opacity-75', className)}>{children}</p>
}
function Big({ children, className }: { children: ReactNode; className?: string }) {
return <p className={cx('mt-1.5 font-jua text-[29px] leading-tight', className)}>{children}</p>
}
function Pic({ name, className }: { name: string; className?: string }) {
return (
<span className={cx('b-fall pointer-events-none absolute top-[30%] right-3.5 w-[42%]', className)} style={fall('.1s', '5s')}>
<Ic name={name} className="w-full drop-shadow-[0_16px_18px_rgb(40_48_74/0.18)]" />
</span>
)
}
const slideBase = 'relative flex h-full w-full shrink-0 snap-start flex-col px-5 py-[22px]'
function SlideView({ slide, bg }: { slide: Slide; bg: SlideBg }) {
const { open } = useSheet()
if (slide.kind === 'hours')
return (
<div className={cx(slideBase, 'b-bg-sky')}>
<Eyebrow>{slide.eyebrow}</Eyebrow>
<Big>
<Lines text={slide.line} />
</Big>
<div className="mt-3.5 grid flex-1 grid-cols-4 gap-2">
{slide.hours.map((h) => (
<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)',
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)]',
)}
>
<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>
</div>
))}
</div>
</div>
)
if (slide.kind === 'gak')
return (
<div className={cx(slideBase, `b-bg-${bg}`)}>
<Eyebrow>오늘의 각 · {slide.rank}위</Eyebrow>
<Big>{slide.line}</Big>
<Pic name={slide.code} />
<b className="mt-auto font-bagel text-[82px] leading-[0.9] font-normal text-(--orange)">{slide.score}</b>
<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>
<Big>
<Lines text={slide.line} />
</Big>
<b className="mt-2 font-bagel text-[62px] leading-[0.9] font-normal">{slide.score}</b>
<div className="mt-3 flex flex-1 flex-col gap-2">
{slide.cuts.map((c, i) => (
<div key={c.kind} className={cx('b-skyline relative flex-1 overflow-hidden rounded-2xl px-3 py-2 font-bagel text-[21px] text-white', `b-cut-${Math.min(i + 1, 3)}`)}>
<span className="relative z-[1]">
{clockShort(c.at)}
<small className="ml-2 font-jua text-sm">{c.label}</small>
</span>
</div>
))}
</div>
</div>
)
if (slide.kind === 'week')
return (
<div className={cx(slideBase, 'b-bg-mint')}>
<Eyebrow>{slide.eyebrow}</Eyebrow>
<Big>
<Lines text={slide.line} />
</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">
{d.weekday} {d.day.split('-').slice(1).map(Number).join('.')}
</b>
<small className="text-[12.5px] font-bold text-(--ink2)">{d.text}</small>
</div>
))}
</div>
</div>
)
return (
<div className={cx(slideBase, `b-bg-${bg}`)}>
<Eyebrow className={DARK.has(bg) ? 'opacity-85' : undefined}>{slide.eyebrow}</Eyebrow>
<Big className="relative z-[1]">
<Lines text={slide.line} />
</Big>
<Pic name={slide.icon} className="w-[36%]" />
<Rows rows={slide.rows ?? []} dark={DARK.has(bg)} />
</div>
)
}
type PostProps = { post: PostData }
/** 인스타식 게시물: 옆으로 넘기는 슬라이드, 두 번 눌러 좋아요 */
export function PostCard({ post }: PostProps) {
const { open } = useSheet()
const { region } = useRegion()
const { loggedIn } = useAuth()
const [liked, setLiked] = useState(!!post.liked)
const [likeCount, setLikeCount] = useState(post.like_count)
const [saved, setSaved] = useState(!!post.saved)
const like = useMutation(likePostMutation())
const unlike = useMutation(unlikePostMutation())
const save = useMutation(savePostMutation())
const unsave = useMutation(unsavePostMutation())
const [index, setIndex] = useState(0)
const [pop, setPop] = useState(0)
const lastTap = useRef(0)
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 ?? [] } })
const comments = () => open({ type: 'comments', postId: post.post_id })
// 화면을 먼저 바꾸고, 실패하면 되돌린다
const setLike = (next: boolean) => {
if (!loggedIn) return open({ type: 'login' })
if (next === liked) return
setLiked(next)
setLikeCount((n) => n + (next ? 1 : -1))
;(next ? like : unlike).mutate(
{ path: { post_id: post.post_id } },
{
onSuccess: (res) => {
if (res.liked != null) setLiked(res.liked)
if (res.like_count != null) setLikeCount(res.like_count)
},
onError: () => {
setLiked(!next)
setLikeCount((n) => n + (next ? -1 : 1))
},
},
)
}
const toggleSave = () => {
if (!loggedIn) return open({ type: 'login' })
const next = !saved
setSaved(next)
;(next ? save : unsave).mutate(
{ path: { post_id: post.post_id } },
{
onSuccess: (res) => {
if (res.saved != null) setSaved(res.saved)
},
onError: () => setSaved(!next),
},
)
}
const onTap = (e: MouseEvent<HTMLDivElement>) => {
if ((e.target as HTMLElement).closest('button')) return
const now = Date.now()
if (now - lastTap.current < 320) {
setLike(true)
if (loggedIn) setPop((p) => p + 1)
}
lastTap.current = now
}
return (
<article className="mt-3.5 border-y border-(--line) bg-white" aria-label={post.title}>
<div className="flex items-center gap-2.5 px-3 py-2.5">
<span className="b-ring size-[34px] shrink-0 rounded-full p-0.5">
<i className="grid size-full place-items-center rounded-full bg-white">
<Ic name={avatar} className="w-[22px]" />
</i>
</span>
<span>
<b className="block text-sm leading-tight font-extrabold">날씨각</b>
<small className="text-xs font-semibold text-(--ink2)">{accountName}</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 className="relative aspect-[4/5] overflow-hidden" onClick={onTap}>
{n > 1 && (
<span className="absolute top-3 right-3 z-[2] rounded-full bg-[rgb(30_36_56/0.55)] px-[9px] py-[3px] text-xs font-extrabold text-white" aria-hidden="true">
{index + 1}/{n}
</span>
)}
<div
className="b-noscroll flex h-full snap-x snap-mandatory overflow-x-auto"
onScroll={(e) => setIndex(Math.round(e.currentTarget.scrollLeft / e.currentTarget.clientWidth))}
tabIndex={n > 1 ? 0 : undefined}
aria-label={n > 1 ? `슬라이드 ${n}장, 옆으로 넘겨 보세요` : undefined}
role={n > 1 ? 'region' : undefined}
>
{post.slides.map((s, i) => (
<SlideView key={i} slide={s} bg={bgs[i]} />
))}
</div>
{pop > 0 && (
<svg key={pop} className="b-heart-pop pointer-events-none absolute top-1/2 left-1/2 z-[4] -mt-12 -ml-12 w-24 opacity-0" viewBox="0 0 24 24" fill="#fff" aria-hidden="true">
<path d="M12 20.5s-8-4.9-8-11A4.6 4.6 0 0 1 12 6.8a4.6 4.6 0 0 1 8 2.7c0 6.1-8 11-8 11z" />
</svg>
)}
</div>
<div className="relative 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>
<button type="button" onClick={comments} aria-label="댓글 보기" className="grid size-7 cursor-pointer place-items-center">
<CommentIcon className="fill-none stroke-(--ink) [stroke-linejoin:round]" />
</button>
<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">
<b className="mr-[5px] font-extrabold">날씨각</b>
{post.caption}
</p>
<button type="button" onClick={comments} className="block cursor-pointer px-3 pt-[3px] text-sm font-semibold text-(--ink3)">
{post.comment_count ? `댓글 ${post.comment_count}개 모두 보기` : '첫 댓글 남기기'}
</button>
<p className="px-3 pt-1 pb-3 text-[11.5px] font-semibold text-(--ink3)">{ago(post.published_at)}</p>
</article>
)
}