feat: 카드뉴스 포스트(관리자 admin/, /v1/card API, 피드 이미지 슬라이드), 인스타 홍보 기획 문서

This commit is contained in:
minaChoi committed 2026-10-23 15:38:07 +09:00
1 parent 96cbd19c61
commit 739a8c59eb
107 files changed
+17684 -19

No files matched your search

+105
View File
@@ -0,0 +1,105 @@
import { useQuery, useQueryClient } from '@tanstack/react-query'
import { useState } from 'react'
import { API_BASE_URL } from '../api/setup'
type Card = { card_id: number; template: string; topic?: string; title: string; status: 1 | 2 | 3; post_id?: number; created_at: string; published_at?: string; image_urls: string[] }
const STATUS: Record<Card['status'], [string, string]> = { 1: ['승인 대기', 'bg-warn-soft text-warn'], 2: ['올림', 'bg-rust-soft text-rust'], 3: ['반려', 'bg-rail text-muted'] }
const TEMPLATE: Record<string, string> = { tarot: '날씨 타로', ootd: '오늘의 코디' }
const when = (iso: string) => new Date(iso).toLocaleString('ko-KR', { month: 'numeric', day: 'numeric', hour: '2-digit', minute: '2-digit' })
/** 만든 카드가 쌓이는 곳. 날씨각 서버(card_set·card_image)에 저장된 것을 보여 주고, 다시 내려받거나 올린다 */
export function HistoryPage() {
const qc = useQueryClient()
const { data, error, isLoading } = useQuery({
queryKey: ['cards'],
queryFn: async () => {
const r = await fetch('/api/cards')
const body = await r.json()
if (!r.ok || body.result?.success === false) throw new Error(body.error ?? body.result?.desc ?? `HTTP ${r.status}`)
return body.items as Card[]
},
})
const [busy, setBusy] = useState<number | null>(null)
const act = async (id: number, what: 'publish' | 'reject') => {
setBusy(id)
try {
const r = await fetch(`/api/cards/${id}/${what}`, { method: 'POST' })
if (!r.ok) throw new Error((await r.json()).error)
await qc.invalidateQueries({ queryKey: ['cards'] })
} catch (e) {
console.error(e)
window.alert(`처리하지 못했어요: ${e instanceof Error ? e.message : String(e)}`)
} finally {
setBusy(null)
}
}
return (
<div className="mx-auto flex max-w-[1440px] flex-col gap-5 px-4 py-5 sm:px-6">
<header className="flex flex-col gap-0.5">
<h1 className="text-[20px] font-bold tracking-[-0.02em]">만든 카드</h1>
<p className="text-[13px] text-muted">'지금 올리기'나 '승인 대기로 저장'을 누른 카드가 날씨각 서버에 쌓여요. 장마다 JPEG로 다시 내려받을 수 있어요.</p>
</header>
{error && (
<div role="alert" className="rounded-xl border border-bad/30 bg-bad-soft px-5 py-4 text-[14px] text-bad">
목록을 받지 못했어요: {String(error instanceof Error ? error.message : error)}
</div>
)}
{isLoading && <div className="h-40 animate-pulse rounded-2xl bg-rail" aria-busy="true" />}
{data?.length === 0 && <p className="rounded-2xl border border-dashed border-line bg-panel px-5 py-10 text-center text-[14px] text-muted">아직 저장한 카드가 없어요.</p>}
<ul className="m-0 flex list-none flex-col gap-3 p-0">
{data?.map((c) => {
const [label, tone] = STATUS[c.status]
return (
<li key={c.card_id} className="grid gap-4 rounded-2xl border border-line bg-panel p-4 md:grid-cols-[minmax(0,1fr)_auto]">
<div className="flex min-w-0 flex-col gap-3">
<div className="flex flex-wrap items-center gap-2 text-[13px]">
<span className={`rounded-full px-2 py-0.5 text-[12px] font-bold ${tone}`}>{label}</span>
<b className="text-[15px]">{c.title}</b>
<span className="text-muted">
{TEMPLATE[c.template] ?? c.template}
{c.topic ? ` · ${c.topic}` : ''} · 카드 {c.card_id}
{c.post_id ? ` · 포스트 ${c.post_id}` : ''}
</span>
<span className="text-muted">만든 때 {when(c.created_at)}{c.published_at ? ` · 올린 때 ${when(c.published_at)}` : ''}</span>
</div>
<ol className="m-0 flex list-none gap-2 overflow-x-auto p-0.5">
{c.image_urls.map((u, i) => (
<li key={u} className="shrink-0">
<a href={`${API_BASE_URL}${u}`} download={`card-${c.card_id}-${i + 1}.jpg`} target="_blank" rel="noreferrer" title={`${i + 1}장 내려받기`} className="block overflow-hidden rounded-md outline-offset-2 hover:outline-2 hover:outline-ink">
<img src={`${API_BASE_URL}${u}`} alt={`${c.title} ${i + 1}장`} loading="lazy" className="h-[135px] w-[108px] object-cover" />
</a>
</li>
))}
</ol>
</div>
<div className="flex shrink-0 flex-col gap-2 md:w-40">
<a
href={`${API_BASE_URL}${c.image_urls[0] ?? ''}`}
download={`card-${c.card_id}-1.jpg`}
target="_blank"
rel="noreferrer"
className="rounded-lg border border-line px-3 py-2 text-center text-[13px] font-bold text-ink hover:bg-rail"
>
이미지 열기
</a>
{c.status === 1 && (
<>
<button onClick={() => act(c.card_id, 'publish')} disabled={busy === c.card_id} className="rounded-lg bg-ink px-3 py-2 text-[13px] font-bold text-white hover:opacity-90 disabled:opacity-40">
오늘 피드에 올리기
</button>
<button onClick={() => act(c.card_id, 'reject')} disabled={busy === c.card_id} className="rounded-lg px-3 py-2 text-[13px] font-semibold text-muted hover:bg-rail disabled:opacity-40">
반려
</button>
</>
)}
</div>
</li>
)
})}
</ul>
</div>
)
}