|
1 | 1 | "use client"; |
2 | 2 |
|
3 | 3 | import { useCallback, useEffect, useState } from "react"; |
4 | | -import { useSearchParams } from "next/navigation"; |
| 4 | +import { usePathname, useRouter, useSearchParams } from "next/navigation"; |
5 | 5 | import { VideoCard } from "@/components/app/video/video-card"; |
6 | 6 | import { getVideos, type VideoDetails } from "@/lib/video"; |
7 | 7 | import { Spinner } from "@/components/ui/spinner"; |
@@ -45,6 +45,8 @@ export default function ExplorePageClient({ |
45 | 45 | initialTotalPages, |
46 | 46 | initialError, |
47 | 47 | }: ExplorePageClientProps) { |
| 48 | + const router = useRouter(); |
| 49 | + const pathname = usePathname(); |
48 | 50 | const params = useSearchParams(); |
49 | 51 |
|
50 | 52 | const shouldFetchInit = Boolean(initialError); |
@@ -111,8 +113,14 @@ export default function ExplorePageClient({ |
111 | 113 | }, [fetchVideos, shouldFetchInit]); |
112 | 114 |
|
113 | 115 | useEffect(() => { |
114 | | - setIsPopupOpen(params.has("popup")); |
115 | | - }, [params]); |
| 116 | + if (!params.has("popup")) return; |
| 117 | + |
| 118 | + const nextParams = new URLSearchParams(params.toString()); |
| 119 | + nextParams.delete("popup"); |
| 120 | + |
| 121 | + const nextUrl = nextParams.toString() ? `${pathname}?${nextParams.toString()}` : pathname; |
| 122 | + router.replace(nextUrl, { scroll: false }); |
| 123 | + }, [params, pathname, router]); |
116 | 124 |
|
117 | 125 | const loadMore = useCallback(() => { |
118 | 126 | if (isLoading || isLoadingMore || !hasMore) return; |
|
0 commit comments