Merge branch 'auto-scroll' into main

This commit is contained in:
Chuck Dries 2022-06-16 00:05:02 -07:00
commit 479d3d661e
No known key found for this signature in database
GPG Key ID: A00B7AEAE1DC5BE6
5 changed files with 34 additions and 6 deletions

View File

@ -9,7 +9,7 @@
],
"scripts": {
"develop": "gatsby develop",
"start": "gatsby develop -H 0.0.0.0",
"start": "cross-env NODE_OPTIONS=--no-experimental-fetch gatsby develop -H 0.0.0.0",
"build": "gatsby build",
"serve": "gatsby serve",
"clean": "gatsby clean",
@ -63,6 +63,7 @@
"use-breakpoint": "^2.0.1"
},
"devDependencies": {
"cross-env": "^7.0.3",
"prettier": "2.3.2"
}
}

View File

@ -51,7 +51,7 @@ const GalleryImage = ({ data, pageContext }) => {
case "Escape":
case "KeyG": {
logKeyShortcut(e.code);
navigate("/photogallery/");
navigate(`/photogallery/#${image.base}`);
}
}
};
@ -59,7 +59,7 @@ const GalleryImage = ({ data, pageContext }) => {
return () => {
document.removeEventListener("keydown", keyListener);
};
}, [pageContext]);
}, [pageContext, image.base]);
const name = getName(image);
const { meta, dateTaken: dt } = getMeta(image);
@ -108,7 +108,7 @@ const GalleryImage = ({ data, pageContext }) => {
</Link>
<Link
className="hover:underline text-vibrant-light hover:text-muted-light mx-1"
to="/photogallery/"
to={`/photogallery/#${image.base}`}
>
gallery <span className="bg-gray-300 text-black">esc</span>
</Link>

View File

@ -17,6 +17,25 @@ const MasonryGallery = ({
);
const { breakpoint } = useBreakpoint(breakpoints, "sm");
console.log("🚀 ~ file: MasonryGallery.js ~ line 20 ~ breakpoint", breakpoint)
const scrollIntoView = React.useCallback(() => {
if (!window.location.hash) {
return;
}
const el = document.getElementById(window.location.hash.split("#")[1]);
if (!el) {
return;
}
el.scrollIntoView();
}, []);
React.useEffect(() => {
// hacky but it works for now
setTimeout(() => {
scrollIntoView();
}, 100)
}, [scrollIntoView]);
const aspectRatios = React.useMemo(
() => R.map(getAspectRatio, images),
@ -84,6 +103,7 @@ const MasonryGallery = ({
return (
<Link
className="border border-black inline-block"
id={image.base}
key={`${image.base}`}
state={{ modal: true }}
style={{

View File

@ -44,13 +44,13 @@ const GalleryPage = ({ data }) => {
</h1>
<div className="mx-auto">
<MasonryGallery
images={images}
aspectsByBreakpoint={{
sm: 3.6,
md: 4,
lg: 5,
xl: 6.1,
}}
images={images}
/>
</div>
</div>

View File

@ -4080,6 +4080,13 @@ cross-env@^6.0.3:
dependencies:
cross-spawn "^7.0.0"
cross-env@^7.0.3:
version "7.0.3"
resolved "https://registry.yarnpkg.com/cross-env/-/cross-env-7.0.3.tgz#865264b29677dc015ba8418918965dd232fc54cf"
integrity sha512-+/HKd6EgcQCJGh2PSjZuUitQBQynKor4wrFbRg4DtAgS1aWO+gU52xpH7M9ScGgXSYmAVS9bIJ8EzuaGw0oNAw==
dependencies:
cross-spawn "^7.0.1"
cross-fetch@3.1.4:
version "3.1.4"
resolved "https://registry.npmjs.org/cross-fetch/-/cross-fetch-3.1.4.tgz"
@ -4087,7 +4094,7 @@ cross-fetch@3.1.4:
dependencies:
node-fetch "2.6.1"
cross-spawn@7.0.3, cross-spawn@^7.0.0, cross-spawn@^7.0.2, cross-spawn@^7.0.3:
cross-spawn@7.0.3, cross-spawn@^7.0.0, cross-spawn@^7.0.1, cross-spawn@^7.0.2, cross-spawn@^7.0.3:
version "7.0.3"
resolved "https://registry.npmjs.org/cross-spawn/-/cross-spawn-7.0.3.tgz"
integrity sha512-iRDPJKUPVEND7dHPO8rkbOnPpyDygcDFtWjpeWNCgy8WP2rXcxXL8TskReQl6OrB2G7+UJrags1q15Fudc7G6w==