chore: main 병합 — 로그인 없이 댓글·좋아요, 구글 로그인만, 동네 이야기·카드뉴스 등 (차단 표 user_block 하나로 합침, 익명 댓글도 신고 가능)

This commit is contained in:
minaChoi committed 2026-10-26 10:00:40 +09:00
commit dba34675c8
408 files changed
+36377 -725

No files matched your search

+115 -12
View File
@@ -1,6 +1,7 @@
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 PlanSlide, type PostData, type ResFeed, type RowsSlide, type SunsetSlide, type WeekSlide } from '@nalssigak/shared/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 '@nalssigak/shared/api/client/types.gen'
import { API_BASE_URL } from '../api/setup'
import { cx } from '../lib/utils'
import { cardBg, clockShort } from '@nalssigak/shared/lib'
import { fall } from './lib'
@@ -8,7 +9,7 @@ import type { SlideBg } from '@nalssigak/shared/lib/types'
import { deg } from '@nalssigak/shared/lib/weatherText'
import { useMutation, useQueryClient, type QueryClient } from '@tanstack/react-query'
import { likePostMutation, unlikePostMutation } from '@nalssigak/shared/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,9 +31,15 @@ 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'],
}
type Slide = HoursSlide | RowsSlide | GakSlide | SunsetSlide | WeekSlide | PlanSlide
type Slide = HoursSlide | RowsSlide | GakSlide | SunsetSlide | WeekSlide | PlanSlide | ImageSlide
const GAK_BG: SlideBg[] = ['butter', 'peach', 'lilac']
const ROW_ICON_BG: Record<string, SlideBg> = { umbrella: 'lilac', vent: 'mint', sunset: 'peach', thermo: 'sky', maple: 'peach', moon: 'lilac', glasses: 'butter' }
@@ -44,6 +51,7 @@ function slideBg(post: PostData, slide: Slide): SlideBg {
if (slide.kind === 'week') return 'mint'
if (slide.kind === 'plan') return slide.eyebrow.startsWith('일') ? 'peach' : 'butter'
if (slide.kind === 'gak') return GAK_BG[post.post_id % GAK_BG.length]
if (slide.kind === 'image') return 'sky'
if (post.post_type === PostType.EVENT) return 'night'
if (post.post_type === PostType.TIP) return 'sky'
if (post.post_type === PostType.AIR) return slide.icon === 'vent' ? 'mint' : 'lilac'
@@ -53,6 +61,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}>
@@ -73,14 +97,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]))
@@ -115,10 +139,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>
@@ -210,6 +241,9 @@ function SlideView({ slide, bg }: { slide: Slide; bg: SlideBg }) {
</div>
)
}
// 카드뉴스: 관리자가 만든 4:5 이미지 한 장 (/v1/card/... 는 API 서버 경로)
if (slide.kind === 'image')
return <img src={slide.url.startsWith('/') ? `${API_BASE_URL}${slide.url}` : slide.url} alt={slide.alt ?? ''} className="h-full w-full shrink-0 object-cover" loading="lazy" draggable={false} />
if (slide.kind === 'rows' && slide.image)
return (
<div className={'relative flex h-full w-full shrink-0 flex-col justify-end bg-cover bg-center text-white'} style={{ backgroundImage: `url(${slide.image})` }}>
@@ -224,7 +258,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} />
@@ -313,7 +347,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()
@@ -339,7 +372,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)
@@ -364,7 +396,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
@@ -402,7 +434,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>
@@ -458,3 +490,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>
)
}