Skip to content

armgit / ente

Public Imported from GitHub
0

πŸ’š End-to-end encrypted cloud for everything.

Add a workaround

Manav Rathi1c74eae13244
diff --git a/web/packages/new/photos/services/ml/index.ts b/web/packages/new/photos/services/ml/index.ts
index 101d33da91..dd1455fa6a 100644
--- a/web/packages/new/photos/services/ml/index.ts
+++ b/web/packages/new/photos/services/ml/index.ts
@@ -551,11 +551,10 @@ const updatePeople = async () => {
const people = await reconstructPeople();
// Notify the search subsystem of the update (search only uses named ones).
- // See: [Note: strict mode migration]
- //
- // eslint-disable-next-line @typescript-eslint/ban-ts-comment
- // @ts-ignore
- setSearchPeople(people.filter((p) => typeof p.name !== "undefined"));
+ const namedPeople = people
+ .map((p) => (p.name ? { name: p.name, person: p } : undefined))
+ .filter((p) => !!p);
+ setSearchPeople(namedPeople);
// Update our in-memory list of people.
setPeopleSnapshot(people);
diff --git a/web/packages/new/photos/services/ml/people.ts b/web/packages/new/photos/services/ml/people.ts
index 7770cbd096..b4b6cb18d0 100644
--- a/web/packages/new/photos/services/ml/people.ts
+++ b/web/packages/new/photos/services/ml/people.ts
@@ -131,10 +131,6 @@ export type Person = (
displayFaceFile: EnteFile;
};
-export type NamedPerson = Omit<Person, "name"> & {
- name: string;
-};
-
/**
* Construct in-memory people using the data present locally, ignoring faces
* belonging to deleted and hidden files.
diff --git a/web/packages/new/photos/services/search/index.ts b/web/packages/new/photos/services/search/index.ts
index 07e3cd326d..e18b91f837 100644
--- a/web/packages/new/photos/services/search/index.ts
+++ b/web/packages/new/photos/services/search/index.ts
@@ -4,12 +4,12 @@ import { ComlinkWorker } from "@/base/worker/comlink-worker";
import { FileType } from "@/media/file-type";
import i18n, { t } from "i18next";
import { clipMatches, isMLEnabled, isMLSupported } from "../ml";
-import type { NamedPerson } from "../ml/people";
import type {
LabelledFileType,
LabelledSearchDateComponents,
LocalizedSearchData,
SearchCollectionsAndFiles,
+ SearchPerson,
SearchSuggestion,
} from "./types";
import type { SearchWorker } from "./worker";
@@ -60,7 +60,7 @@ export const setSearchCollectionsAndFiles = (cf: SearchCollectionsAndFiles) =>
/**
* Set the (named) people that we should search across.
*/
-export const setSearchPeople = (people: NamedPerson[]) =>
+export const setSearchPeople = (people: SearchPerson[]) =>
void worker().then((w) => w.setPeople(people));
/**
diff --git a/web/packages/new/photos/services/search/types.ts b/web/packages/new/photos/services/search/types.ts
index 9c9123366f..49b2c35839 100644
--- a/web/packages/new/photos/services/search/types.ts
+++ b/web/packages/new/photos/services/search/types.ts
@@ -114,3 +114,16 @@ export type City = Location & {
/** Name of the city. */
name: string;
};
+
+export type NamedPerson = Person & {
+ name: string;
+};
+
+/**
+ * What we want is NamedPerson, but I can't get it to TypeScript to accept it in
+ * our usage contexts. This is a workaround.
+ */
+export interface SearchPerson {
+ person: Person;
+ name: string;
+}
diff --git a/web/packages/new/photos/services/search/worker.ts b/web/packages/new/photos/services/search/worker.ts
index ed6b4df859..03e39c1d4c 100644
--- a/web/packages/new/photos/services/search/worker.ts
+++ b/web/packages/new/photos/services/search/worker.ts
@@ -2,7 +2,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 { NamedPerson } from "@/new/photos/services/ml/people";
import type { EnteFile } from "@/new/photos/types/file";
import { ensure } from "@/utils/ensure";
import { nullToUndefined } from "@/utils/transform";
@@ -23,6 +22,7 @@ import type {
LocalizedSearchData,
SearchCollectionsAndFiles,
SearchDateComponents,
+ SearchPerson,
SearchSuggestion,
} from "./types";
@@ -37,7 +37,7 @@ export class SearchWorker {
collections: [],
files: [],
};
- private people: NamedPerson[] = [];
+ private people: SearchPerson[] = [];
/**
* Fetch any state we might need when the actual search happens.
@@ -64,7 +64,7 @@ export class SearchWorker {
/**
* Set the (named) people that we should search across.
*/
- setPeople(people: NamedPerson[]) {
+ setPeople(people: SearchPerson[]) {
this.people = people;
}
@@ -122,7 +122,7 @@ const suggestionsForString = (
re: RegExp,
searchString: string,
{ collections, files }: SearchCollectionsAndFiles,
- people: NamedPerson[],
+ people: SearchPerson[],
{ locale, holidays, labelledFileTypes }: LocalizedSearchData,
locationTags: LocationTag[],
cities: City[],
@@ -198,11 +198,11 @@ const fileCaptionSuggestion = (
const peopleSuggestions = (
re: RegExp,
- people: NamedPerson[],
+ people: SearchPerson[],
): SearchSuggestion[] =>
people
- .filter((p) => re.test(p.name))
- .map((person) => ({ type: "person", person, label: person.name }));
+ .filter((sp) => re.test(sp.name))
+ .map((sp) => ({ type: "person", person: sp.person, label: sp.name }));
const dateSuggestions = (
s: string,