Skip to content

armgit / ente

Public Imported from GitHub
0

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

Conv

Manav Rathic5afc6d45372
diff --git a/web/packages/new/photos/services/collections.ts b/web/packages/new/photos/services/collections.ts
index 3df9176ae7..be60fd6b1b 100644
--- a/web/packages/new/photos/services/collections.ts
+++ b/web/packages/new/photos/services/collections.ts
@@ -1,7 +1,11 @@
import { type Collection } from "ente-media/collection";
import localForage from "ente-shared/storage/localForage";
import { getCollections, isHiddenCollection } from "./collection";
-import { savedCollections } from "./photos-fdb";
+import {
+ savedCollections,
+ savedHiddenCollectionIDs,
+ saveHiddenCollectionIDs,
+} from "./photos-fdb";
const COLLECTION_TABLE = "collections";
const HIDDEN_COLLECTION_IDS = "hidden-collection-ids";
@@ -49,7 +53,7 @@ export const pullCollections = async (): Promise<Collection[]> => {
const changes = await getCollections(sinceTime);
if (!changes.length) return localCollections;
- const hiddenCollectionIDs = await getHiddenCollectionIDs();
+ const hiddenCollectionIDs = new Set(await savedHiddenCollectionIDs());
const collectionsByID = new Map(localCollections.map((c) => [c.id, c]));
for (const { id, updationTime, collection } of changes) {
@@ -58,7 +62,7 @@ export const pullCollections = async (): Promise<Collection[]> => {
if (collection) {
collectionsByID.set(id, collection);
- const wasHidden = hiddenCollectionIDs.includes(collection.id);
+ const wasHidden = hiddenCollectionIDs.has(collection.id);
const isHidden = isHiddenCollection(collection);
// If hidden state changes.
removeSyncTime = wasHidden != isHidden;
@@ -81,10 +85,7 @@ export const pullCollections = async (): Promise<Collection[]> => {
await localForage.setItem(COLLECTION_TABLE, collections);
await localForage.setItem(COLLECTION_UPDATION_TIME, sinceTime);
- await localForage.setItem(
- HIDDEN_COLLECTION_IDS,
- updatedHiddenCollectionIDs,
- );
+ await saveHiddenCollectionIDs(updatedHiddenCollectionIDs);
return collections;
};
diff --git a/web/packages/new/photos/services/photos-fdb.ts b/web/packages/new/photos/services/photos-fdb.ts
index bda1a82c50..a104799295 100644
--- a/web/packages/new/photos/services/photos-fdb.ts
+++ b/web/packages/new/photos/services/photos-fdb.ts
@@ -45,6 +45,28 @@ export const saveCollections = async (collections: Collection[]) => {
await localForage.setItem("collections", collections);
};
+/**
+ * Return the collectionIDs of hidden collections as per our local database.
+ *
+ * The returned value is an array for storage simplicity, but should be
+ * semantically be thought of as a set.
+ *
+ * Use {@link saveHiddenCollectionIDs} to update the database.
+ */
+export const savedHiddenCollectionIDs = async (): Promise<number[]> =>
+ z
+ .array(z.number())
+ .parse((await localForage.getItem("hidden-collection-ids")) ?? []);
+
+/**
+ * Replace the list of hidden collectionIDs stored in our local database.
+ *
+ * This is the setter corresponding to {@link savedHiddenCollectionIDs}.
+ */
+export const saveHiddenCollectionIDs = async (hs: number[]): Promise<void> => {
+ await localForage.setItem("hidden-collection-ids", hs);
+};
+
const TrashItemCollectionKey = z.object({
/**
* Collection ID.