Merge branch 'react-native' into release/1026-merge
# Conflicts: # backend/common/enums.py # backend/router/v1/auth/account.py # frontend/.dockerignore # frontend/package-lock.json # frontend/package.json # frontend/public/terms.html # frontend/src/api/client/index.ts # frontend/src/b/BLayout.tsx # frontend/src/b/Sheets.tsx # shared/api/client/@tanstack/react-query.gen.ts # shared/api/client/sdk.gen.ts # shared/api/client/types.gen.ts
This commit is contained in:
commit
5d18fa51fa
148 files changed
+21940
-4532
No files matched your search
+250
-28
@@ -1,10 +1,12 @@
|
||||
import { useInfiniteQuery, useMutation, useQuery, useQueryClient, type InfiniteData } from '@tanstack/react-query'
|
||||
import { useCallback, useDeferredValue, useEffect, useMemo, useRef, useState, type FormEvent, type ReactNode } from 'react'
|
||||
import regionPages from '../../seo/region.json'
|
||||
import { setTokens, subscribeAuth } from '../api/auth'
|
||||
import { clearTokens, setTokens, subscribeAuth } from '@nalssigak/shared/api/auth'
|
||||
import { SITE_URL } from '../api/setup'
|
||||
import {
|
||||
addCommentMutation,
|
||||
agreeTermsMutation,
|
||||
blockAuthorMutation,
|
||||
deleteCommentMutation,
|
||||
getArticleOptions,
|
||||
getFeedQueryKey,
|
||||
@@ -12,24 +14,30 @@ import {
|
||||
getSeasonWeekOptions,
|
||||
likeCommentMutation,
|
||||
listCommentsInfiniteOptions,
|
||||
listBlockedOptions,
|
||||
listBlockedQueryKey,
|
||||
listCommentsInfiniteQueryKey,
|
||||
listRegionsOptions,
|
||||
meQueryKey,
|
||||
reportCommentMutation,
|
||||
unblockMutation,
|
||||
unlikeCommentMutation,
|
||||
updateMeMutation,
|
||||
} from '../api/client/@tanstack/react-query.gen'
|
||||
import { AuthProvider, type CommentData, type Factor, type ResAuth, type ResCommentList, type ResIndexDetail } from '../api/client/types.gen'
|
||||
withdrawMutation,
|
||||
} from '@nalssigak/shared/api/client/@tanstack/react-query.gen'
|
||||
import { AuthProvider, ReportReason, type CommentData, type Factor, type ResAuth, type ResCommentList, type ResIndexDetail } from '@nalssigak/shared/api/client/types.gen'
|
||||
import { track } from '../lib/analytics'
|
||||
import { IS_TOSS, tossShare } from '../lib/platform'
|
||||
import { cx } from '../lib/utils'
|
||||
import { useAuth } from './authContext'
|
||||
import { ago, ARTICLE_CAT, articleMeta, AVATAR_COLORS, cardBg, CHARACTERS, dateRange, loadOf, MOODS, shortDay } from './lib'
|
||||
import { ago, articleMeta, AVATAR_COLORS, cardBg, CHARACTERS, dateRange, loadOf, MOODS, shortDay } from '@nalssigak/shared/lib'
|
||||
import { GoogleButton } from './googleLogin'
|
||||
import { useInstall, useInstallable } from './install'
|
||||
import { InstallSheet } from './installBanner'
|
||||
import { WeatherWhySheet } from './weatherWhy'
|
||||
import { ARTICLE_CAT } from './lib'
|
||||
import { MixSheet } from './myGak'
|
||||
import { ownPage, useRegion } from './regionContext'
|
||||
import { WeatherWhySheet } from './weatherWhy'
|
||||
import { useSky } from './skyContext'
|
||||
import { SHARE_SIZES, shareImage, type ShareSize } from './storyImage'
|
||||
import { SheetContext, useSheet, type SharePayload, type SheetState } from './sheetContext'
|
||||
@@ -642,8 +650,88 @@ function ShareSheet({ share }: { share: SharePayload }) {
|
||||
/* ---------- 댓글 ---------- */
|
||||
const NOT_FOUND = 3001 // 서버 ErrorType.NOT_FOUND
|
||||
const EMOJIS = ['☀️', '🌂', '🍻', '🌇', '😍', '👍']
|
||||
const REPORT_REASONS = [
|
||||
[ReportReason.ABUSE, '욕설·비하'],
|
||||
[ReportReason.AD, '광고'],
|
||||
[ReportReason.PRIVACY, '개인정보 노출'],
|
||||
[ReportReason.OTHER, '기타'],
|
||||
] as const
|
||||
const isCommentList = (q: { queryKey: readonly unknown[] }) => (q.queryKey[0] as { _id?: string } | undefined)?._id === 'listComments'
|
||||
|
||||
function CommentRow({ c, postId }: { c: CommentData; postId: number }) {
|
||||
/** 남의 댓글: ⋯ → 신고하기(이유 고르기) / 이 사람 차단하기(한 번 더 묻기). 끝나면 목록을 다시 받아 그 댓글이 빠진다 */
|
||||
function CommentMenu({ c, postId, onNotice }: { c: CommentData; postId: number; onNotice: (text: string) => void }) {
|
||||
const { loggedIn } = useAuth()
|
||||
const { open } = useSheet()
|
||||
const queryClient = useQueryClient()
|
||||
const [step, setStep] = useState<'closed' | 'menu' | 'report' | 'block'>('closed')
|
||||
const [failed, setFailed] = useState(false)
|
||||
const report = useMutation(reportCommentMutation())
|
||||
const block = useMutation(blockAuthorMutation())
|
||||
const pending = report.isPending || block.isPending
|
||||
|
||||
const finish = (notice: string) => ({
|
||||
onSuccess: (res: { result?: { success?: boolean } }) => {
|
||||
if (!res.result?.success) return setFailed(true)
|
||||
setStep('closed')
|
||||
onNotice(notice)
|
||||
queryClient.invalidateQueries({ predicate: isCommentList })
|
||||
queryClient.invalidateQueries({ queryKey: listBlockedQueryKey() })
|
||||
},
|
||||
onError: () => setFailed(true),
|
||||
})
|
||||
const go = (next: typeof step) => {
|
||||
setFailed(false)
|
||||
if (next !== 'closed' && !loggedIn) return open({ type: 'login', then: { type: 'comments', postId } })
|
||||
setStep(next)
|
||||
}
|
||||
const btn = 'cursor-pointer rounded-[12px] bg-[#f3f6fb] px-3 py-2 text-[13px] font-extrabold text-(--ink) disabled:opacity-50'
|
||||
|
||||
return (
|
||||
<>
|
||||
<button type="button" onClick={() => go(step === 'closed' ? 'menu' : 'closed')} aria-expanded={step !== 'closed'} aria-label="댓글 메뉴" className="ml-1.5 cursor-pointer px-1 font-extrabold text-(--ink3)">
|
||||
⋯
|
||||
</button>
|
||||
{step !== 'closed' && (
|
||||
<span className="mt-2 flex flex-wrap items-center gap-1.5" role="group" aria-label="댓글 메뉴">
|
||||
{step === 'menu' && (
|
||||
<>
|
||||
<button type="button" className={btn} onClick={() => go('report')}>
|
||||
신고하기
|
||||
</button>
|
||||
<button type="button" className={btn} onClick={() => go('block')}>
|
||||
이 사람 차단하기
|
||||
</button>
|
||||
</>
|
||||
)}
|
||||
{step === 'report' &&
|
||||
REPORT_REASONS.map(([reason, label]) => (
|
||||
<button key={reason} type="button" disabled={pending} className={btn} onClick={() => report.mutate({ path: { comment_id: c.comment_id }, body: { reason } }, finish('신고했어요. 확인하고 조치할게요.'))}>
|
||||
{label}
|
||||
</button>
|
||||
))}
|
||||
{step === 'block' && (
|
||||
<>
|
||||
<span className="w-full text-[13px] font-bold text-(--ink)">{c.nickname}님 댓글을 더는 안 볼까요?</span>
|
||||
<button type="button" disabled={pending} className={cx(btn, 'bg-(--heart) text-white')} onClick={() => block.mutate({ path: { comment_id: c.comment_id } }, finish('차단했어요. 내 정보에서 풀 수 있어요.'))}>
|
||||
차단하기
|
||||
</button>
|
||||
<button type="button" disabled={pending} className={btn} onClick={() => go('closed')}>
|
||||
취소
|
||||
</button>
|
||||
</>
|
||||
)}
|
||||
{failed && (
|
||||
<span className="w-full text-[13px] font-bold text-(--heart)" role="alert">
|
||||
잠시 뒤에 다시 해 주세요.
|
||||
</span>
|
||||
)}
|
||||
</span>
|
||||
)}
|
||||
</>
|
||||
)
|
||||
}
|
||||
|
||||
function CommentRow({ c, postId, onNotice }: { c: CommentData; postId: number; onNotice: (text: string) => void }) {
|
||||
const { region } = useRegion()
|
||||
const queryClient = useQueryClient()
|
||||
const [liked, setLiked] = useState(c.liked)
|
||||
@@ -725,6 +813,7 @@ function CommentRow({ c, postId }: { c: CommentData; postId: number }) {
|
||||
</button>
|
||||
</>
|
||||
)}
|
||||
{!c.mine && <CommentMenu c={c} postId={postId} onNotice={onNotice} />}
|
||||
</small>
|
||||
</div>
|
||||
<button type="button" onClick={toggle} aria-pressed={liked} aria-label="댓글 좋아요" className={cx('relative cursor-pointer pt-1', TAP44)}>
|
||||
@@ -744,13 +833,21 @@ function CommentsSheet({ postId, draft }: { postId: number; draft?: string }) {
|
||||
getNextPageParam: (last) => last.next_cursor ?? undefined,
|
||||
})
|
||||
const add = useMutation(addCommentMutation())
|
||||
const agree = useMutation(agreeTermsMutation())
|
||||
const [addFailed, setAddFailed] = useState(false)
|
||||
const [askTerms, setAskTerms] = useState(false)
|
||||
const [notice, setNotice] = useState('')
|
||||
const [text, setText] = useState(draft ?? '')
|
||||
const inputRef = useRef<HTMLInputElement>(null)
|
||||
const comments = list.data?.pages.flatMap((p) => p.comments ?? []) ?? []
|
||||
|
||||
const submit = (e: FormEvent) => {
|
||||
e.preventDefault()
|
||||
useEffect(() => {
|
||||
if (!notice) return
|
||||
const t = setTimeout(() => setNotice(''), 3000)
|
||||
return () => clearTimeout(t)
|
||||
}, [notice])
|
||||
|
||||
const send = () => {
|
||||
const body = text.trim()
|
||||
if (!body || add.isPending) return
|
||||
setAddFailed(false)
|
||||
@@ -758,6 +855,7 @@ function CommentsSheet({ postId, draft }: { postId: number; draft?: string }) {
|
||||
{ path: { post_id: postId }, body: { body, region: region.code } },
|
||||
{
|
||||
onSuccess: (res) => {
|
||||
if (res.result?.desc === 'TERMS_REQUIRED') return setAskTerms(true)
|
||||
setAddFailed(!res.result?.success)
|
||||
if (!res.result?.success) return
|
||||
setText('')
|
||||
@@ -769,13 +867,35 @@ function CommentsSheet({ postId, draft }: { postId: number; draft?: string }) {
|
||||
)
|
||||
}
|
||||
|
||||
// 로그인했으면 약관에 동의해야 댓글을 쓸 수 있다. 동의하면 쓰던 댓글을 바로 올린다
|
||||
const submit = (e: FormEvent) => {
|
||||
e.preventDefault()
|
||||
if (me && !me.terms_agreed) return setAskTerms(true)
|
||||
send()
|
||||
}
|
||||
const agreeAndSend = () => {
|
||||
setAddFailed(false)
|
||||
agree.mutate(
|
||||
{},
|
||||
{
|
||||
onSuccess: (res) => {
|
||||
if (!res.result?.success) return setAddFailed(true)
|
||||
queryClient.setQueryData(meQueryKey(), res)
|
||||
setAskTerms(false)
|
||||
send()
|
||||
},
|
||||
onError: () => setAddFailed(true),
|
||||
},
|
||||
)
|
||||
}
|
||||
|
||||
return (
|
||||
<>
|
||||
<Body>
|
||||
{comments.length ? (
|
||||
<>
|
||||
{/* 다시 받은 좋아요 상태(로그인 바뀜 등)가 행에 반영되도록 key 에 넣는다 */}
|
||||
{comments.map((c) => <CommentRow key={`${c.comment_id}:${c.liked}:${c.like_count}`} c={c} postId={postId} />)}
|
||||
{comments.map((c) => <CommentRow key={`${c.comment_id}:${c.liked}:${c.like_count}`} c={c} postId={postId} onNotice={setNotice} />)}
|
||||
{list.hasNextPage && (
|
||||
<button type="button" onClick={() => list.fetchNextPage()} disabled={list.isFetchingNextPage} className="my-2 w-full cursor-pointer text-center text-sm font-bold text-(--ink3) disabled:opacity-50">
|
||||
{list.isFetchingNextPage ? '불러오는 중…' : '댓글 더 보기'}
|
||||
@@ -788,24 +908,38 @@ function CommentsSheet({ postId, draft }: { postId: number; draft?: string }) {
|
||||
<StateBox load={loadOf(list)} onRetry={() => list.refetch()} empty="아직 댓글이 없어요. 첫 댓글을 남겨 보세요." hold={<CommentsSkel />} className="inset-0" />
|
||||
)}
|
||||
</Body>
|
||||
<div className="flex justify-around pt-1 text-[22px]" role="group" aria-label="빠른 이모지">
|
||||
{EMOJIS.map((e) => (
|
||||
<button
|
||||
key={e}
|
||||
type="button"
|
||||
disabled={add.isPending}
|
||||
className="cursor-pointer disabled:opacity-40"
|
||||
onClick={() => {
|
||||
setText((t) => (t + e).slice(0, 60))
|
||||
inputRef.current?.focus()
|
||||
}}
|
||||
>
|
||||
{e}
|
||||
</button>
|
||||
))}
|
||||
</div>
|
||||
<p className="h-4 px-4 text-center text-xs leading-4 font-bold text-(--heart)" role="alert">
|
||||
{addFailed && '댓글을 올리지 못했어요. 다시 해 주세요.'}
|
||||
{askTerms ? (
|
||||
<div className="mx-3 flex flex-col gap-2 rounded-[16px] bg-[#f3f6fb] p-3" role="dialog" aria-label="이용약관 동의">
|
||||
<p className="m-0 text-[13px] font-bold text-(--ink)">댓글을 쓰려면 이용약관에 동의해 주세요. 욕설·광고·개인정보 노출은 숨겨지고, 계속되면 이용이 제한돼요.</p>
|
||||
<div className="flex gap-2">
|
||||
<a href="/terms.html" target="_blank" rel="noopener" className="flex-1 rounded-[12px] bg-white p-2.5 text-center text-[13px] font-extrabold text-(--ink)">
|
||||
이용약관 보기
|
||||
</a>
|
||||
<button type="button" onClick={agreeAndSend} disabled={agree.isPending || add.isPending} className="flex-1 cursor-pointer rounded-[12px] bg-(--orange) p-2.5 text-[13px] font-extrabold text-white disabled:opacity-60">
|
||||
동의하고 쓰기
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
) : (
|
||||
<div className="flex justify-around pt-1 text-[22px]" role="group" aria-label="빠른 이모지">
|
||||
{EMOJIS.map((e) => (
|
||||
<button
|
||||
key={e}
|
||||
type="button"
|
||||
disabled={add.isPending}
|
||||
className="cursor-pointer disabled:opacity-40"
|
||||
onClick={() => {
|
||||
setText((t) => (t + e).slice(0, 60))
|
||||
inputRef.current?.focus()
|
||||
}}
|
||||
>
|
||||
{e}
|
||||
</button>
|
||||
))}
|
||||
</div>
|
||||
)}
|
||||
<p className={cx('h-4 px-4 text-center text-xs leading-4 font-bold', addFailed ? 'text-(--heart)' : 'text-(--ink2)')} role="alert">
|
||||
{addFailed ? '댓글을 올리지 못했어요. 다시 해 주세요.' : notice}
|
||||
</p>
|
||||
<form onSubmit={submit} className="flex items-center gap-2.5 border-t border-(--line) px-3 pt-2.5 pb-2.5">
|
||||
<input ref={inputRef} value={text} onChange={(e) => setText(e.target.value)} readOnly={add.isPending} maxLength={60} placeholder={me ? `${me.nickname}(으)로 댓글 달기…` : '댓글 달기…'} aria-label="댓글" className="min-w-0 flex-1 rounded-full border border-[#dfe5ee] bg-[#f7f9fc] px-3.5 py-2.5" />
|
||||
@@ -870,7 +1004,93 @@ function TossNoLoginSheet({ onDone }: { onDone: () => void }) {
|
||||
)
|
||||
}
|
||||
|
||||
/* ---------- 내 정보: 캐릭터·닉네임·로그아웃 ---------- */
|
||||
/* ---------- 내 정보: 캐릭터·닉네임·로그아웃·탈퇴 ---------- */
|
||||
/** 탈퇴: 한 번 더 묻고 지운다. 계정이 없어지니 이 기기 토큰도 지운다 */
|
||||
function Withdraw({ onDone }: { onDone: () => void }) {
|
||||
const withdraw = useMutation(withdrawMutation())
|
||||
const [asking, setAsking] = useState(false)
|
||||
const [failed, setFailed] = useState(false)
|
||||
if (!asking)
|
||||
return (
|
||||
<button type="button" onClick={() => setAsking(true)} className="cursor-pointer self-center p-1 text-[13px] font-semibold text-(--ink3)">
|
||||
탈퇴하기
|
||||
</button>
|
||||
)
|
||||
const run = () => {
|
||||
setFailed(false)
|
||||
withdraw.mutate(
|
||||
{},
|
||||
{
|
||||
onSuccess: (res) => {
|
||||
if (!res.result?.success) return setFailed(true)
|
||||
clearTokens()
|
||||
onDone()
|
||||
},
|
||||
onError: () => setFailed(true),
|
||||
},
|
||||
)
|
||||
}
|
||||
return (
|
||||
<div className="flex flex-col gap-2.5 rounded-[18px] bg-[#fff1f3] p-3.5" role="alert">
|
||||
<p className="m-0 text-center text-sm font-bold text-(--ink)">
|
||||
탈퇴하면 계정과 남긴 댓글·좋아요가
|
||||
<br />
|
||||
모두 지워져요. 되돌릴 수 없어요.
|
||||
</p>
|
||||
<div className="flex gap-2">
|
||||
<button type="button" onClick={() => setAsking(false)} disabled={withdraw.isPending} className="flex-1 cursor-pointer rounded-[14px] bg-white p-3 text-sm font-extrabold text-(--ink)">
|
||||
그만둘게요
|
||||
</button>
|
||||
<button type="button" onClick={run} disabled={withdraw.isPending} className="flex-1 cursor-pointer rounded-[14px] bg-(--heart) p-3 text-sm font-extrabold text-white disabled:opacity-60">
|
||||
탈퇴할게요
|
||||
</button>
|
||||
</div>
|
||||
{failed && <p className="m-0 text-center text-[13px] font-bold text-(--heart)">탈퇴하지 못했어요. 잠시 뒤에 다시 해 주세요.</p>}
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
/** 차단한 사람: 있을 때만 보이고, 풀면 그 사람 댓글이 다시 보인다 */
|
||||
function Blocked() {
|
||||
const queryClient = useQueryClient()
|
||||
const list = useQuery(listBlockedOptions())
|
||||
const unblock = useMutation(unblockMutation())
|
||||
const [failed, setFailed] = useState(false)
|
||||
const users = list.data?.users ?? []
|
||||
if (!users.length) return null
|
||||
const release = (user_id: string) => {
|
||||
setFailed(false)
|
||||
unblock.mutate(
|
||||
{ path: { user_id } },
|
||||
{
|
||||
onSuccess: (res) => {
|
||||
if (!res.result?.success) return setFailed(true)
|
||||
queryClient.invalidateQueries({ queryKey: listBlockedQueryKey() })
|
||||
queryClient.invalidateQueries({ predicate: isCommentList })
|
||||
},
|
||||
onError: () => setFailed(true),
|
||||
},
|
||||
)
|
||||
}
|
||||
return (
|
||||
<section aria-label="차단한 사람">
|
||||
<h4 className="m-0 mb-2 text-sm font-extrabold">차단한 사람</h4>
|
||||
<ul className="m-0 flex list-none flex-col gap-2 p-0">
|
||||
{users.map((u) => (
|
||||
<li key={u.user_id} className="flex items-center gap-2.5">
|
||||
<Avatar character={u.character} color={u.color} />
|
||||
<span className="flex-1 text-sm font-bold">{u.nickname}</span>
|
||||
<button type="button" onClick={() => release(u.user_id)} disabled={unblock.isPending} className="cursor-pointer rounded-[12px] bg-[#f3f6fb] px-3 py-2 text-[13px] font-extrabold text-(--ink) disabled:opacity-50">
|
||||
풀기
|
||||
</button>
|
||||
</li>
|
||||
))}
|
||||
</ul>
|
||||
{failed && <p className="m-0 mt-1.5 text-[13px] font-bold text-(--heart)">잠시 뒤에 다시 해 주세요.</p>}
|
||||
</section>
|
||||
)
|
||||
}
|
||||
|
||||
function MeSheet({ onDone }: { onDone: () => void }) {
|
||||
const install = useInstall()
|
||||
const installable = useInstallable()
|
||||
@@ -997,6 +1217,8 @@ function MeSheet({ onDone }: { onDone: () => void }) {
|
||||
>
|
||||
로그아웃
|
||||
</button>
|
||||
<Blocked />
|
||||
<Withdraw onDone={onDone} />
|
||||
</Body>
|
||||
)
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user