Skip to content

Commit 62f84c6

Browse files
authored
Merge pull request #172 from wafflestudio/166-bug-deploy
스토리를 닫을 때 이전 페이지로 이동하도록 수정
2 parents 2159ad5 + 77c4a44 commit 62f84c6

File tree

5 files changed

+54
-11
lines changed

5 files changed

+54
-11
lines changed

src/features/story-viewer/model/useStoryViewer.ts

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,17 @@ import { useState, useCallback, useMemo, useEffect } from 'react'
22
import { useNavigate } from '@tanstack/react-router'
33
import type { StoryFeedItem } from '@/entities/story/model/types'
44

5+
type UseStoryViewerOptions = {
6+
onComplete?: () => void
7+
}
8+
59
export function useStoryViewer(
610
storiesData: StoryFeedItem[],
7-
initialUserId: string
11+
initialUserId: string,
12+
options?: UseStoryViewerOptions
813
) {
914
const navigate = useNavigate()
15+
const { onComplete } = options ?? {}
1016
const STORY_DURATION = 5000
1117
const INTERVAL_MS = 10
1218

@@ -50,10 +56,19 @@ export function useStoryViewer(
5056
to: '/stories/$user_id',
5157
params: { user_id: String(nextUser.userId) },
5258
})
59+
} else if (onComplete) {
60+
onComplete()
5361
} else {
5462
navigate({ to: '/', search: { page: 1 } })
5563
}
56-
}, [currentUser, state.storyIndex, currentUserIndex, storiesData, navigate])
64+
}, [
65+
currentUser,
66+
state.storyIndex,
67+
currentUserIndex,
68+
storiesData,
69+
navigate,
70+
onComplete,
71+
])
5772

5873
const handlePrev = useCallback(() => {
5974
if (!currentUser) return

src/features/story-viewer/ui/StoryViewer.tsx

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ interface StoryViewerProps {
2424
userId: string
2525
detailUser?: StoryFeedItem
2626
isDetailLoading?: boolean
27+
onClose?: () => void
2728
}
2829

2930
const formatRelativeTime = (createdAt: string) => {
@@ -43,8 +44,17 @@ export function StoryViewer({
4344
userId,
4445
detailUser,
4546
isDetailLoading,
47+
onClose,
4648
}: StoryViewerProps) {
4749
const navigate = useNavigate()
50+
51+
const handleClose = () => {
52+
if (onClose) {
53+
onClose()
54+
} else {
55+
navigate({ to: '/', search: { page: 1 } })
56+
}
57+
}
4858
const queryClient = useQueryClient()
4959
const { data: me, isLoading: isMeLoading } = useCurrentUser()
5060

@@ -64,7 +74,7 @@ export function StoryViewer({
6474
handleNext,
6575
handlePrev,
6676
togglePause,
67-
} = useStoryViewer(feed, userId)
77+
} = useStoryViewer(feed, userId, { onComplete: onClose })
6878

6979
const viewerUser =
7080
detailUser && String(detailUser.userId) === String(userId)
@@ -125,7 +135,7 @@ export function StoryViewer({
125135
if (response.isSuccess) {
126136
queryClient.invalidateQueries({ queryKey: ['stories', 'feed'] })
127137
queryClient.invalidateQueries({ queryKey: ['stories', 'user', userId] })
128-
navigate({ to: '/', search: { page: 1 } })
138+
handleClose()
129139
}
130140
} catch (error) {
131141
console.error('스토리 삭제 실패:', error)
@@ -145,7 +155,7 @@ export function StoryViewer({
145155
</div>
146156

147157
<button
148-
onClick={() => navigate({ to: '/', search: { page: 1 } })}
158+
onClick={handleClose}
149159
className="absolute top-4 right-4 z-50 p-2 text-white transition-opacity hover:opacity-70"
150160
>
151161
<X className="h-9 w-9" strokeWidth={1.5} />

src/features/story-viewer/ui/constants.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,8 @@ export const STORY_VIEWER_UI = {
77
OVERLAY_TOP:
88
'absolute top-0 z-30 flex w-full flex-col gap-3 bg-gradient-to-b from-black/60 to-transparent p-4 pb-10',
99
PROGRESS_CONTAINER: 'flex w-full gap-1',
10-
PROGRESS_BAR: 'h-0.5 flex-1 overflow-hidden rounded-full bg-white/30',
11-
PROGRESS_BAR_FILL:
12-
'h-full bg-white transition-all duration-100 ease-linear',
10+
PROGRESS_BAR: 'h-[3px] flex-1 overflow-hidden rounded-full bg-white/30',
11+
PROGRESS_BAR_FILL: 'h-full bg-white',
1312
HEADER: 'flex items-center justify-between',
1413
USER_SECTION: 'flex items-center gap-3',
1514
USER_INFO: 'flex items-center gap-2 text-[14px] font-medium text-white',

src/routes/stories/$profile_name/$story_id.tsx

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,35 @@
1-
import { createFileRoute } from '@tanstack/react-router'
1+
import { createFileRoute, useNavigate } from '@tanstack/react-router'
22
import { StoryViewer } from '@/features/story-viewer/ui/StoryViewer'
33
import { useQuery } from '@tanstack/react-query'
44
import { getStoryDetail } from '@/entities/story/api/getStoryDetail'
55
import { useProfile } from '@/entities/user/model/hooks/useProfile'
6-
import { useMemo } from 'react'
6+
import { useCallback, useMemo } from 'react'
77
import type { StoryFeedItem } from '@/entities/story/model/types'
8+
import { z } from 'zod'
9+
10+
const searchSchema = z.object({
11+
returnTo: z.string().optional(),
12+
})
813

914
export const Route = createFileRoute('/stories/$profile_name/$story_id')({
1015
component: RouteComponent,
16+
validateSearch: searchSchema,
1117
})
1218

1319
function RouteComponent() {
1420
const { profile_name: userId } = Route.useParams()
21+
const { returnTo } = Route.useSearch()
22+
const navigate = useNavigate()
1523
const { data: profileData } = useProfile(Number(userId))
1624

25+
const handleClose = useCallback(() => {
26+
if (returnTo) {
27+
navigate({ to: returnTo })
28+
} else {
29+
navigate({ to: '/$userId', params: { userId } })
30+
}
31+
}, [navigate, returnTo, userId])
32+
1733
const { data: detailData, isLoading: isDetailLoading } = useQuery({
1834
queryKey: ['stories', 'user', userId],
1935
queryFn: () => getStoryDetail(userId),
@@ -51,6 +67,7 @@ function RouteComponent() {
5167
userId={userId}
5268
detailUser={userStoryFeedItem}
5369
isDetailLoading={isDetailLoading}
70+
onClose={handleClose}
5471
/>
5572
</div>
5673
)

src/widgets/profile-header/ui/ProfileAvatar.tsx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { Link } from '@tanstack/react-router'
1+
import { Link, useLocation } from '@tanstack/react-router'
22
import { cn } from '@/shared/lib/utils'
33
import { DefaultProfileImage } from '@/shared/ui/default-profile-image'
44

@@ -21,6 +21,7 @@ export function ProfileAvatar({
2121
userId,
2222
firstStoryId,
2323
}: ProfileAvatarProps) {
24+
const location = useLocation()
2425
const avatarContent = avatarUrl ? (
2526
<img
2627
src={avatarUrl}
@@ -61,6 +62,7 @@ export function ProfileAvatar({
6162
profile_name: String(userId),
6263
story_id: String(firstStoryId),
6364
}}
65+
search={{ returnTo: location.pathname }}
6466
>
6567
{content}
6668
</Link>

0 commit comments

Comments
 (0)