diff --git a/app/(help)/help.tsx b/app/(help)/help.tsx index 4d8ed97..531aa21 100644 --- a/app/(help)/help.tsx +++ b/app/(help)/help.tsx @@ -30,4 +30,3 @@ export default function HelpScreen() { ); } - diff --git a/app/(tabs-user)/_layout.tsx b/app/(tabs-user)/_layout.tsx index bbbb726..3d16245 100644 --- a/app/(tabs-user)/_layout.tsx +++ b/app/(tabs-user)/_layout.tsx @@ -31,7 +31,7 @@ export default function UserTabsLayout() { ( - + } /> { - queryClient.invalidateQueries({ queryKey: queries.voices._def }); queryClient.invalidateQueries({ queryKey: queries.questions._def }); queryClient.invalidateQueries({ queryKey: queries.chatbot._def }); @@ -279,7 +278,7 @@ export default function DiaryScreen() { return ( - } /> + } /> - + diff --git a/shared/ui/buttons/help-button.tsx b/shared/ui/buttons/help-button.tsx index 03a8658..c5bab1a 100644 --- a/shared/ui/buttons/help-button.tsx +++ b/shared/ui/buttons/help-button.tsx @@ -6,11 +6,11 @@ export const HelpButton = () => { const router = useRouter(); const handlePress = () => { - router.push('/(help)/help'); + router.push("/(help)/help"); }; return ( ); -}; \ No newline at end of file +}; diff --git a/shared/ui/header/navbar.tsx b/shared/ui/header/navbar.tsx index 3c693d1..b6f11e0 100644 --- a/shared/ui/header/navbar.tsx +++ b/shared/ui/header/navbar.tsx @@ -6,7 +6,7 @@ type HeaderProps = { title: string; navigateTo?: Href; rightComponent?: React.ReactNode; -} +}; export const BackHeader = ({ title, navigateTo, rightComponent }: HeaderProps) => { const router = useRouter(); @@ -34,4 +34,4 @@ export const BackHeader = ({ title, navigateTo, rightComponent }: HeaderProps) = )} ); -}; \ No newline at end of file +}; diff --git a/widgets/chat/report/ui/weekly-story.tsx b/widgets/chat/report/ui/weekly-story.tsx index 33f3330..6a274bf 100644 --- a/widgets/chat/report/ui/weekly-story.tsx +++ b/widgets/chat/report/ui/weekly-story.tsx @@ -1,11 +1,12 @@ -import { useIsMutating, useMutation, useQuery, useQueryClient } from "@tanstack/react-query"; -import { useEffect, useMemo } from "react"; +import { noop, useIsMutating, useMutation, useQuery, useQueryClient } from "@tanstack/react-query"; +import { useEffect, useMemo, useRef } from "react"; import { ActivityIndicator, Text, View } from "react-native"; import { FluentSparkleIcon } from "@/assets/icons"; import { queries } from "@/entities"; import { createWeeklyReport, type WeeklyReportItem } from "@/entities/chatbot"; import { normalizeEmotion } from "@/shared/lib/emotions"; +import { Icon } from "@/shared/ui"; export const WeeklyStory = ({ username }: { username: string }) => { const queryClient = useQueryClient(); @@ -46,6 +47,12 @@ export const WeeklyStory = ({ username }: { username: string }) => { // mutation key 생성 const createWeeklyReportMutationKey = ["createWeeklyReport", username, currentWeekStart]; + // 같은 주에 대해 생성 요청을 한 번만 시도하기 위한 ref (404/무데이터 시 무한 재시도 방지) + const triedCreateForWeekRef = useRef(null); + if (triedCreateForWeekRef.current !== null && triedCreateForWeekRef.current !== currentWeekStart) { + triedCreateForWeekRef.current = null; + } + // mutation이 진행 중인지 확인 const isMutating = useIsMutating({ mutationKey: createWeeklyReportMutationKey, @@ -96,6 +103,7 @@ export const WeeklyStory = ({ username }: { username: string }) => { target_date: currentWeekStart, }); }, + onError: noop, onSuccess: () => { queryClient.invalidateQueries({ queryKey: queries.chatbot.monthlyReports(username, year, month).queryKey, @@ -120,19 +128,19 @@ export const WeeklyStory = ({ username }: { username: string }) => { const is404Error = isError && (error as any)?.response?.status === 404; + // 같은 주에 대해 이미 생성 시도를 했으면 다시 호출하지 않음 (404/무데이터 시 무한 재시도 방지) + if (triedCreateForWeekRef.current === currentWeekStart) { + return; + } + if (is404Error) { - console.log("[WeeklyStory] 주간 리포트 생성 이유: monthlyReports API에서 404 에러 발생", { - username, - year, - month, - currentWeekStart, - currentWeekEnd, - }); + triedCreateForWeekRef.current = currentWeekStart; createWeeklyStory(); return; } if (!isError && !currentWeekReport) { + triedCreateForWeekRef.current = currentWeekStart; const hasReports = monthlyReports?.reports && monthlyReports.reports.length > 0; const reason = !monthlyReports?.reports ? "monthlyReports 데이터가 없음" @@ -209,7 +217,13 @@ export const WeeklyStory = ({ username }: { username: string }) => { - ) : null} + ) : ( + + + { + error?.response?.data?.message ?? "금주 대화가 없어 생성할 수 없습니다."} + + )} ); }; \ No newline at end of file