Remove location hash when user scrolls page

This commit is contained in:
Chuck Dries 2022-07-10 17:56:28 -07:00
parent f038f5e9ef
commit f021378813
No known key found for this signature in database
GPG Key ID: A00B7AEAE1DC5BE6

View File

@ -16,8 +16,21 @@ const SORT_KEYS = {
date: [],
};
function removeHash() {
const url = new URL(
typeof window !== "undefined"
? window.location.href.toString()
: "https://chuckdries.com/photogallery/"
);
url.hash = "";
window.history.replaceState(null, "", url.href.toString());
window.removeEventListener('wheel', removeHash);
}
const GalleryPage = ({ data }) => {
const hash = typeof window !== "undefined" ? window.location.hash.replace("#", "") : "";
const hash =
typeof window !== "undefined" ? window.location.hash.replace("#", "") : "";
const [filterKeyword, _setKeyword] = React.useState(null);
const [sortKey, _setSortKey] = React.useState("rating");
@ -74,6 +87,7 @@ const GalleryPage = ({ data }) => {
el.scrollIntoView({
block: "center",
});
window.addEventListener("wheel", removeHash);
}, [hash]);
React.useEffect(() => {