fix person search file cout

This commit is contained in:
Abhinav 2022-08-02 15:58:55 +05:30
parent 7a5d6b89c7
commit 7e5cc6f793
3 changed files with 70 additions and 43 deletions

View file

@ -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;
}

View file

@ -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,

View file

@ -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,6 +52,13 @@ export const getAutoCompleteSuggestions =
...(await getLocationSuggestions(searchPhrase)),
];
return convertSuggestionsToOptions(suggestions, files);
};
function convertSuggestionsToOptions(
suggestions: Suggestion[],
files: EnteFile[]
) {
const previewImageAppendedOptions: SearchOption[] = suggestions
.map((suggestion) => ({
suggestion,
@ -69,7 +77,7 @@ export const getAutoCompleteSuggestions =
.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 };
}
}