diff --git a/src/components/PhotoFrame.tsx b/src/components/PhotoFrame.tsx index 5162cffd0..41f4b5567 100644 --- a/src/components/PhotoFrame.tsx +++ b/src/components/PhotoFrame.tsx @@ -192,6 +192,21 @@ const PhotoFrame = ({ ) { return false; } + if ( + search?.person && + search.person.files.indexOf(item.id) === -1 + ) { + return false; + } + if ( + search?.thing && + search.thing.files.indexOf(item.id) === -1 + ) { + return false; + } + if (search?.text && search.text.files.indexOf(item.id) === -1) { + return false; + } if ( !isDeduplicating && activeCollection === ALL_SECTION && @@ -203,25 +218,6 @@ const PhotoFrame = ({ if (activeCollection === ARCHIVE_SECTION && !IsArchived(item)) { return false; } - - if ( - search?.person && - search.person.files.indexOf(item.id) === -1 - ) { - return false; - } - - if ( - search?.thing && - search.thing.files.indexOf(item.id) === -1 - ) { - return false; - } - - if (search?.text && search.text.files.indexOf(item.id) === -1) { - return false; - } - if (isSharedFile(item) && !isSharedCollection) { return false; } diff --git a/src/components/Search/SearchBar/searchInput/index.tsx b/src/components/Search/SearchBar/searchInput/index.tsx index 883ad25ed..61b7d0abc 100644 --- a/src/components/Search/SearchBar/searchInput/index.tsx +++ b/src/components/Search/SearchBar/searchInput/index.tsx @@ -24,6 +24,7 @@ import { Collection } from 'types/collection'; import { OptionWithInfo } from './optionWithInfo'; import { SearchInputWrapper } from '../styledComponents'; import MenuWithPeople from './MenuWithPeople'; +import { Person, ThingClass, WordGroup } from 'types/machineLearning'; interface Iprops { isOpen: boolean; @@ -47,7 +48,7 @@ export default function SearchInput(props: Iprops) { useEffect(() => { const main = async () => { - const defaultOptions = await getDefaultOptions(); + const defaultOptions = await getDefaultOptions(props.files)(); setDefaultOptions(defaultOptions); }; main(); @@ -97,6 +98,14 @@ export default function SearchInput(props: Iprops) { search = { file: selectedOption.value as number }; setValue(null); break; + case SuggestionType.PERSON: + search = { person: selectedOption.value as Person }; + break; + case SuggestionType.THING: + search = { thing: selectedOption.value as ThingClass }; + break; + case SuggestionType.TEXT: + search = { text: selectedOption.value as WordGroup }; } props.updateSearch(search, { optionName: selectedOption.label, diff --git a/src/services/searchService.ts b/src/services/searchService.ts index 369012847..6e585df70 100644 --- a/src/services/searchService.ts +++ b/src/services/searchService.ts @@ -23,16 +23,17 @@ import ObjectService from './machineLearning/objectService'; import textService from './machineLearning/textService'; import { FILE_TYPE } from 'constants/file'; import { getFormattedDate, isInsideBox, isSameDayAnyYear } from 'utils/search'; +import { Person } from 'types/machineLearning'; const ENDPOINT = getEndpoint(); const DIGITS = new Set(['0', '1', '2', '3', '4', '5', '6', '7', '8', '9']); -export const getDefaultOptions = async () => { - return [ - await getIndexStatusSuggestion(), - ...(await getAllPeopleSuggestion()), - ]; +export const getDefaultOptions = (files: EnteFile[]) => async () => { + return convertSuggestionsToOptions( + [await getIndexStatusSuggestion(), ...(await getAllPeopleSuggestion())], + files + ); }; export const getAutoCompleteSuggestions = @@ -51,26 +52,33 @@ export const getAutoCompleteSuggestions = ...(await getLocationSuggestions(searchPhrase)), ]; - const previewImageAppendedOptions: SearchOption[] = suggestions - .map((suggestion) => ({ - suggestion, - searchQuery: convertSuggestionToSearchQuery(suggestion), - })) - .map(({ suggestion, searchQuery }) => { - const resultFiles = files.filter((file) => - isSearchedFile(file, searchQuery) - ); - return { - ...suggestion, - fileCount: resultFiles.length, - previewFiles: resultFiles.slice(0, 3), - }; - }) - .filter((option) => option.fileCount); - - return previewImageAppendedOptions; + return convertSuggestionsToOptions(suggestions, files); }; +function convertSuggestionsToOptions( + suggestions: Suggestion[], + files: EnteFile[] +) { + const previewImageAppendedOptions: SearchOption[] = suggestions + .map((suggestion) => ({ + suggestion, + searchQuery: convertSuggestionToSearchQuery(suggestion), + })) + .map(({ suggestion, searchQuery }) => { + const resultFiles = files.filter((file) => + isSearchedFile(file, searchQuery) + ); + return { + ...suggestion, + fileCount: resultFiles.length, + previewFiles: resultFiles.slice(0, 3), + }; + }) + .filter((option) => option.fileCount); + + return previewImageAppendedOptions; +} + function getHolidaySuggestion(searchPhrase: string): Suggestion[] { return [ { @@ -314,6 +322,17 @@ export function isSearchedFile(file: EnteFile, search: Search) { if (search?.collection) { return search.collection === file.collectionID; } + if (search?.person) { + return search.person.files.indexOf(file.id) !== -1; + } + + if (search?.thing) { + return search.thing.files.indexOf(file.id) !== -1; + } + + if (search?.text) { + return search.text.files.indexOf(file.id) !== -1; + } return false; } @@ -335,5 +354,8 @@ function convertSuggestionToSearchQuery(option: Suggestion): Search { case SuggestionType.IMAGE: case SuggestionType.VIDEO: return { file: option.value as number }; + + case SuggestionType.PERSON: + return { person: option.value as Person }; } }