From a023cbf3112b3ab7a9e82934594b0366ca956e78 Mon Sep 17 00:00:00 2001 From: Sam Becker Date: Thu, 21 Sep 2023 18:20:56 -0500 Subject: [PATCH] Manage scrolling on share modals --- src/components/IconPathButton.tsx | 4 +++- src/components/Modal.tsx | 2 +- src/photo/PhotoDetailPage.tsx | 1 + src/photo/PhotoLarge.tsx | 3 +++ src/photo/SharePhotoButton.tsx | 3 +++ 5 files changed, 11 insertions(+), 2 deletions(-) diff --git a/src/components/IconPathButton.tsx b/src/components/IconPathButton.tsx index 53f8058c..8cb41c0b 100644 --- a/src/components/IconPathButton.tsx +++ b/src/components/IconPathButton.tsx @@ -10,11 +10,13 @@ export default function IconPathButton({ path, prefetch, loaderDelay = 250, + shouldScroll = true, }: { icon: JSX.Element path: string prefetch?: boolean loaderDelay?: number + shouldScroll?: boolean }) { const router = useRouter(); @@ -43,7 +45,7 @@ export default function IconPathButton({ startTransition(() => - router.push(path))} + router.push(path, { scroll: shouldScroll }))} isLoading={shouldShowLoader} className={cc( 'active:translate-y-[1px]', diff --git a/src/components/Modal.tsx b/src/components/Modal.tsx index adfffc97..3f3bd86e 100644 --- a/src/components/Modal.tsx +++ b/src/components/Modal.tsx @@ -28,7 +28,7 @@ export default function Modal({ useClickInsideOutside({ htmlElements, - onClickOutside: () => router.push(onClosePath ?? '/'), + onClickOutside: () => router.push(onClosePath ?? '/', { scroll: false}), }); return ( diff --git a/src/photo/PhotoDetailPage.tsx b/src/photo/PhotoDetailPage.tsx index 581293c9..20bc70a3 100644 --- a/src/photo/PhotoDetailPage.tsx +++ b/src/photo/PhotoDetailPage.tsx @@ -41,6 +41,7 @@ export default function PhotoDetailPage({ tag={tag} priority prefetchShare + shouldScrollOnShare={false} />, ]} /> diff --git a/src/photo/PhotoLarge.tsx b/src/photo/PhotoLarge.tsx index b76db149..e0202e2c 100644 --- a/src/photo/PhotoLarge.tsx +++ b/src/photo/PhotoLarge.tsx @@ -12,11 +12,13 @@ export default function PhotoLarge({ tag, priority, prefetchShare, + shouldScrollOnShare, }: { photo: Photo tag?: string priority?: boolean prefetchShare?: boolean + shouldScrollOnShare?: boolean }) { const tagsToShow = photo.tags.filter(t => t !== tag); @@ -101,6 +103,7 @@ export default function PhotoLarge({ photo={photo} tag={tag} prefetch={prefetchShare} + shouldScroll={shouldScrollOnShare} /> diff --git a/src/photo/SharePhotoButton.tsx b/src/photo/SharePhotoButton.tsx index c25a97f9..2c02f421 100644 --- a/src/photo/SharePhotoButton.tsx +++ b/src/photo/SharePhotoButton.tsx @@ -7,16 +7,19 @@ export default function SharePhotoButton({ photo, tag, prefetch, + shouldScroll, }: { photo: Photo tag?: string prefetch?: boolean + shouldScroll?: boolean }) { return ( } path={pathForPhotoShare(photo, tag)} prefetch={prefetch} + shouldScroll={shouldScroll} /> ); }