From dd96181ccfed4b3f1606e7b743a6c82797111e74 Mon Sep 17 00:00:00 2001 From: Scott Cazan Date: Wed, 3 Jul 2024 11:57:13 +0200 Subject: [PATCH] optimize for client-side rendering when in same space --- src/components/Search/SearchModal.tsx | 1 + src/components/Search/SearchPageResultItem.tsx | 11 ++++++++++- src/components/Search/SearchResults.tsx | 5 ++++- src/components/Search/SearchSectionResultItem.tsx | 11 ++++++++++- 4 files changed, 25 insertions(+), 3 deletions(-) diff --git a/src/components/Search/SearchModal.tsx b/src/components/Search/SearchModal.tsx index 50f91f4caf..6f6bf80eff 100644 --- a/src/components/Search/SearchModal.tsx +++ b/src/components/Search/SearchModal.tsx @@ -246,6 +246,7 @@ function SearchModalBody( global: state.global, }); }} + onClose={onClose} > {parent && state.query ? : null} diff --git a/src/components/Search/SearchPageResultItem.tsx b/src/components/Search/SearchPageResultItem.tsx index af0525c46b..82bed0abda 100644 --- a/src/components/Search/SearchPageResultItem.tsx +++ b/src/components/Search/SearchPageResultItem.tsx @@ -11,15 +11,24 @@ export const SearchPageResultItem = React.forwardRef(function SearchPageResultIt query: string; item: ComputedPageResult; active: boolean; + onClick?: (to: string) => void; }, ref: React.Ref, ) { - const { query, item, active } = props; + const { query, item, active, onClick } = props; return ( { + if (!onClick) { + return true; + } + + event.preventDefault(); + onClick(item.href); + }} className={tcls( 'flex', 'flex-row', diff --git a/src/components/Search/SearchResults.tsx b/src/components/Search/SearchResults.tsx index 113a390b07..779ec20c7d 100644 --- a/src/components/Search/SearchResults.tsx +++ b/src/components/Search/SearchResults.tsx @@ -43,10 +43,11 @@ export const SearchResults = React.forwardRef(function SearchResults( parent: Site | Collection | null; withAsk: boolean; onSwitchToAsk: () => void; + onClose: (to?: string) => void; }, ref: React.Ref, ) { - const { children, query, spaceId, revisionId, parent, withAsk, onSwitchToAsk } = props; + const { children, query, spaceId, revisionId, parent, withAsk, onSwitchToAsk, onClose } = props; const language = useLanguage(); const debounceTimeout = React.useRef(null); @@ -210,6 +211,7 @@ export const SearchResults = React.forwardRef(function SearchResults( query={query} item={item} active={index === cursor} + onClick={parent ? undefined : onClose} /> ); } @@ -250,6 +252,7 @@ export const SearchResults = React.forwardRef(function SearchResults( query={query} item={item} active={index === cursor} + onClick={parent ? undefined : onClose} /> ); } diff --git a/src/components/Search/SearchSectionResultItem.tsx b/src/components/Search/SearchSectionResultItem.tsx index b620a7651f..f2014728f8 100644 --- a/src/components/Search/SearchSectionResultItem.tsx +++ b/src/components/Search/SearchSectionResultItem.tsx @@ -11,15 +11,24 @@ export const SearchSectionResultItem = React.forwardRef(function SearchSectionRe query: string; item: ComputedSectionResult; active: boolean; + onClick?: (to: string) => void; }, ref: React.Ref, ) { - const { query, item, active } = props; + const { query, item, active, onClick } = props; return ( { + if (!onClick) { + return true; + } + + event.preventDefault(); + onClick(item.href); + }} className={tcls( 'search-section-result-item', '[&:has(+:not(&))]:mb-6',