Skip to content

Commit

Permalink
optimize for client-side rendering when in same space
Browse files Browse the repository at this point in the history
  • Loading branch information
scazan committed Jul 3, 2024
1 parent 9f5b3f7 commit dd96181
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 3 deletions.
1 change: 1 addition & 0 deletions src/components/Search/SearchModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -246,6 +246,7 @@ function SearchModalBody(
global: state.global,
});
}}
onClose={onClose}
>
{parent && state.query ? <SearchScopeToggle spaceTitle={spaceTitle} /> : null}
</SearchResults>
Expand Down
11 changes: 10 additions & 1 deletion src/components/Search/SearchPageResultItem.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,24 @@ export const SearchPageResultItem = React.forwardRef(function SearchPageResultIt
query: string;
item: ComputedPageResult;
active: boolean;
onClick?: (to: string) => void;
},
ref: React.Ref<HTMLAnchorElement>,
) {
const { query, item, active } = props;
const { query, item, active, onClick } = props;

return (
<Link
ref={ref}
href={item.href}
onClick={(event) => {
if (!onClick) {
return true;
}

event.preventDefault();
onClick(item.href);
}}
className={tcls(
'flex',
'flex-row',
Expand Down
5 changes: 4 additions & 1 deletion src/components/Search/SearchResults.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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<SearchResultsRef>,
) {
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<NodeJS.Timeout | null>(null);
Expand Down Expand Up @@ -210,6 +211,7 @@ export const SearchResults = React.forwardRef(function SearchResults(
query={query}
item={item}
active={index === cursor}
onClick={parent ? undefined : onClose}
/>
);
}
Expand Down Expand Up @@ -250,6 +252,7 @@ export const SearchResults = React.forwardRef(function SearchResults(
query={query}
item={item}
active={index === cursor}
onClick={parent ? undefined : onClose}
/>
);
}
Expand Down
11 changes: 10 additions & 1 deletion src/components/Search/SearchSectionResultItem.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,24 @@ export const SearchSectionResultItem = React.forwardRef(function SearchSectionRe
query: string;
item: ComputedSectionResult;
active: boolean;
onClick?: (to: string) => void;
},
ref: React.Ref<HTMLAnchorElement>,
) {
const { query, item, active } = props;
const { query, item, active, onClick } = props;

return (
<Link
ref={ref}
href={item.href}
onClick={(event) => {
if (!onClick) {
return true;
}

event.preventDefault();
onClick(item.href);
}}
className={tcls(
'search-section-result-item',
'[&:has(+:not(&))]:mb-6',
Expand Down

0 comments on commit dd96181

Please sign in to comment.