feat: 카드뉴스 포스트(관리자 admin/, /v1/card API, 피드 이미지 슬라이드), 인스타 홍보 기획 문서
This commit is contained in:
1 parent
96cbd19c61
commit
739a8c59eb
107 files changed
+17684
-19
No files matched your search
@@ -0,0 +1,39 @@
|
||||
import { useEffect, useRef, useState } from 'react'
|
||||
import { useSearchParams } from 'react-router'
|
||||
import { BASE_REGION, useCardData } from '../cards/data'
|
||||
import { decodeCopy, whenPainted } from '../cards/share'
|
||||
import { templateById } from '../cards/templates'
|
||||
|
||||
/** 카드 한 장만 1080×1350으로. 다 그려지면 <html data-ready="1"> */
|
||||
export function RenderPage() {
|
||||
const [params] = useSearchParams()
|
||||
const template = templateById(params.get('template') ?? '')
|
||||
const slideNo = Number(params.get('slide') ?? '1')
|
||||
const { data, error } = useCardData(params.get('region') ?? BASE_REGION)
|
||||
const ref = useRef<HTMLDivElement>(null)
|
||||
const [ready, setReady] = useState(false)
|
||||
|
||||
useEffect(() => {
|
||||
if (!data || !ref.current) return
|
||||
let alive = true
|
||||
whenPainted(ref.current).then(() => alive && setReady(true))
|
||||
return () => {
|
||||
alive = false
|
||||
}
|
||||
}, [data])
|
||||
|
||||
useEffect(() => {
|
||||
document.documentElement.dataset.ready = ready ? '1' : ''
|
||||
}, [ready])
|
||||
|
||||
if (!template) return <p>template 값이 없거나 틀렸어요: today · ootd · tarot</p>
|
||||
if (error) return <p>날씨각 API에서 데이터를 받지 못했어요: {String(error)}</p>
|
||||
if (!data) return null
|
||||
const copy = { ...template.defaults(data), ...decodeCopy(params.get('copy')) }
|
||||
const slides = template.slides(data, copy)
|
||||
return (
|
||||
<div ref={ref} style={{ width: 1080, height: 1350 }}>
|
||||
{slides[slideNo - 1] ?? <p>{slides.length}장까지 있어요</p>}
|
||||
</div>
|
||||
)
|
||||
}
|
||||
Reference in new issue
Block a user