hacky solution for auto scroll feature for now

This commit is contained in:
Chuck Dries 2022-06-16 00:04:33 -07:00
parent a94cd6b85d
commit c939888d87
No known key found for this signature in database
GPG Key ID: A00B7AEAE1DC5BE6
2 changed files with 8 additions and 14 deletions

View File

@ -51,7 +51,7 @@ const GalleryImage = ({ data, pageContext }) => {
case "Escape": case "Escape":
case "KeyG": { case "KeyG": {
logKeyShortcut(e.code); logKeyShortcut(e.code);
navigate("/photogallery/"); navigate(`/photogallery/#${image.base}`);
} }
} }
}; };
@ -59,7 +59,7 @@ const GalleryImage = ({ data, pageContext }) => {
return () => { return () => {
document.removeEventListener("keydown", keyListener); document.removeEventListener("keydown", keyListener);
}; };
}, [pageContext]); }, [pageContext, image.base]);
const name = getName(image); const name = getName(image);
const { meta, dateTaken: dt } = getMeta(image); const { meta, dateTaken: dt } = getMeta(image);

View File

@ -16,10 +16,9 @@ const MasonryGallery = ({
[aspectTargetsByBreakpoint] [aspectTargetsByBreakpoint]
); );
const { breakpoint } = useBreakpoint(breakpoints, "xs"); const { breakpoint } = useBreakpoint(breakpoints, "sm");
console.log("🚀 ~ file: MasonryGallery.js ~ line 20 ~ breakpoint", breakpoint) console.log("🚀 ~ file: MasonryGallery.js ~ line 20 ~ breakpoint", breakpoint)
// const [scrolled, setScrolled] = React.useState(false);
const scrollIntoView = React.useCallback(() => { const scrollIntoView = React.useCallback(() => {
if (!window.location.hash) { if (!window.location.hash) {
return; return;
@ -28,20 +27,15 @@ const MasonryGallery = ({
if (!el) { if (!el) {
return; return;
} }
console.log("el", el);
el.scrollIntoView(); el.scrollIntoView();
console.log(
"🚀 ~ file: MasonryGallery.js ~ line 21 ~ scrollIntoView ~ el.offsetTop",
el.offsetTop
);
if (el.offsetTop > window.innerHeight && window.scrollY === 0) {
// queue another
}
}, []); }, []);
React.useEffect(() => { React.useEffect(() => {
// hacky but it works for now
setTimeout(() => {
scrollIntoView(); scrollIntoView();
}, [scrollIntoView, breakpoint]); }, 100)
}, [scrollIntoView]);
const aspectRatios = React.useMemo( const aspectRatios = React.useMemo(
() => R.map(getAspectRatio, images), () => R.map(getAspectRatio, images),