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

+202 -21
View File
@@ -13,17 +13,21 @@ import {
listCommentsOptions,
listRegionsOptions,
loginMutation,
meQueryKey,
signupMutation,
unlikeCommentMutation,
updateMeMutation,
} from '../api/client/@tanstack/react-query.gen'
import type { CommentData, Factor, ResAuth, ResIndexDetail } from '../api/client/types.gen'
import { cx } from '../lib/utils'
import { useAuth } from './authContext'
import { ago, ARTICLE_CAT, articleMeta, cardBg, dayLabel, shortDay } from './lib'
import { AVATAR_COLORS, ago, ARTICLE_CAT, articleMeta, cardBg, CHARACTERS, dayLabel, 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 { Ic, StateBox } from './ui'
import { Avatar, Ic, StateBox } from './ui'
export function SheetProvider({ children }: { children: ReactNode }) {
const [state, setState] = useState<SheetState>(null)
@@ -42,7 +46,7 @@ export function SheetProvider({ children }: { children: ReactNode }) {
)
}
const TITLES = { article: '읽을거리', seasonWeek: '이번 주 특집', share: '보내기', comments: '댓글', login: '로그인', region: '지역 바꾸기' } as const
const TITLES = { article: '읽을거리', seasonWeek: '이번 주 특집', share: '보내기', comments: '댓글', login: '로그인', me: '내 정보', region: '지역 바꾸기' } as const
/** 아래에서 올라오는 창: 네이티브 <dialog>라 ESC·포커스 가두기·포커스 되돌리기가 기본으로 된다 */
function SheetHost({ state, onClose }: { state: SheetState; onClose: () => void }) {
@@ -57,6 +61,18 @@ function SheetHost({ state, onClose }: { state: SheetState; onClose: () => void
if (!state && el.open) el.close()
}, [state])
// 창이 열려 있는 동안 뒤 페이지는 스크롤되지 않게 잠근다
const isOpen = state != null
useEffect(() => {
if (!isOpen) return
const root = document.documentElement
const before = root.style.overflow
root.style.overflow = 'hidden'
return () => {
root.style.overflow = before
}
}, [isOpen])
const title = !state ? '' : state.type === 'gak' ? gakTitle : state.type === 'article' ? articleTitle || TITLES.article : TITLES[state.type]
return (
@@ -84,6 +100,7 @@ function SheetHost({ state, onClose }: { state: SheetState; onClose: () => void
{state.type === 'share' && <ShareSheet share={state.share} />}
{state.type === 'comments' && <CommentsSheet postId={state.postId} />}
{state.type === 'login' && <LoginSheet onDone={onClose} />}
{state.type === 'me' && <MeSheet onDone={onClose} />}
{state.type === 'region' && <RegionSheet onDone={onClose} />}
</div>
)}
@@ -92,7 +109,7 @@ function SheetHost({ state, onClose }: { state: SheetState; onClose: () => void
}
function Body({ children, className }: { children: ReactNode; className?: string }) {
return <div className={cx('flex-1 overflow-auto px-4 pt-3.5 pb-[18px]', className)}>{children}</div>
return <div className={cx('flex-1 overflow-auto overscroll-contain px-4 pt-3.5 pb-[18px]', className)}>{children}</div>
}
/* ---------- 각 계산 근거 ---------- */
@@ -264,6 +281,52 @@ function ShareSheet({ share }: { share: SharePayload }) {
const url = window.location.origin
const text = `${msg} — ${share.title} · 날씨각`
const { kind } = useSky()
const [image, setImage] = useState<{ blob: Blob; src: string } | null>(null)
const [imageError, setImageError] = useState(false)
// 창이 열리면 카드를 스토리 크기 이미지로 미리 만들어 둔다
useEffect(() => {
if (!share.card) return
let src = ''
let alive = true
storyImage(share.card, { title: share.title, sub: `${region.name} · 날씨각`, sky: kind }).then(
(blob) => {
if (!alive) return
src = URL.createObjectURL(blob)
setImage({ blob, src })
},
(e: unknown) => {
console.error('[share] story image', e)
if (alive) setImageError(true)
},
)
return () => {
alive = false
if (src) URL.revokeObjectURL(src)
}
}, [share.card, share.title, region.name, kind])
// 휴대폰은 공유창에 이미지 파일을 넘기고(인스타 스토리·카톡 등), 안 되면 이미지를 내려받는다
const shareImage = () => {
if (!image) return
const file = new File([image.blob], 'nalssigak.png', { type: 'image/png' })
if (navigator.canShare?.({ files: [file] })) {
navigator.share({ files: [file], title: share.title, text }).then(
() => setToast('보냈어요'),
(e: unknown) => {
if (e instanceof DOMException && e.name === 'AbortError') return
setToast('공유하지 못했어요. 이미지를 내려받아 올려 주세요')
},
)
return
}
const a = document.createElement('a')
a.href = image.src
a.download = 'nalssigak.png'
a.click()
setToast('이미지를 내려받았어요. 인스타 스토리에 올려 보세요')
}
// 휴대폰 기본 공유창. 없거나 실패하면 링크 복사로 대신한다.
const shareNative = () => {
@@ -319,6 +382,18 @@ function ShareSheet({ share }: { share: SharePayload }) {
className="mt-1.5 w-full resize-none rounded-[14px] border border-[#dfe5ee] px-3 py-2.5"
/>
)}
{share.card && (
<div className="mt-3.5 flex items-center gap-3 rounded-[18px] bg-[#f3f6fb] p-2.5">
{image ? <img src={image.src} alt="공유할 이미지 미리보기" className="h-28 rounded-[10px] shadow-[0_4px_10px_rgb(40_48_74/0.15)]" /> : <span className="grid h-28 w-16 place-items-center rounded-[10px] bg-white text-xs font-bold text-(--ink3)">{imageError ? '실패' : '만드는 중'}</span>}
<div className="flex flex-1 flex-col gap-1.5">
<b className="text-sm font-extrabold">이미지로 보내기</b>
<small className="text-xs font-semibold text-(--ink2)">인스타 스토리 크기(9:16)로 만들어요</small>
<button type="button" onClick={shareImage} disabled={!image} className="cursor-pointer rounded-[14px] bg-(--orange) py-2.5 font-jua text-[15px] text-white shadow-[inset_0_-4px_0_var(--orange-deep)] disabled:opacity-50">
이미지 공유하기
</button>
</div>
</div>
)}
<div className="mt-3.5 grid grid-cols-2 gap-2">
<button type="button" onClick={shareNative} className="cursor-pointer rounded-[16px] bg-(--orange-deep) py-3 font-jua text-base text-white">
공유하기
@@ -335,10 +410,9 @@ function ShareSheet({ share }: { share: SharePayload }) {
}
/* ---------- 댓글 ---------- */
const AV_COLORS = ['#ff8e4e', '#4f97e3', '#1f9d62', '#7a5cd6', '#d6457a', '#c2471b']
const EMOJIS = ['☀️', '🌂', '🍻', '🌇', '😍', '👍']
function CommentRow({ c, index, postId }: { c: CommentData; index: number; postId: number }) {
function CommentRow({ c, postId }: { c: CommentData; postId: number }) {
const { region } = useRegion()
const { loggedIn } = useAuth()
const { open } = useSheet()
@@ -382,9 +456,7 @@ function CommentRow({ c, index, postId }: { c: CommentData; index: number; postI
return (
<div className="grid grid-cols-[34px_1fr_24px] items-start gap-2.5 py-2">
<span className="grid size-[34px] place-items-center rounded-full text-[13px] font-extrabold text-white" style={{ background: AV_COLORS[(c.nickname.charCodeAt(0) + index) % AV_COLORS.length] }} aria-hidden="true">
{c.nickname[0]}
</span>
<Avatar character={c.character} color={c.color} mood={c.mood} />
<div>
<p className="m-0 text-sm">
<b className="mr-1.5 font-extrabold">{c.nickname}</b>
@@ -442,7 +514,7 @@ function CommentsSheet({ postId }: { postId: number }) {
<>
<Body>
{comments.length ? (
comments.map((c, k) => <CommentRow key={c.comment_id} c={c} index={k} postId={postId} />)
comments.map((c) => <CommentRow key={c.comment_id} c={c} postId={postId} />)
) : list.isSuccess ? (
<p className="my-6 text-center font-semibold text-(--ink3)">
아직 댓글이 없어요.
@@ -490,7 +562,7 @@ const AUTH_ERRORS: Record<string, string> = {
}
function LoginSheet({ onDone }: { onDone: () => void }) {
const { me, logout } = useAuth()
const { me } = useAuth()
const [mode, setMode] = useState<'login' | 'signup'>('login')
const [loginId, setLoginId] = useState('')
const [password, setPassword] = useState('')
@@ -517,15 +589,7 @@ function LoginSheet({ onDone }: { onDone: () => void }) {
else signup.mutate({ body: { login_id: loginId.trim(), password, nickname: nickname.trim() } }, { onSuccess: done, onError: fail })
}
if (me)
return (
<Body className="flex flex-col gap-2.5 text-center">
<p className="text-sm font-semibold text-(--ink2)">{me.nickname}(으)로 로그인했어요.</p>
<button type="button" onClick={logout} className="cursor-pointer rounded-[14px] bg-[#f3f6fb] p-[13px] text-[15px] font-extrabold text-(--ink)">
로그아웃
</button>
</Body>
)
if (me) return <MeSheet onDone={onDone} />
const field = 'w-full rounded-[14px] border border-[#dfe5ee] bg-[#f7f9fc] px-3.5 py-3'
return (
@@ -545,7 +609,7 @@ function LoginSheet({ onDone }: { onDone: () => void }) {
))}
</div>
<input value={loginId} onChange={(e) => setLoginId(e.target.value)} autoComplete="username" required minLength={4} maxLength={20} placeholder="아이디" aria-label="아이디" className={field} />
<input value={password} onChange={(e) => setPassword(e.target.value)} type="password" autoComplete={mode === 'login' ? 'current-password' : 'new-password'} required minLength={8} placeholder="비밀번호 (8자 이상)" aria-label="비밀번호" className={field} />
<input value={password} onChange={(e) => setPassword(e.target.value)} type="password" autoComplete={mode === 'login' ? 'current-password' : 'new-password'} required minLength={mode === 'signup' ? 8 : undefined} placeholder={mode === 'signup' ? '비밀번호 (8자 이상)' : '비밀번호'} aria-label="비밀번호" className={field} />
{mode === 'signup' && <input value={nickname} onChange={(e) => setNickname(e.target.value)} required minLength={2} maxLength={12} placeholder="닉네임 (2~12자)" aria-label="닉네임" className={field} />}
<p className="min-h-5 text-center text-[13px] font-bold text-(--heart)" aria-live="polite">
{error}
@@ -561,6 +625,123 @@ function LoginSheet({ onDone }: { onDone: () => void }) {
)
}
/* ---------- 내 정보: 캐릭터·닉네임·로그아웃 ---------- */
function MeSheet({ onDone }: { onDone: () => void }) {
const { me, logout } = useAuth()
const queryClient = useQueryClient()
const update = useMutation(updateMeMutation())
const [nickname, setNickname] = useState(me?.nickname ?? '')
const [error, setError] = useState('')
if (!me) return null
const save = (body: { nickname?: string; character?: string; color?: string; mood?: string }) => {
setError('')
update.mutate(
{ body },
{
onSuccess: (res) => {
if (!res.result?.success) return setError(res.result?.desc === 'INVALID_INPUT' ? '닉네임은 2~12자로 써 주세요.' : '잠시 뒤에 다시 해 주세요.')
queryClient.setQueryData(meQueryKey(), res)
// 댓글에 보이는 내 캐릭터·닉네임도 바뀐다
queryClient.invalidateQueries({ predicate: (q) => (q.queryKey[0] as { _id?: string } | undefined)?._id === 'listComments' })
},
onError: () => setError('서버에 닿지 못했어요. 잠시 뒤에 다시 해 주세요.'),
},
)
}
return (
<Body className="flex flex-col gap-3">
<div className="flex flex-col items-center gap-1.5">
<Avatar character={me.character} color={me.color} mood={me.mood} size={64} />
<p className="m-0 text-center text-sm font-semibold text-(--ink2)">{me.login_id}(으)로 로그인했어요</p>
</div>
<section aria-label="내 캐릭터">
<h4 className="m-0 mb-2 text-sm font-extrabold">내 캐릭터</h4>
<div className="grid grid-cols-3 gap-2" role="radiogroup" aria-label="캐릭터 고르기">
{CHARACTERS.map(([key, label]) => (
<button
key={key}
type="button"
role="radio"
aria-checked={me.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)')}
>
<Ic name={key} className="w-12" />
{label}
</button>
))}
</div>
</section>
<section aria-label="배경색">
<h4 className="m-0 mb-2 text-sm font-extrabold">배경색</h4>
<div className="flex flex-wrap gap-2.5" role="radiogroup" aria-label="배경색 고르기">
{Object.entries(AVATAR_COLORS).map(([key, hex]) => (
<button
key={key}
type="button"
role="radio"
aria-checked={me.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)]')}
style={{ background: hex }}
/>
))}
</div>
</section>
<section aria-label="오늘 기분">
<h4 className="m-0 mb-2 text-sm font-extrabold">오늘 기분</h4>
<div className="grid grid-cols-4 gap-2" role="radiogroup" aria-label="오늘 기분 고르기">
{MOODS.map(([key, emoji, label]) => (
<button
key={key}
type="button"
role="radio"
aria-checked={me.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)')}
>
<span className="text-[22px] leading-none">{emoji}</span>
{label}
</button>
))}
</div>
<p className="m-0 mt-1.5 text-xs font-semibold text-(--ink3)">한 번 더 누르면 지워져요</p>
</section>
<form
className="flex items-center gap-2"
onSubmit={(e) => {
e.preventDefault()
save({ nickname: nickname.trim() })
}}
>
<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">
바꾸기
</button>
</form>
<p className="m-0 min-h-5 text-center text-[13px] font-bold text-(--heart)" aria-live="polite">
{error}
</p>
<button
type="button"
onClick={() => {
logout()
onDone()
}}
className="cursor-pointer rounded-[14px] bg-[#f3f6fb] p-[13px] text-[15px] font-extrabold text-(--ink)"
>
로그아웃
</button>
</Body>
)
}
/* ---------- 지역 ---------- */
const LOCATE_TEXT = { idle: '', locating: '위치를 찾는 중이에요…', denied: '위치 권한이 꺼져 있어요. 아래 목록에서 골라 주세요.', error: '위치를 찾지 못했어요. 아래 목록에서 골라 주세요.' } as const