Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 30 additions & 6 deletions app/(feed)/explore/explore-page-client.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import { toast } from "sonner";
import useInfiniteScroll from "@/hooks/use-infinite-scroll";

const PAGE_SIZE = 24;
const EXPLORE_POPUP_DISMISSED_KEY = "fairplay:explore-popup-dismissed";

function mergeUniqueById(prev: VideoDetails[], next: VideoDetails[]) {
if (next.length === 0) return prev;
Expand Down Expand Up @@ -58,7 +59,7 @@ export default function ExplorePageClient({
shouldFetchInit ? null : (initialError ?? null),
);

const [isPopupOpen, setIsPopupOpen] = useState<boolean>(params.has("popup"));
const [isPopupOpen, setIsPopupOpen] = useState<boolean>(false);

const [page, setPage] = useState<number>(1);

Expand Down Expand Up @@ -112,16 +113,29 @@ export default function ExplorePageClient({
fetchVideos(1, "initial");
}, [fetchVideos, shouldFetchInit]);

useEffect(() => {
if (!params.has("popup")) return;

const removePopupParam = useCallback(() => {
const nextParams = new URLSearchParams(params.toString());
nextParams.delete("popup");

const nextUrl = nextParams.toString() ? `${pathname}?${nextParams.toString()}` : pathname;
router.replace(nextUrl, { scroll: false });
}, [params, pathname, router]);

const closePopup = useCallback(() => {
window.localStorage.setItem(EXPLORE_POPUP_DISMISSED_KEY, "true");
setIsPopupOpen(false);
}, []);

useEffect(() => {
if (!params.has("popup")) return;

const hasDismissedPopup =
window.localStorage.getItem(EXPLORE_POPUP_DISMISSED_KEY) === "true";

setIsPopupOpen(!hasDismissedPopup);
removePopupParam();
}, [params, removePopupParam]);

const loadMore = useCallback(() => {
if (isLoading || isLoadingMore || !hasMore) return;
fetchVideos(page + 1, "more");
Expand Down Expand Up @@ -177,7 +191,17 @@ export default function ExplorePageClient({
) : null}
</div>

<AlertDialog open={isPopupOpen} onOpenChange={setIsPopupOpen}>
<AlertDialog
open={isPopupOpen}
onOpenChange={(open) => {
if (open) {
setIsPopupOpen(true);
return;
}

closePopup();
}}
>
<AlertDialogContent>
<AlertDialogHeader>
<AlertDialogTitle>Hang on a sec...</AlertDialogTitle>
Expand All @@ -188,7 +212,7 @@ export default function ExplorePageClient({
</AlertDialogHeader>

<AlertDialogFooter>
<AlertDialogAction onClick={() => setIsPopupOpen(false)}>Continue</AlertDialogAction>
<AlertDialogAction onClick={closePopup}>Continue</AlertDialogAction>
</AlertDialogFooter>
</AlertDialogContent>
</AlertDialog>
Expand Down
20 changes: 20 additions & 0 deletions app/globals.css
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,26 @@ html {
scrollbar-gutter: stable;
}

/*
* Radix UI injects the following CSS when a dialog box is opened:
* margin-right: 6px !important;
* --removed-body-scroll-bar-size: 6px;
* to compensate for the removal of the scrollbar.
*
* However, the scrollbar is already managed by "scrollbar-gutter: stable" on <html>,
* these causes an overlay shift.
*
* The following style corrects this shift.
*/
html body[data-scroll-locked] {
margin-right: 0 !important;
--removed-body-scroll-bar-size: 0px !important;
}

body[data-scroll-locked] {
margin-right: 0 !important;
}

body {
font-family: var(--font-body);
line-height: 1.6;
Expand Down
Loading