feat: 댓글 신고·차단·약관 동의(관리 스크립트 포함), 구글 로그인(서버·웹·안드로이드 앱), 앱 패키지 kr.o2o.nalssigak·versionCode 1000

This commit is contained in:
minaChoi committed 2026-10-26 09:45:00 +09:00
1 parent fbebdcb796
commit 3f3a3ea039
35 files changed
+1723 -115

No files matched your search

+169 -35
View File
@@ -1,29 +1,114 @@
import {
addCommentMutation,
agreeTermsMutation,
blockAuthorMutation,
deleteCommentMutation,
getFeedQueryKey,
likeCommentMutation,
listBlockedQueryKey,
listCommentsInfiniteOptions,
listCommentsInfiniteQueryKey,
meQueryKey,
reportCommentMutation,
unlikeCommentMutation,
} from '@nalssigak/shared/api/client/@tanstack/react-query.gen';
import type { CommentData, ResCommentList } from '@nalssigak/shared/api/client/types.gen';
import { ReportReason, type CommentData, type ResCommentList } from '@nalssigak/shared/api/client/types.gen';
import { ago, loadOf } from '@nalssigak/shared/lib';
import { useInfiniteQuery, useMutation, useQueryClient, type InfiniteData } from '@tanstack/react-query';
import { useRef, useState } from 'react';
import { Pressable, Text, TextInput, View } from 'react-native';
import { useEffect, useRef, useState } from 'react';
import { Linking, Pressable, TextInput, View } from 'react-native';
import { Text } from '@/components/text';
import { useCSSVariable } from 'uniwind';
import { Avatar, Skel, StateBox } from '@/components/ui';
import { useAuth } from '@/lib/auth';
import { useRegion } from '@/lib/region';
import { useSheet } from '@/lib/sheet';
import { SITE_URL } from '@/lib/site';
import { Body, ErrorLine, Field, HeartIcon } from './parts';
import { Body, ErrorLine, Field, HeartIcon, useSoft } from './parts';
const NOT_FOUND = 3001; // 서버 ErrorType.NOT_FOUND
const EMOJIS = ['☀️', '🌂', '🍻', '🌇', '😍', '👍'];
const N3 = [0, 1, 2];
const REPORT_REASONS = [
[ReportReason.ABUSE, '욕설·비하'],
[ReportReason.AD, '광고'],
[ReportReason.PRIVACY, '개인정보 노출'],
[ReportReason.OTHER, '기타'],
] as const;
export const isCommentList = (q: { queryKey: readonly unknown[] }) => (q.queryKey[0] as { _id?: string } | undefined)?._id === 'listComments';
function Chip({ label, onPress, disabled, danger }: { label: string; onPress: () => void; disabled?: boolean; danger?: boolean }) {
const s = useSoft();
return (
<Pressable onPress={onPress} disabled={disabled} className={`rounded-[12px] px-3 py-2 disabled:opacity-50 ${danger ? 'bg-heart' : ''}`} style={danger ? undefined : { backgroundColor: s.soft }}>
<Text className={`text-[13px] font-extrabold ${danger ? 'text-white' : 'text-ink'}`}>{label}</Text>
</Pressable>
);
}
/** 남의 댓글: ⋯ → 신고하기(이유 고르기) / 이 사람 차단하기(한 번 더 묻기). 끝나면 목록을 다시 받아 그 댓글이 빠진다 */
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);
};
return (
<>
<Pressable onPress={() => go(step === 'closed' ? 'menu' : 'closed')} hitSlop={10} accessibilityRole="button" accessibilityState={{ expanded: step !== 'closed' }} accessibilityLabel="댓글 메뉴" className="px-1">
<Text className="text-sm font-extrabold text-ink3">⋯</Text>
</Pressable>
{step !== 'closed' && (
<View className="mt-2 w-full flex-row flex-wrap items-center gap-1.5" accessibilityLabel="댓글 메뉴">
{step === 'menu' && (
<>
<Chip label="신고하기" onPress={() => go('report')} />
<Chip label="이 사람 차단하기" onPress={() => go('block')} />
</>
)}
{step === 'report' &&
REPORT_REASONS.map(([reason, label]) => (
<Chip key={reason} label={label} disabled={pending} onPress={() => report.mutate({ path: { comment_id: c.comment_id }, body: { reason } }, finish('신고했어요. 확인하고 조치할게요.'))} />
))}
{step === 'block' && (
<>
<Text className="w-full text-[13px] font-bold text-ink">{c.nickname}님 댓글을 더는 안 볼까요?</Text>
<Chip label="차단하기" danger disabled={pending} onPress={() => block.mutate({ path: { comment_id: c.comment_id } }, finish('차단했어요. 내 정보에서 풀 수 있어요.'))} />
<Chip label="취소" disabled={pending} onPress={() => go('closed')} />
</>
)}
{failed && (
<Text className="w-full text-[13px] font-bold text-heart" accessibilityRole="alert">
잠시 뒤에 다시 해 주세요.
</Text>
)}
</View>
)}
</>
);
}
function CommentsSkel() {
return (
@@ -41,7 +126,7 @@ function CommentsSkel() {
);
}
function CommentRow({ c, postId }: { c: CommentData; postId: number }) {
function CommentRow({ c, postId, onNotice }: { c: CommentData; postId: number; onNotice: (text: string) => void }) {
const { region } = useRegion();
const { loggedIn } = useAuth();
const { open } = useSheet();
@@ -117,17 +202,20 @@ function CommentRow({ c, postId }: { c: CommentData; postId: number }) {
<Text className="font-extrabold">{c.nickname} </Text>
{c.body}
</Text>
<Text className="mt-0.5 text-xs font-bold text-ink3">
{ago(c.created_at)} · {likeFailed ? <Text className="text-heart">좋아요를 못 했어요. 잠시 뒤에 다시 눌러 주세요</Text> : `좋아요 ${count}개`}
{c.mine && (
<>
{' · '}
<Text onPress={remove.isPending ? undefined : del} className={removeFailed && !remove.isPending ? 'text-heart' : 'text-ink3'}>
{remove.isPending ? '지우는 중…' : removeFailed ? '못 지웠어요 · 다시' : '지우기'}
</Text>
</>
)}
</Text>
<View className="mt-0.5 flex-row flex-wrap items-center">
<Text className="text-xs font-bold text-ink3">
{ago(c.created_at)} · {likeFailed ? <Text className="text-heart">좋아요를 못 했어요. 잠시 뒤에 다시 눌러 주세요</Text> : `좋아요 ${count}개`}
{c.mine && (
<>
{' · '}
<Text onPress={remove.isPending ? undefined : del} className={removeFailed && !remove.isPending ? 'text-heart' : 'text-ink3'}>
{remove.isPending ? '지우는 중…' : removeFailed ? '못 지웠어요 · 다시' : '지우기'}
</Text>
</>
)}
</Text>
{!c.mine && <CommentMenu c={c} postId={postId} onNotice={onNotice} />}
</View>
</View>
<Pressable onPress={toggle} hitSlop={12} accessibilityRole="button" accessibilityState={{ selected: liked }} accessibilityLabel="댓글 좋아요" className="pt-1">
<HeartIcon size={16} fill={liked ? heart : 'none'} stroke={liked ? heart : ink3} />
@@ -147,13 +235,22 @@ export function CommentsSheet({ postId, draft }: { postId: number; draft?: strin
getNextPageParam: (last) => last.next_cursor ?? undefined,
});
const add = useMutation(addCommentMutation());
const agree = useMutation(agreeTermsMutation());
const s = useSoft();
const [addFailed, setAddFailed] = useState(false);
const [askTerms, setAskTerms] = useState(false);
const [notice, setNotice] = useState('');
const [text, setText] = useState(draft ?? '');
const inputRef = useRef<TextInput>(null);
const comments = list.data?.pages.flatMap((p) => p.comments ?? []) ?? [];
const submit = () => {
if (!loggedIn) return open({ type: 'login', then: { type: 'comments', postId, draft: text } });
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);
@@ -161,6 +258,7 @@ export function CommentsSheet({ postId, draft }: { postId: number; draft?: strin
{ path: { post_id: postId }, body: { body } },
{
onSuccess: (res) => {
if (res.result?.desc === 'TERMS_REQUIRED') return setAskTerms(true);
setAddFailed(!res.result?.success);
if (!res.result?.success) return;
setText('');
@@ -172,6 +270,28 @@ export function CommentsSheet({ postId, draft }: { postId: number; draft?: strin
);
};
// 약관에 동의해야 댓글을 쓸 수 있다. 동의하면 쓰던 댓글을 바로 올린다
const submit = () => {
if (!loggedIn) return open({ type: 'login', then: { type: 'comments', postId, draft: text } });
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>
@@ -179,7 +299,7 @@ export function CommentsSheet({ postId, draft }: { postId: number; draft?: strin
<>
{/* 다시 받은 좋아요 상태(로그인 바뀜 등)가 행에 반영되도록 key 에 넣는다 */}
{comments.map((c) => (
<CommentRow key={`${c.comment_id}:${c.liked}:${c.like_count}`} c={c} postId={postId} />
<CommentRow key={`${c.comment_id}:${c.liked}:${c.like_count}`} c={c} postId={postId} onNotice={setNotice} />
))}
{list.hasNextPage && (
<Pressable onPress={() => list.fetchNextPage()} disabled={list.isFetchingNextPage} className="my-2 disabled:opacity-50">
@@ -193,22 +313,36 @@ export function CommentsSheet({ postId, draft }: { postId: number; draft?: strin
<StateBox load={loadOf(list)} onRetry={() => list.refetch()} empty="아직 댓글이 없어요. 첫 댓글을 남겨 보세요." hold={<CommentsSkel />} boxClassName="inset-0" />
)}
</Body>
<View className="flex-row justify-around pt-1" accessibilityLabel="빠른 이모지">
{EMOJIS.map((e) => (
<Pressable
key={e}
disabled={add.isPending}
className="disabled:opacity-40"
onPress={() => {
setText((t) => (t + e).slice(0, 60));
inputRef.current?.focus();
}}
>
<Text className="text-[22px]">{e}</Text>
</Pressable>
))}
</View>
<ErrorLine className="h-4 text-xs leading-4" text={addFailed ? '댓글을 올리지 못했어요. 다시 해 주세요.' : undefined} />
{askTerms ? (
<View className="mx-3 gap-2 rounded-[16px] p-3" style={{ backgroundColor: s.soft }} accessibilityLabel="이용약관 동의">
<Text className="text-[13px] font-bold text-ink">댓글을 쓰려면 이용약관에 동의해 주세요. 욕설·광고·개인정보 노출은 숨겨지고, 계속되면 이용이 제한돼요.</Text>
<View className="flex-row gap-2">
<Pressable onPress={() => void Linking.openURL(`${SITE_URL}/terms.html`)} accessibilityRole="link" className="flex-1 rounded-[12px] bg-card p-2.5">
<Text className="text-center text-[13px] font-extrabold text-ink">이용약관 보기</Text>
</Pressable>
<Pressable onPress={agreeAndSend} disabled={agree.isPending || add.isPending} className="flex-1 rounded-[12px] bg-orange p-2.5 disabled:opacity-60">
<Text className="text-center text-[13px] font-extrabold text-white">동의하고 쓰기</Text>
</Pressable>
</View>
</View>
) : (
<View className="flex-row justify-around pt-1" accessibilityLabel="빠른 이모지">
{EMOJIS.map((e) => (
<Pressable
key={e}
disabled={add.isPending}
className="disabled:opacity-40"
onPress={() => {
setText((t) => (t + e).slice(0, 60));
inputRef.current?.focus();
}}
>
<Text className="text-[22px]">{e}</Text>
</Pressable>
))}
</View>
)}
{addFailed ? <ErrorLine className="h-4 text-xs leading-4" text="댓글을 올리지 못했어요. 다시 해 주세요." /> : <Text className="h-4 text-center text-xs leading-4 font-bold text-ink2">{notice}</Text>}
<View className="flex-row items-center gap-2.5 border-t border-line px-3 py-2.5">
<View className="flex-1">
<Field ref={inputRef} round value={text} onChangeText={setText} editable={!add.isPending} maxLength={60} placeholder={me ? `${me.nickname}(으)로 댓글 달기…` : '댓글 달기…'} accessibilityLabel="댓글" returnKeyType="send" onSubmitEditing={submit} />
+52
View File
@@ -0,0 +1,52 @@
import { authConfigOptions, googleLoginMutation } from '@nalssigak/shared/api/client/@tanstack/react-query.gen';
import type { ResAuth } from '@nalssigak/shared/api/client/types.gen';
import { GoogleSignin, isErrorWithCode, isSuccessResponse, statusCodes } from '@react-native-google-signin/google-signin';
import { useMutation, useQuery } from '@tanstack/react-query';
import { useState } from 'react';
import { Platform, Pressable, View } from 'react-native';
import { Text } from '@/components/text';
/** 구글로 계속하기. 서버에 클라이언트 ID가 없거나 안드로이드가 아니면 그리지 않는다 */
export function GoogleButton({ onResult, onFail }: { onResult: (res: ResAuth) => void; onFail: () => void }) {
const clientId = useQuery({ ...authConfigOptions(), staleTime: Infinity, enabled: Platform.OS === 'android' }).data?.google_client_id;
const login = useMutation(googleLoginMutation());
const [busy, setBusy] = useState(false);
const [broken, setBroken] = useState(false);
const press = async () => {
if (!clientId) return;
setBroken(false);
setBusy(true);
try {
GoogleSignin.configure({ webClientId: clientId });
await GoogleSignin.hasPlayServices({ showPlayServicesUpdateDialog: true });
const res = await GoogleSignin.signIn();
if (!isSuccessResponse(res)) return;
const token = res.data.idToken;
if (!token) return onFail();
login.mutate({ body: { credential: token } }, { onSuccess: onResult, onError: onFail });
} catch (e) {
if (isErrorWithCode(e) && e.code === statusCodes.IN_PROGRESS) return;
console.error('[google] sign in', e);
setBroken(true);
} finally {
setBusy(false);
}
};
if (Platform.OS !== 'android' || !clientId) return null;
const pending = busy || login.isPending;
return (
<View className="gap-2">
<Pressable onPress={press} disabled={pending} className="rounded-full border-[1.5px] border-line bg-white p-3 disabled:opacity-60" accessibilityRole="button">
<Text className="text-center text-[15px] font-extrabold text-[#28304a]">{pending ? '구글로 로그인 중…' : '구글로 계속하기'}</Text>
</Pressable>
{broken && <Text className="text-center text-[13px] font-bold text-ink3">구글 로그인을 하지 못했어요. 아이디로 로그인해 주세요.</Text>}
<View className="flex-row items-center gap-2">
<View className="h-px flex-1 bg-line" />
<Text className="text-[12.5px] font-bold text-ink3">또는 아이디로</Text>
<View className="h-px flex-1 bg-line" />
</View>
</View>
);
}
+4 -1
View File
@@ -3,10 +3,12 @@ import { loginMutation, signupMutation } from '@nalssigak/shared/api/client/@tan
import type { ResAuth } from '@nalssigak/shared/api/client/types.gen';
import { useMutation } from '@tanstack/react-query';
import { useState } from 'react';
import { Pressable, Text, View } from 'react-native';
import { Pressable, View } from 'react-native';
import { Text } from '@/components/text';
import { useAuth } from '@/lib/auth';
import { GoogleButton } from './google';
import { MeSheet } from './me';
import { Body, ErrorLine, Field, useSoft } from './parts';
@@ -60,6 +62,7 @@ export function LoginSheet({ onDone, onLoggedIn }: { onDone: () => void; onLogge
return (
<Body className="gap-2.5">
<Text className="text-center text-sm font-semibold text-ink2">좋아요·댓글은 로그인한 뒤에 할 수 있어요.</Text>
<GoogleButton onResult={done} onFail={fail} />
<View className="flex-row gap-1 rounded-full p-1" style={{ backgroundColor: s.soft }} accessibilityLabel="로그인 또는 가입">
{MODES.map(([m, l]) => (
<Pressable key={m} accessibilityState={{ selected: mode === m }} onPress={() => setMode(m)} className={`flex-1 rounded-full py-2 ${mode === m ? 'bg-ink-btn' : ''}`}>
+49 -4
View File
@@ -1,13 +1,15 @@
import { clearTokens } from '@nalssigak/shared/api/auth';
import { meQueryKey, updateMeMutation, withdrawMutation } from '@nalssigak/shared/api/client/@tanstack/react-query.gen';
import { listBlockedOptions, listBlockedQueryKey, meQueryKey, unblockMutation, updateMeMutation, withdrawMutation } from '@nalssigak/shared/api/client/@tanstack/react-query.gen';
import { AVATAR_COLORS, CHARACTERS, MOODS } from '@nalssigak/shared/lib';
import { useMutation, useQueryClient } from '@tanstack/react-query';
import { useMutation, useQuery, useQueryClient } from '@tanstack/react-query';
import { useState } from 'react';
import { Pressable, Text, View } from 'react-native';
import { Pressable, View } from 'react-native';
import { Text } from '@/components/text';
import { Avatar, Ic } from '@/components/ui';
import { useAuth } from '@/lib/auth';
import { isCommentList } from './comments';
import { Body, Field, useSoft } from './parts';
/** 탈퇴: 한 번 더 묻고 지운다. 계정이 없어지니 이 기기 토큰도 지운다 */
@@ -51,7 +53,49 @@ function Withdraw({ onDone }: { onDone: () => void }) {
);
}
/** 내 정보: 캐릭터·배경색·기분·닉네임·로그아웃·탈퇴 */
/** 차단한 사람: 있을 때만 보이고, 풀면 그 사람 댓글이 다시 보인다 */
function Blocked() {
const s = useSoft();
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 (
<View accessibilityLabel="차단한 사람">
<Text className="mb-2 text-sm font-extrabold text-ink">차단한 사람</Text>
<View className="gap-2">
{users.map((u) => (
<View key={u.user_id} className="flex-row items-center gap-2.5">
<Avatar character={u.character} color={u.color} />
<Text className="flex-1 text-sm font-bold text-ink">{u.nickname}</Text>
<Pressable onPress={() => release(u.user_id)} disabled={unblock.isPending} className="rounded-[12px] px-3 py-2 disabled:opacity-50" style={{ backgroundColor: s.soft }}>
<Text className="text-[13px] font-extrabold text-ink">풀기</Text>
</Pressable>
</View>
))}
</View>
{failed && <Text className="mt-1.5 text-[13px] font-bold text-heart">잠시 뒤에 다시 해 주세요.</Text>}
</View>
);
}
/** 내 정보: 캐릭터·배경색·기분·닉네임·로그아웃·차단한 사람·탈퇴 */
export function MeSheet({ onDone }: { onDone: () => void }) {
const { me, logout } = useAuth();
const s = useSoft();
@@ -165,6 +209,7 @@ export function MeSheet({ onDone }: { onDone: () => void }) {
>
<Text className="text-center text-[15px] font-extrabold text-ink">로그아웃</Text>
</Pressable>
<Blocked />
<Withdraw onDone={onDone} />
</Body>
);