From 0f1cc56bf3d763c54717d9ec1e521b32f759b142 Mon Sep 17 00:00:00 2001 From: kimnamheeee Date: Sat, 7 Feb 2026 15:04:56 +0900 Subject: [PATCH 1/2] =?UTF-8?q?=E2=9C=A8=20feat(story):=20return=20to=20pr?= =?UTF-8?q?evious=20page=20when=20closing=20story?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../story-viewer/model/useStoryViewer.ts | 19 +++++++++++++++-- src/features/story-viewer/ui/StoryViewer.tsx | 16 +++++++++++--- .../stories/$profile_name/$story_id.tsx | 21 +++++++++++++++++-- .../profile-header/ui/ProfileAvatar.tsx | 4 +++- 4 files changed, 52 insertions(+), 8 deletions(-) diff --git a/src/features/story-viewer/model/useStoryViewer.ts b/src/features/story-viewer/model/useStoryViewer.ts index 73ebd6c..03afb24 100644 --- a/src/features/story-viewer/model/useStoryViewer.ts +++ b/src/features/story-viewer/model/useStoryViewer.ts @@ -2,11 +2,17 @@ import { useState, useCallback, useMemo, useEffect } from 'react' import { useNavigate } from '@tanstack/react-router' import type { StoryFeedItem } from '@/entities/story/model/types' +type UseStoryViewerOptions = { + onComplete?: () => void +} + export function useStoryViewer( storiesData: StoryFeedItem[], - initialUserId: string + initialUserId: string, + options?: UseStoryViewerOptions ) { const navigate = useNavigate() + const { onComplete } = options ?? {} const STORY_DURATION = 5000 const INTERVAL_MS = 10 @@ -50,10 +56,19 @@ export function useStoryViewer( to: '/stories/$user_id', params: { user_id: String(nextUser.userId) }, }) + } else if (onComplete) { + onComplete() } else { navigate({ to: '/', search: { page: 1 } }) } - }, [currentUser, state.storyIndex, currentUserIndex, storiesData, navigate]) + }, [ + currentUser, + state.storyIndex, + currentUserIndex, + storiesData, + navigate, + onComplete, + ]) const handlePrev = useCallback(() => { if (!currentUser) return diff --git a/src/features/story-viewer/ui/StoryViewer.tsx b/src/features/story-viewer/ui/StoryViewer.tsx index 565ae8c..ac0c38a 100644 --- a/src/features/story-viewer/ui/StoryViewer.tsx +++ b/src/features/story-viewer/ui/StoryViewer.tsx @@ -24,6 +24,7 @@ interface StoryViewerProps { userId: string detailUser?: StoryFeedItem isDetailLoading?: boolean + onClose?: () => void } const formatRelativeTime = (createdAt: string) => { @@ -43,8 +44,17 @@ export function StoryViewer({ userId, detailUser, isDetailLoading, + onClose, }: StoryViewerProps) { const navigate = useNavigate() + + const handleClose = () => { + if (onClose) { + onClose() + } else { + navigate({ to: '/', search: { page: 1 } }) + } + } const queryClient = useQueryClient() const { data: me, isLoading: isMeLoading } = useCurrentUser() @@ -64,7 +74,7 @@ export function StoryViewer({ handleNext, handlePrev, togglePause, - } = useStoryViewer(feed, userId) + } = useStoryViewer(feed, userId, { onComplete: onClose }) const viewerUser = detailUser && String(detailUser.userId) === String(userId) @@ -125,7 +135,7 @@ export function StoryViewer({ if (response.isSuccess) { queryClient.invalidateQueries({ queryKey: ['stories', 'feed'] }) queryClient.invalidateQueries({ queryKey: ['stories', 'user', userId] }) - navigate({ to: '/', search: { page: 1 } }) + handleClose() } } catch (error) { console.error('스토리 삭제 실패:', error) @@ -145,7 +155,7 @@ export function StoryViewer({