fix hash nav stuff
This commit is contained in:
parent
f21fc5efd1
commit
fa2a639dbb
@ -90,6 +90,9 @@ const GalleryPage = ({
|
|||||||
);
|
);
|
||||||
|
|
||||||
const removeHash = React.useCallback(() => {
|
const removeHash = React.useCallback(() => {
|
||||||
|
if (!hash.length) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
const url = new URL(
|
const url = new URL(
|
||||||
typeof window !== "undefined"
|
typeof window !== "undefined"
|
||||||
? window.location.href.toString()
|
? window.location.href.toString()
|
||||||
@ -97,9 +100,9 @@ const GalleryPage = ({
|
|||||||
);
|
);
|
||||||
|
|
||||||
url.hash = "";
|
url.hash = "";
|
||||||
navigate(url.href.toString());
|
window.history.replaceState(null, "", url.href.toString());
|
||||||
window.removeEventListener("wheel", removeHash);
|
window.removeEventListener("wheel", removeHash);
|
||||||
}, []);
|
}, [hash]);
|
||||||
|
|
||||||
React.useEffect(() => {
|
React.useEffect(() => {
|
||||||
window.addEventListener("wheel", removeHash);
|
window.addEventListener("wheel", removeHash);
|
||||||
@ -110,7 +113,7 @@ const GalleryPage = ({
|
|||||||
// hacky but it works for now
|
// hacky but it works for now
|
||||||
requestAnimationFrame(() => {
|
requestAnimationFrame(() => {
|
||||||
// don't scroll into view if user got here with back button or if we just cleared it
|
// don't scroll into view if user got here with back button or if we just cleared it
|
||||||
if (!hash || !hash.length) {
|
if (!hash.length) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
const el = document.getElementById(hash);
|
const el = document.getElementById(hash);
|
||||||
@ -118,6 +121,7 @@ const GalleryPage = ({
|
|||||||
console.log("⚠️failed to find hash");
|
console.log("⚠️failed to find hash");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
console.log('scrolling into view manually')
|
||||||
el.scrollIntoView({
|
el.scrollIntoView({
|
||||||
block: hash.startsWith("all") ? "start" : "center",
|
block: hash.startsWith("all") ? "start" : "center",
|
||||||
});
|
});
|
||||||
|
Loading…
x
Reference in New Issue
Block a user