Store photo gallery sort and filter in URL

This commit is contained in:
2022-07-10 15:31:01 -07:00
parent fd4d148a07
commit 01d2452b12
3 changed files with 22 additions and 6 deletions

View File

@@ -7,6 +7,7 @@ import { Picker, Item } from "@adobe/react-spectrum";
import MasonryGallery from "../components/MasonryGallery";
import KeywordsPicker from "../components/KeywordsPicker";
import { useQueryParamString } from "react-use-query-param-string";
const SORT_KEYS = {
hue: ["fields", "imageMeta", "vibrantHue"],
@@ -16,8 +17,9 @@ const SORT_KEYS = {
};
const GalleryPage = ({ data }) => {
const [keyword, _setKeyword] = React.useState(null);
const [sortKey, _setSortKey] = React.useState("rating");
const [keyword, _setKeyword] = useQueryParamString("filter", null);
const [sortKey, _setSortKey] = useQueryParamString("sort", "rating");
const [showDebug, _setShowDebug] = useQueryParamString("debug", false);
const setKeyword = React.useCallback(
(keyword) => {
@@ -81,10 +83,6 @@ const GalleryPage = ({ data }) => {
[data, sortKey, keyword]
);
const showDebug =
typeof window !== "undefined" &&
window.location.search.includes("debug=true");
return (
<>
<Helmet>