From 5b2be09a6a44987dd4cf3fee3a5ed8a75410a0e8 Mon Sep 17 00:00:00 2001 From: Manav Rathi Date: Wed, 11 Sep 2024 19:56:51 +0530 Subject: [PATCH] To new --- .../new/photos/services/search/index.ts | 22 ++++--------------- .../new/photos/services/search/worker.ts | 13 +++++++++++ 2 files changed, 17 insertions(+), 18 deletions(-) diff --git a/web/packages/new/photos/services/search/index.ts b/web/packages/new/photos/services/search/index.ts index 25bdf5ce42..eb84ce3b33 100644 --- a/web/packages/new/photos/services/search/index.ts +++ b/web/packages/new/photos/services/search/index.ts @@ -166,7 +166,10 @@ const labelledFileTypes = (): LabelledFileType[] => [ export const getAutoCompleteSuggestions = (files: EnteFile[], collections: Collection[]) => async (searchPhrase: string): Promise => { - log.debug(() => ["getAutoCompleteSuggestions", { searchPhrase }]); + log.debug(() => [ + "getAutoCompleteSuggestions", + { searchPhrase, collections }, + ]); try { const searchPhrase2 = searchPhrase.trim().toLowerCase(); // eslint-disable-next-line @typescript-eslint/no-unnecessary-condition @@ -180,7 +183,6 @@ export const getAutoCompleteSuggestions = // - getLocationSuggestion(searchPhrase), // - getFileTypeSuggestion(searchPhrase), ...(await createSearchQuery(searchPhrase)), - ...getCollectionSuggestion(searchPhrase2, collections), getFileNameSuggestion(searchPhrase2, files), getFileCaptionSuggestion(searchPhrase2, files), // eslint-disable-next-line @typescript-eslint/no-unnecessary-condition @@ -219,22 +221,6 @@ async function convertSuggestionsToOptions( return previewImageAppendedOptions; } -function getCollectionSuggestion( - searchPhrase: string, - collections: Collection[], -): Suggestion[] { - const collectionResults = searchCollection(searchPhrase, collections); - - return collectionResults.map( - (searchResult) => - ({ - type: SuggestionType.COLLECTION, - value: searchResult.id, - label: searchResult.name, - }) as Suggestion, - ); -} - function getFileNameSuggestion( searchPhrase: string, files: EnteFile[], diff --git a/web/packages/new/photos/services/search/worker.ts b/web/packages/new/photos/services/search/worker.ts index 8b3c57dce9..d45c85bf24 100644 --- a/web/packages/new/photos/services/search/worker.ts +++ b/web/packages/new/photos/services/search/worker.ts @@ -1,5 +1,6 @@ import { HTTPError } from "@/base/http"; import type { Location } from "@/base/types"; +import type { Collection } from "@/media/collection"; import { fileCreationPhotoDate, fileLocation } from "@/media/file-metadata"; import type { EnteFile } from "@/new/photos/types/file"; import { nullToUndefined } from "@/utils/transform"; @@ -73,6 +74,7 @@ export class SearchWorker { createSearchQuery(s: string, localizedSearchData: LocalizedSearchData) { return createSearchQuery( s, + this.searchableData, localizedSearchData, this.locationTags, this.cities, @@ -93,16 +95,27 @@ expose(SearchWorker); const createSearchQuery = ( s: string, + { collections }: SearchableData, { locale, holidays, labelledFileTypes }: LocalizedSearchData, locationTags: Searchable[], cities: Searchable[], ): Suggestion[] => [ + collectionSuggestions(s, collections), dateSuggestions(s, locale, holidays), locationSuggestions(s, locationTags, cities), fileTypeSuggestions(s, labelledFileTypes), ].flat(); +const collectionSuggestions = (s: string, collections: Collection[]) => + collections + .filter(({ name }) => name.toLowerCase().includes(s)) + .map(({ id, name }) => ({ + type: SuggestionType.COLLECTION, + value: id, + label: name, + })); + const dateSuggestions = ( s: string, locale: string,