This commit is contained in:
Manav Rathi
2024-09-18 11:53:27 +05:30
parent d62ca44675
commit 1521971a5d

View File

@@ -28,6 +28,8 @@ import type {
SearchSuggestion,
} from "./types";
type SearchableCGroup = Searchable<Omit<CGroup, "name"> & { name: string }>;
/**
* A web worker that runs the search asynchronously so that the main thread
* remains responsive.
@@ -39,9 +41,7 @@ export class SearchWorker {
collections: [],
files: [],
};
private searchableCGroups: Searchable<
Omit<CGroup, "name"> & { name: string }
>[] = [];
private searchableCGroups: SearchableCGroup[] = [];
/**
* Fetch any state we might need when the actual search happens.
@@ -102,6 +102,7 @@ export class SearchWorker {
s,
searchString,
this.searchableCollectionsAndFiles,
this.searchableCGroups,
localizedSearchData,
this.locationTags,
this.cities,
@@ -139,12 +140,14 @@ const suggestionsForString = (
s: string,
searchString: string,
{ collections, files }: SearchableCollectionsAndFiles,
searchableCGroups: SearchableCGroup[],
{ locale, holidays, labelledFileTypes }: LocalizedSearchData,
locationTags: Searchable<LocationTag>[],
cities: Searchable<City>[],
): SearchSuggestion[] =>
[
// <-- caption suggestions will be inserted here by our caller.
// . <-- clip suggestions will be inserted here by our caller.
peopleSuggestions(s, searchableCGroups),
fileTypeSuggestions(s, labelledFileTypes),
dateSuggestions(s, locale, holidays),
locationSuggestions(s, locationTags, cities),
@@ -211,6 +214,24 @@ const fileCaptionSuggestion = (
: [];
};
const peopleSuggestions = (
s: string,
searchableCGroups: SearchableCGroup[],
): SearchSuggestion[] => {
// Suppress the unused warning during WIP
if (process.env.NEXT_PUBLIC_ENTE_WIP_CL) {
console.log({ s, searchableCGroups });
}
return [];
// searchableCGroups
// .filter(({ lowercasedName }) => lowercasedName.startsWith(s))
// .map((scgroup) => ({
// type: "person",
// person: scgroup,
// label: scgroup.name,
// }));
};
const dateSuggestions = (
s: string,
locale: string,