Skip to content

armgit / ente

Public Imported from GitHub
0

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

Also pass collections

Manav Rathibf001794b418
diff --git a/web/apps/photos/src/pages/gallery.tsx b/web/apps/photos/src/pages/gallery.tsx
index 0b33378521..64405dd4ff 100644
--- a/web/apps/photos/src/pages/gallery.tsx
+++ b/web/apps/photos/src/pages/gallery.tsx
@@ -11,7 +11,7 @@ import {
getLocalTrashedFiles,
} from "@/new/photos/services/files";
import { wipHasSwitchedOnceCmpAndSet } from "@/new/photos/services/ml";
-import { search, setSearchableFiles } from "@/new/photos/services/search";
+import { search, setSearchableData } from "@/new/photos/services/search";
import {
SearchQuery,
SearchResultSummary,
@@ -407,8 +407,11 @@ export default function Gallery() {
};
}, []);
- // TODO: Is this uniquing necessary? Doesn't seem like.
- useEffect(() => setSearchableFiles(getUniqueFiles(files)), [files]);
+ useEffect(
+ // TODO: Try to set things up so that this uniquing is not needed.
+ () => setSearchableData({ collections, files: getUniqueFiles(files) }),
+ [collections, files],
+ );
useEffect(() => {
if (!user || !files || !collections || !hiddenFiles || !trashedFiles) {
diff --git a/web/packages/new/photos/services/search/index.ts b/web/packages/new/photos/services/search/index.ts
index 9f90d3bd6b..25bdf5ce42 100644
--- a/web/packages/new/photos/services/search/index.ts
+++ b/web/packages/new/photos/services/search/index.ts
@@ -8,19 +8,20 @@ import type { LocationTag } from "@/new/photos/services/user-entity";
import i18n, { t } from "i18next";
import type { EnteFile } from "../../types/file";
import { clipMatches, isMLEnabled } from "../ml";
-import {
- SuggestionType,
- type City,
- type ClipSearchScores,
- type DateSearchResult,
- type LabelledFileType,
- type LocalizedSearchData,
- type SearchDateComponents,
- type SearchOption,
- type SearchPerson,
- type SearchQuery,
- type Suggestion,
+import type {
+ City,
+ ClipSearchScores,
+ DateSearchResult,
+ LabelledFileType,
+ LocalizedSearchData,
+ SearchableData,
+ SearchDateComponents,
+ SearchOption,
+ SearchPerson,
+ SearchQuery,
+ Suggestion,
} from "./types";
+import { SuggestionType } from "./types";
import type { SearchWorker } from "./worker";
/**
@@ -61,10 +62,10 @@ export const triggerSearchDataSync = () =>
void worker().then((w) => masterKeyFromSession().then((k) => w.sync(k)));
/**
- * Set the files over which we will search.
+ * Set the collections and files over which we should search.
*/
-export const setSearchableFiles = (enteFiles: EnteFile[]) =>
- void worker().then((w) => w.setEnteFiles(enteFiles));
+export const setSearchableData = (data: SearchableData) =>
+ void worker().then((w) => w.setSearchableData(data));
/**
* Convert a search string into a reusable "search query" that can be passed on
diff --git a/web/packages/new/photos/services/search/types.ts b/web/packages/new/photos/services/search/types.ts
index b375c05aeb..2ef199d736 100644
--- a/web/packages/new/photos/services/search/types.ts
+++ b/web/packages/new/photos/services/search/types.ts
@@ -4,10 +4,19 @@
*/
import type { Location } from "@/base/types";
+import type { Collection } from "@/media/collection";
import { FileType } from "@/media/file-type";
import type { EnteFile } from "@/new/photos/types/file";
import type { LocationTag } from "../user-entity";
+/**
+ * The base data over which we should search.
+ */
+export interface SearchableData {
+ collections: Collection[];
+ files: EnteFile[];
+}
+
export interface DateSearchResult {
components: SearchDateComponents;
label: string;
diff --git a/web/packages/new/photos/services/search/worker.ts b/web/packages/new/photos/services/search/worker.ts
index 735bd9c035..8b3c57dce9 100644
--- a/web/packages/new/photos/services/search/worker.ts
+++ b/web/packages/new/photos/services/search/worker.ts
@@ -19,6 +19,7 @@ import type {
LabelledFileType,
LocalizedSearchData,
Searchable,
+ SearchableData,
SearchDateComponents,
SearchQuery,
Suggestion,
@@ -30,7 +31,7 @@ import { SuggestionType } from "./types";
* remains responsive.
*/
export class SearchWorker {
- private enteFiles: EnteFile[] = [];
+ private searchableData: SearchableData = { collections: [], files: [] };
private locationTags: Searchable<LocationTag>[] = [];
private cities: Searchable<City>[] = [];
@@ -60,10 +61,10 @@ export class SearchWorker {
}
/**
- * Set the files that we should search across.
+ * Set the data that we should search across.
*/
- setEnteFiles(enteFiles: EnteFile[]) {
- this.enteFiles = enteFiles;
+ setSearchableData(data: SearchableData) {
+ this.searchableData = data;
}
/**
@@ -82,7 +83,9 @@ export class SearchWorker {
* Return {@link EnteFile}s that satisfy the given {@link searchQuery}.
*/
search(searchQuery: SearchQuery) {
- return this.enteFiles.filter((f) => isMatchingFile(f, searchQuery));
+ return this.searchableData.files.filter((f) =>
+ isMatchingFile(f, searchQuery),
+ );
}
}