From d24ffecf7ca277635a527f0be5f36c7fa37ee70e Mon Sep 17 00:00:00 2001 From: Chuck Dries Date: Thu, 9 Mar 2023 21:31:54 -0800 Subject: [PATCH] fix deselect in keyword picker --- src/components/KeywordsPicker.tsx | 4 ++-- src/pages/photogallery.tsx | 34 ++++++++++++++----------------- 2 files changed, 17 insertions(+), 21 deletions(-) diff --git a/src/components/KeywordsPicker.tsx b/src/components/KeywordsPicker.tsx index e0cd75f..4aa0283 100644 --- a/src/components/KeywordsPicker.tsx +++ b/src/components/KeywordsPicker.tsx @@ -5,7 +5,7 @@ import { Link } from "gatsby"; interface KeywordsPickerProps { keywords: string[]; value: string | null; - getHref: (value: string | null) => string; + getHref: (value: string | null, selected: boolean) => string; onPick: (value: string | null) => void; } const KeywordsPicker = ({ keywords, value, getHref, onPick }: KeywordsPickerProps) => { @@ -28,7 +28,7 @@ const KeywordsPicker = ({ keywords, value, getHref, onPick }: KeywordsPickerProp )} onClick={() => onPick(keyword)} replace={false} - to={getHref(keyword)} + to={getHref(keyword, selected)} > {keyword}{" "} diff --git a/src/pages/photogallery.tsx b/src/pages/photogallery.tsx index bcd91e7..bc2e6f7 100644 --- a/src/pages/photogallery.tsx +++ b/src/pages/photogallery.tsx @@ -54,20 +54,17 @@ const GalleryPage = ({ const showDebug = Boolean(params.get("debug")?.length); const [showPalette, setShowPalette] = React.useState(false); - const onKeywordPick = React.useCallback( - (newKeyword: string | null) => { - if (newKeyword) { - try { - window.plausible("Filter Keyword", { - props: { keyword: newKeyword }, - }); - } catch (e) { - // do nothing - } + const onKeywordPick = React.useCallback((newKeyword: string | null) => { + if (newKeyword) { + try { + window.plausible("Filter Keyword", { + props: { keyword: newKeyword }, + }); + } catch (e) { + // do nothing } - }, - [] - ); + } + }, []); const setSortKey = React.useCallback( (newSortKey: string) => { @@ -121,7 +118,7 @@ const GalleryPage = ({ console.log("⚠️failed to find hash"); return; } - console.log('scrolling into view manually') + console.log("scrolling into view manually"); el.scrollIntoView({ block: hash.startsWith("all") ? "start" : "center", }); @@ -254,11 +251,10 @@ const GalleryPage = ({
- getGalleryPageUrl( - { keyword: val, sortKey, showDebug }, - hash - ) + getHref={(val, selected) => + selected + ? getGalleryPageUrl({ keyword: null, sortKey, showDebug }, hash) + : getGalleryPageUrl({ keyword: val, sortKey, showDebug }, hash) } keywords={[ "Boyce Thompson Arboretum",