feat: main 병합 + 인스타 올리기 API(/v1/card/{id}/instagram), 관리자 올릴 곳 선택(로컬·킹서버), 만든 카드 화면
This commit is contained in:
commit
572b2a05c8
188 files changed
+16605
-741
No files matched your search
+108
-11
@@ -1,6 +1,6 @@
|
||||
import { useEffect, useRef, useState, type CSSProperties, type MouseEvent, type ReactNode } from 'react'
|
||||
import { useEffect, useRef, useState, type CSSProperties, type MouseEvent, type ReactNode, type RefObject } from 'react'
|
||||
import { createPortal } from 'react-dom'
|
||||
import { PostType, SlotTone, type GakSlide, type HoursSlide, type ImageSlide, type PlanSlide, type PostData, type ResFeed, type RowsSlide, type SunsetSlide, type WeekSlide } from '../api/client/types.gen'
|
||||
import { PostType, SlotTone, type GakSlide, type HoursSlide, type ImageSlide, type PlanSlide, type PostData, type PostReaction, type ResFeed, type RowsSlide, type SunsetSlide, type WeekSlide } from '../api/client/types.gen'
|
||||
import { API_BASE_URL } from '../api/setup'
|
||||
import { cx } from '../lib/utils'
|
||||
import { cardBg, clockShort, fall } from './lib'
|
||||
@@ -8,7 +8,7 @@ import type { SlideBg } from './types'
|
||||
import { deg } from './weatherText'
|
||||
import { useMutation, useQueryClient, type QueryClient } from '@tanstack/react-query'
|
||||
import { likePostMutation, unlikePostMutation } from '../api/client/@tanstack/react-query.gen'
|
||||
import { useAuth } from './authContext'
|
||||
import { usePinnedLike, type PinnedKey } from './pinnedLike'
|
||||
import { useSheet } from './sheetContext'
|
||||
import { CommentIcon, HeartIcon, SendIcon } from './svg'
|
||||
import { useCarousel } from './carousel'
|
||||
@@ -30,6 +30,11 @@ const ACCOUNTS: Record<PostType, readonly [string, string]> = {
|
||||
[PostType.DAY_TRIP]: ['당일치기', 'picnic'],
|
||||
[PostType.MOON]: ['오늘 밤 달', 'moon'],
|
||||
[PostType.UV]: ['자외선', 'glasses'],
|
||||
[PostType.HERO]: ['오늘 날씨', 'sun'],
|
||||
[PostType.TODAY_GAK]: ['오늘의 각', 'rabbit'],
|
||||
[PostType.FOLIAGE]: ['단풍 지도', 'maple'],
|
||||
[PostType.EVENTS_BAND]: ['이번 주 가까운 행사', 'fireworks'],
|
||||
[PostType.SEASON_BAND]: ['이번 주 계절 이야기', 'fallen_leaf'],
|
||||
[PostType.CARD]: ['날씨각 카드', 'stars'],
|
||||
}
|
||||
|
||||
@@ -55,6 +60,22 @@ function slideBg(post: PostData, slide: Slide): SlideBg {
|
||||
|
||||
const DARK = new Set<SlideBg>(['dusk', 'night'])
|
||||
|
||||
// 그림 배경이 있는 각(code)과 장 수. 여러 장이면 글마다 돌려 쓴다
|
||||
const BG_IMAGES: Record<string, number> = { bike: 4, picnic: 1, hiking: 1, camping: 1, stars: 1, walk: 1, hangang: 1 }
|
||||
const EVENT_BG_N = 4
|
||||
|
||||
function bgImage(name: string, n: number, seed: number): CSSProperties {
|
||||
const file = n > 1 ? `${name}-${'abcd'[seed % n]}` : name
|
||||
return { backgroundImage: `url(/post-bg/${file}.webp)`, backgroundSize: 'cover', backgroundPosition: 'center' }
|
||||
}
|
||||
|
||||
/** 그림 배경: 각은 각마다, 사진 없는 행사는 행사용. 없으면 색 배경만 */
|
||||
function slideImage(post: PostData, slide: Slide): CSSProperties | undefined {
|
||||
if (slide.kind === 'gak') return BG_IMAGES[slide.code] ? bgImage(slide.code, BG_IMAGES[slide.code], post.post_id) : undefined
|
||||
if (post.post_type === PostType.EVENT && slide.kind === 'rows' && !slide.image) return bgImage('event', EVENT_BG_N, post.post_id)
|
||||
return undefined
|
||||
}
|
||||
|
||||
function Lines({ text }: { text: string }) {
|
||||
return text.split('\n').map((t, i) => (
|
||||
<span key={i}>
|
||||
@@ -75,14 +96,14 @@ function Big({ children, className }: { children: ReactNode; className?: string
|
||||
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)]" />
|
||||
<Ic name={name} className="b-bob w-full drop-shadow-[0_16px_18px_rgb(40_48_74/0.18)]" />
|
||||
</span>
|
||||
)
|
||||
}
|
||||
|
||||
const slideBase = 'relative flex h-full w-full shrink-0 flex-col px-5 py-[22px]'
|
||||
|
||||
function SlideView({ slide, bg }: { slide: Slide; bg: SlideBg }) {
|
||||
function SlideView({ slide, bg, img }: { slide: Slide; bg: SlideBg; img?: CSSProperties }) {
|
||||
const { open } = useSheet()
|
||||
if (slide.kind === 'hours') {
|
||||
const temps = slide.hours.flatMap((h) => (h.temp_c == null ? [] : [h.temp_c]))
|
||||
@@ -117,10 +138,17 @@ function SlideView({ slide, bg }: { slide: Slide; bg: SlideBg }) {
|
||||
}
|
||||
if (slide.kind === 'gak')
|
||||
return (
|
||||
<div className={cx(slideBase, `b-bg-${bg}`)}>
|
||||
<div className={cx(slideBase, `b-bg-${bg}`)} style={img}>
|
||||
<Eyebrow>오늘의 각 · {slide.rank}위</Eyebrow>
|
||||
<Big>{slide.line}</Big>
|
||||
<Pic name={slide.code} />
|
||||
{slide.say && <p className="relative z-[1] m-0 mt-2.5 w-[56%] rounded-[16px] rounded-tl-[4px] bg-white/80 px-3 py-2 text-[14px] leading-snug font-bold">{slide.say}</p>}
|
||||
{/* 점수 근거: 비중 큰 조건과 지금 값. 오른쪽 아이콘과 겹치지 않게 왼쪽 반만 */}
|
||||
{!!slide.rows?.length && (
|
||||
<div className="relative z-[1] mt-2 w-[56%] rounded-[16px] bg-white/70 px-3 text-[14px] [&_b]:text-[15px] [&>div>div]:py-1.5 [&>div]:mt-0">
|
||||
<Rows rows={slide.rows} />
|
||||
</div>
|
||||
)}
|
||||
<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>
|
||||
@@ -229,7 +257,7 @@ function SlideView({ slide, bg }: { slide: Slide; bg: SlideBg }) {
|
||||
</div>
|
||||
)
|
||||
return (
|
||||
<div className={cx(slideBase, `b-bg-${bg}`)}>
|
||||
<div className={cx(slideBase, `b-bg-${bg}`)} style={img}>
|
||||
<Eyebrow className={DARK.has(bg) ? 'opacity-85' : undefined}>{slide.eyebrow}</Eyebrow>
|
||||
<Big className="relative z-[1]">
|
||||
<Lines text={slide.line} />
|
||||
@@ -318,7 +346,6 @@ export function PostCardSkel() {
|
||||
|
||||
function FullCard({ post }: PostProps) {
|
||||
const { open } = useSheet()
|
||||
const { loggedIn } = useAuth()
|
||||
const liked = !!post.liked
|
||||
const likeCount = post.like_count
|
||||
const queryClient = useQueryClient()
|
||||
@@ -344,7 +371,6 @@ function FullCard({ post }: PostProps) {
|
||||
|
||||
// 화면을 먼저 바꾸고, 실패하면 되돌린다 (서버는 실패도 200 + result.success=false 로 준다)
|
||||
const setLike = (on: boolean) => {
|
||||
if (!loggedIn) return open({ type: 'login' })
|
||||
if (on === liked || like.isPending || unlike.isPending) return
|
||||
if (on) setPop((p) => p + 1)
|
||||
setLikeFailed(0)
|
||||
@@ -369,7 +395,7 @@ function FullCard({ post }: PostProps) {
|
||||
if ((e.target as HTMLElement).closest('button')) return
|
||||
const now = Date.now()
|
||||
if (now - lastTap.current < 320) {
|
||||
if (liked && loggedIn) setPop((p) => p + 1)
|
||||
if (liked) setPop((p) => p + 1)
|
||||
else setLike(true)
|
||||
}
|
||||
lastTap.current = now
|
||||
@@ -407,7 +433,7 @@ function FullCard({ post }: PostProps) {
|
||||
>
|
||||
<div ref={trackRef} className="flex h-full">
|
||||
{post.slides.map((s, i) => (
|
||||
<SlideView key={i} slide={s} bg={bgs[i]} />
|
||||
<SlideView key={i} slide={s} bg={bgs[i]} img={slideImage(post, s)} />
|
||||
))}
|
||||
</div>
|
||||
</div>
|
||||
@@ -463,3 +489,74 @@ function FullCard({ post }: PostProps) {
|
||||
</article>
|
||||
)
|
||||
}
|
||||
|
||||
type FrameProps = {
|
||||
title: string
|
||||
account: string
|
||||
avatar: string
|
||||
caption?: ReactNode
|
||||
more?: ReactNode
|
||||
shot?: RefObject<HTMLDivElement | null>
|
||||
pinned?: { key: PinnedKey; post?: PostReaction | null }
|
||||
children: ReactNode
|
||||
}
|
||||
|
||||
/** 피드 글과 같은 틀(계정 줄·본문·보내기 줄)에 날씨·각 같은 화면 조각을 담는다. 보내기는 shot(공유용 틀)이 있으면 그것을, 없으면 본문을 이미지로 */
|
||||
export function PostFrame({ title, account, avatar, caption, more, shot, pinned, children }: FrameProps) {
|
||||
const { open } = useSheet()
|
||||
const bodyRef = useRef<HTMLDivElement>(null)
|
||||
const like = usePinnedLike(pinned?.key ?? 'gak_post', pinned?.post)
|
||||
const postId = pinned?.post?.post_id
|
||||
const share = () => {
|
||||
const el = shot?.current ?? bodyRef.current
|
||||
if (el) open({ type: 'share', share: { title, slides: [el] } })
|
||||
}
|
||||
return (
|
||||
<article className="mt-3.5 border-y border-(--line) bg-white first:mt-1" aria-label={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)">{account}</small>
|
||||
</span>
|
||||
</div>
|
||||
<div ref={bodyRef}>{children}</div>
|
||||
<div className="flex items-center gap-3.5 px-3 pt-2.5 pb-1 [&_svg]:size-[26px] [&_svg]:stroke-[1.9]">
|
||||
{postId != null && (
|
||||
<>
|
||||
<button type="button" onClick={like.toggle} aria-pressed={like.liked} aria-label="좋아요" className={cx('relative grid size-7 cursor-pointer place-items-center', TAP44)}>
|
||||
<HeartIcon className={like.liked ? 'fill-(--heart) stroke-(--heart)' : 'fill-none stroke-(--ink)'} />
|
||||
</button>
|
||||
<button type="button" onClick={() => open({ type: 'comments', postId })} aria-label="댓글 보기" className={cx('relative grid size-7 cursor-pointer place-items-center', TAP44)}>
|
||||
<CommentIcon className="fill-none stroke-(--ink) [stroke-linejoin:round]" />
|
||||
</button>
|
||||
</>
|
||||
)}
|
||||
<button type="button" onClick={share} aria-label="보내기" className={cx('relative grid size-7 cursor-pointer place-items-center', TAP44)}>
|
||||
<SendIcon className="fill-none stroke-(--ink) [stroke-linecap:round] [stroke-linejoin:round]" />
|
||||
</button>
|
||||
{more && <span className="ml-auto text-[13px] font-bold text-(--ink2)">{more}</span>}
|
||||
</div>
|
||||
{postId != null && (
|
||||
<p className="px-3 py-0.5 text-sm font-extrabold">
|
||||
{like.failed ? <span className="text-(--heart)" role="alert">좋아요를 반영하지 못했어요. 다시 해 주세요.</span> : `좋아요 ${like.count.toLocaleString()}개`}
|
||||
</p>
|
||||
)}
|
||||
{caption && (
|
||||
<p className="px-3 pt-0.5 pb-3 text-sm">
|
||||
<b className="mr-[5px] font-extrabold">날씨각</b>
|
||||
{caption}
|
||||
</p>
|
||||
)}
|
||||
{postId != null && (
|
||||
<button type="button" onClick={() => open({ type: 'comments', postId })} className="block cursor-pointer px-3 pb-3 text-sm font-semibold text-(--ink3)">
|
||||
{pinned?.post?.comment_count ? `댓글 ${pinned.post.comment_count}개 모두 보기` : '첫 댓글 남기기'}
|
||||
</button>
|
||||
)}
|
||||
</article>
|
||||
)
|
||||
}
|
||||
Reference in new issue
Block a user