feat: 피드를 시간대별 카드로 다시 짜고 하늘 배경·내 캐릭터 추가, 다른 시안 정리

- 피드: 그날 카드 12장을 03:00에 한 번에 만들고, 시간대(아침·낮·저녁·밤, 저녁은 일몰 2시간 전부터)마다 순서를 바꾸고 조건이 맞는 카드만 켠다. 새 카드 우산·특보, 내일 미리보기, 한 문장·시(예시 seed). 흐린 날 노을은 한 줄 카드.
- 캐시를 feed:{구}:{시간대}로 나누고 시간대 경계·일몰·예보 갱신 때 만료해 새 카드가 늦게 보이던 문제를 고친다.
- 히어로는 오늘 1위 각만 보여 준다.
- 각 점수·노을 점수를 7일 지나면 지운다.
- 화면 전체 하늘 배경(시간대별 색, 느린 일렁임, 밤 별)과 화면 끝까지 이어지는 위·아래 바.
- 상단바 로그인 버튼, 내 정보 창(캐릭터 6종·배경색 6종·오늘 기분 8종·닉네임·로그아웃), PATCH /v1/auth/me, 댓글·상단바에 캐릭터·배경색·기분 표시. users.character·color·mood 칸 추가.
- 카드 슬라이드와 가로 줄을 Embla 카로셀로 바꿔 PC에서도 마우스로 끌어 넘기고 화살표로 넘긴다.
- 좋아요·저장을 받아 둔 피드 데이터에도 반영해 다른 탭에 다녀와도 유지되게 고치고, 좋아요 때 하트가 터지는 애니메이션을 넣는다.
- 보내기에서 게시물을 인스타 스토리 크기(1080×1920) 이미지로 공유하거나 내려받는다 (modern-screenshot).
- 창이 열려 있는 동안 뒤 페이지 스크롤을 잠근다.
- 시안 B 확정: 시안 A 아이콘(public/a)과 쓰지 않는 전역 스타일·글꼴 삭제.
- 문서: 데이터 흐름 지도(backend/docs/data-flow-map.html), 확정 시안(docs/시안B_확정.html), 피드 기획 v2, 호출량·DB 크기 추정, data-pipeline 갱신. 보고 폴더와 예전 시안 html 삭제.
This commit is contained in:
minaChoi committed 2026-10-02 15:47:20 +09:00
1 parent f8b47f064a
commit a9ddbaab3c
93 files changed
+2322 -2751

No files matched your search

+100 -44
View File
@@ -1,16 +1,17 @@
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 { 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 { cx } from '../lib/utils'
import { ago, cardBg, clockShort, fall } from './lib'
import { cardBg, clockShort, fall } from './lib'
import type { SlideBg } from './types'
import { deg } from './weatherText'
import { useMutation } from '@tanstack/react-query'
import { useMutation, useQueryClient, type QueryClient } 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'
import { useCarousel } from './carousel'
import { Arrows, Ic, Rows } from './ui'
const ACCOUNTS: Record<PostType, readonly [string, string]> = {
[PostType.WEATHER]: ['오늘 날씨', 'sun'],
@@ -20,6 +21,9 @@ const ACCOUNTS: Record<PostType, readonly [string, string]> = {
[PostType.EVENT]: ['행사', 'fireworks'],
[PostType.TIP]: ['날씨 상식', 'bulb'],
[PostType.WEEK]: ['주말 추천', 'calendar'],
[PostType.ALERT]: ['생활 알림', 'umbrella'],
[PostType.TOMORROW]: ['내일 미리보기', 'moon'],
[PostType.QUOTE]: ['오늘의 한 문장', 'letter'],
}
type Slide = HoursSlide | RowsSlide | GakSlide | SunsetSlide | WeekSlide
@@ -65,7 +69,7 @@ function Pic({ name, className }: { name: string; className?: string }) {
)
}
const slideBase = 'relative flex h-full w-full shrink-0 snap-start flex-col px-5 py-[22px]'
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()
@@ -161,60 +165,91 @@ function SlideView({ slide, bg }: { slide: Slide; bg: SlideBg }) {
type PostProps = { post: PostData }
const HEART = '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'
// 좋아요 때 튀어 나가는 작은 하트: [x, y, 회전, 색]
const BURST: [number, number, number, string][] = [
[-86, -60, -24, '#ff3b5c'],
[84, -66, 22, '#ff8e4e'],
[-104, 18, -40, '#ffc86e'],
[102, 24, 36, '#ff3b5c'],
[-48, -104, -8, '#ff8aa0'],
[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,
)
}
/** 한 줄 카드 (흐린 날 노을처럼 큰 그림이 필요 없는 소식) */
function LineCard({ post }: PostProps) {
const [account, avatar] = ACCOUNTS[post.post_type]
return (
<article className="mx-3 mt-3.5 flex items-center gap-3 rounded-[22px] bg-white px-4 py-3 shadow-[inset_0_-4px_0_var(--shade)]" aria-label={post.title}>
<Ic name={post.icon || avatar} className="w-10 shrink-0" />
<p className="m-0 min-w-0 text-sm">
<small className="block text-xs font-bold text-(--ink3)">{account}</small>
<b className="font-jua text-base font-normal">{post.title}</b> <span className="text-(--ink2)">{post.caption}</span>
</p>
</article>
)
}
/** 인스타식 게시물: 옆으로 넘기는 슬라이드, 두 번 눌러 좋아요 */
export function PostCard({ post }: PostProps) {
return post.size === 'line' ? <LineCard post={post} /> : <FullCard post={post} />
}
function FullCard({ 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 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 [index, setIndex] = useState(0)
const { ref: sliderRef, api: slider, prev: canPrev, next: canNext, index } = useCarousel({ align: 'start' })
const [pop, setPop] = 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 ?? [] } })
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)
// 화면을 먼저 바꾸고, 실패하면 되돌린다
const setLike = (next: boolean) => {
const setLike = (on: boolean) => {
if (!loggedIn) return open({ type: 'login' })
if (next === liked) return
setLiked(next)
setLikeCount((n) => n + (next ? 1 : -1))
;(next ? like : unlike).mutate(
if (on === liked) return
if (on) setPop((p) => p + 1)
patch({ liked: on, like_count: likeCount + (on ? 1 : -1) })
;(on ? 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))
},
onSuccess: (res) => patch({ liked: res.liked ?? on, ...(res.like_count != null ? { like_count: res.like_count } : {}) }),
onError: () => patch({ liked, like_count: likeCount }),
},
)
}
const toggleSave = () => {
if (!loggedIn) return open({ type: 'login' })
const next = !saved
setSaved(next)
;(next ? save : unsave).mutate(
const on = !saved
patch({ saved: on })
;(on ? save : unsave).mutate(
{ path: { post_id: post.post_id } },
{
onSuccess: (res) => {
if (res.saved != null) setSaved(res.saved)
},
onError: () => setSaved(!next),
onSuccess: (res) => patch({ saved: res.saved ?? on }),
onError: () => patch({ saved }),
},
)
}
@@ -223,8 +258,8 @@ export function PostCard({ post }: PostProps) {
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)
if (liked && loggedIn) setPop((p) => p + 1)
else setLike(true)
}
lastTap.current = now
}
@@ -245,27 +280,48 @@ export function PostCard({ post }: PostProps) {
<MoreIcon />
</button>
</div>
<div className="relative aspect-[4/5] overflow-hidden" onClick={onTap}>
<div ref={cardRef} 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">
<span data-noshot 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))}
ref={sliderRef}
className="h-full overflow-hidden"
tabIndex={n > 1 ? 0 : undefined}
aria-label={n > 1 ? `슬라이드 ${n}장, 옆으로 넘겨 보세요` : undefined}
role={n > 1 ? 'region' : undefined}
onKeyDown={(e) => {
if (e.key === 'ArrowLeft') slider?.scrollPrev()
if (e.key === 'ArrowRight') slider?.scrollNext()
}}
>
{post.slides.map((s, i) => (
<SlideView key={i} slide={s} bg={bgs[i]} />
))}
<div className="flex h-full">
{post.slides.map((s, i) => (
<SlideView key={i} slide={s} bg={bgs[i]} />
))}
</div>
</div>
{n > 1 && <Arrows api={slider} prev={canPrev} next={canNext} />}
{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 key={pop} data-noshot className="pointer-events-none absolute inset-0 z-[4] grid place-items-center" aria-hidden="true">
{BURST.map((b, k) => (
<svg key={k} className="b-like-bit absolute w-5" style={{ '--dx': `${b[0]}px`, '--dy': `${b[1]}px`, '--rot': `${b[2]}deg` } as CSSProperties} viewBox="0 0 24 24" fill={b[3]}>
<path d={HEART} />
</svg>
))}
<svg className="b-heart-pop w-28 opacity-0 drop-shadow-[0_10px_18px_rgb(255_59_92/0.45)]" viewBox="0 0 24 24" fill="url(#b-like-grad)">
<defs>
<linearGradient id="b-like-grad" x1="0" y1="0" x2="0" y2="1">
<stop offset="0" stopColor="#ff8aa0" />
<stop offset="1" stopColor="#ff3b5c" />
</linearGradient>
</defs>
<path d={HEART} />
</svg>
<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>
)}
</div>
<div className="relative flex items-center gap-3.5 px-3 pt-2.5 pb-1 [&_svg]:size-[26px] [&_svg]:stroke-[1.9]">
@@ -297,7 +353,7 @@ export function PostCard({ post }: PostProps) {
<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>
<p className="px-3 pt-1 pb-3 text-[11.5px] font-semibold text-(--ink3)">오늘</p>
</article>
)
}