Skip to content

Commit

Permalink
Merge pull request #1197 from mi6/fix-search-issues-preventing-local-…
Browse files Browse the repository at this point in the history
…build

Fix search issues preventing local build
  • Loading branch information
GCHQ-Developer-530 authored Nov 11, 2024
2 parents 1ccf6ae + 9045b13 commit c4d541c
Showing 1 changed file with 9 additions and 5 deletions.
14 changes: 9 additions & 5 deletions src/components/Search/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -86,15 +86,19 @@ const Search: React.FC = () => {
const onIcInput = async (
event: IcSearchBarCustomEvent<IcValueEventDetail>
) => {
const newValue = event.detail.value;
const newValue = Array.isArray(event.detail.value)
? event.detail.value.join(" ")
: event.detail.value;
const includesNewValue = (property?: string) =>
!!property?.toLowerCase().includes(newValue.toLowerCase());
typeof newValue === "string" &&
typeof property === "string" &&
property.toLowerCase().includes(newValue.toLowerCase());

if (idx && value !== newValue) {
setLoading(true);
const loaded = await idx.search(newValue, {});
const loaded = await idx.search({ query: newValue as string });
const mappedResults = loaded
.flatMap((loadedId) => {
.flatMap((loadedId: string | number) => {
const { path, title, id, tags, body, subTitle } = store[loadedId];
const isInTags = !!tags?.some((tag) => includesNewValue(tag));
const isInBody = includesNewValue(body);
Expand All @@ -113,7 +117,7 @@ const Search: React.FC = () => {
}
: [];
})
.sort((a, b) => {
.sort((a: SearchResult, b: SearchResult) => {
const getPriority = ({
label,
description,
Expand Down

0 comments on commit c4d541c

Please sign in to comment.