Skip to content

armgit / ente

Public Imported from GitHub
0

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

wip: checkpoint

Manav Rathia6611e9631a1
diff --git a/web/apps/photos/src/pages/gallery.tsx b/web/apps/photos/src/pages/gallery.tsx
index 009a3b0089..7b9925dfeb 100644
--- a/web/apps/photos/src/pages/gallery.tsx
+++ b/web/apps/photos/src/pages/gallery.tsx
@@ -49,6 +49,7 @@ import {
setSearchCollectionsAndFiles,
} from "@/new/photos/services/search";
import type { SearchOption } from "@/new/photos/services/search/types";
+import type { FamilyData } from "@/new/photos/services/user";
import { AppContext } from "@/new/photos/types/context";
import { ensure } from "@/utils/ensure";
import { wait } from "@/utils/promise";
@@ -136,7 +137,6 @@ import {
SetFilesDownloadProgressAttributes,
SetFilesDownloadProgressAttributesCreator,
} from "types/gallery";
-import { FamilyData } from "types/user";
import { checkSubscriptionPurchase } from "utils/billing";
import {
COLLECTION_OPS_TYPE,
@@ -191,7 +191,6 @@ export const GalleryContext = createContext<GalleryContextType>(
*/
export default function Gallery() {
const [state, dispatch] = useGalleryReducer();
- const [user, setUser] = useState(null);
const [familyData, setFamilyData] = useState<FamilyData>(null);
const [collections, setCollections] = useState<Collection[]>(null);
const [hiddenCollections, setHiddenCollections] =
diff --git a/web/apps/photos/src/services/collectionService.ts b/web/apps/photos/src/services/collectionService.ts
index 998a75603e..13e2d432f6 100644
--- a/web/apps/photos/src/services/collectionService.ts
+++ b/web/apps/photos/src/services/collectionService.ts
@@ -29,6 +29,7 @@ import {
import { groupFilesBasedOnCollectionID } from "@/new/photos/services/file";
import { getLocalFiles, sortFiles } from "@/new/photos/services/files";
import { updateMagicMetadata } from "@/new/photos/services/magic-metadata";
+import type { FamilyData } from "@/new/photos/services/user";
import { batch } from "@/utils/array";
import { CustomError } from "@ente/shared/error";
import HTTPService from "@ente/shared/network/HTTPService";
@@ -37,7 +38,6 @@ import { LS_KEYS, getData } from "@ente/shared/storage/localStorage";
import { getToken } from "@ente/shared/storage/localStorage/helpers";
import { getActualKey } from "@ente/shared/user";
import type { User } from "@ente/shared/user/types";
-import { FamilyData } from "types/user";
import {
changeCollectionSubType,
getHiddenCollections,
diff --git a/web/apps/photos/src/types/user/index.ts b/web/apps/photos/src/types/user/index.ts
index 2b6c4ff45e..0073740d09 100644
--- a/web/apps/photos/src/types/user/index.ts
+++ b/web/apps/photos/src/types/user/index.ts
@@ -1,17 +1,5 @@
import { Subscription } from "types/billing";
-export interface FamilyMember {
- email: string;
- usage: number;
- id: string;
- isAdmin: boolean;
-}
-
-export interface FamilyData {
- storage: number;
- expiry: number;
- members: FamilyMember[];
-}
export interface Bonus {
storage: number;
diff --git a/web/apps/photos/src/utils/user/family.ts b/web/apps/photos/src/utils/user/family.ts
index 68d17ece07..80a1528766 100644
--- a/web/apps/photos/src/utils/user/family.ts
+++ b/web/apps/photos/src/utils/user/family.ts
@@ -1,7 +1,7 @@
import log from "@/base/log";
import { LS_KEYS, getData } from "@ente/shared/storage/localStorage";
import type { User } from "@ente/shared/user/types";
-import { FamilyData, FamilyMember } from "types/user";
+import type { FamilyData, FamilyMember } from "@/new/photos/services/user";
export function getLocalFamilyData(): FamilyData {
return getData(LS_KEYS.FAMILY_DATA);
diff --git a/web/packages/new/photos/components/gallery/reducer.ts b/web/packages/new/photos/components/gallery/reducer.ts
index baa5381438..3091ece7f1 100644
--- a/web/packages/new/photos/components/gallery/reducer.ts
+++ b/web/packages/new/photos/components/gallery/reducer.ts
@@ -39,6 +39,20 @@ import type { Person } from "../../services/ml/people";
* the UI state until the operation completes.
*/
export interface GalleryState {
+ /**
+ * The logged in {@link User}.
+ *
+ * This is expected to be undefined only for a brief duration until the code
+ * for the initial "mount" runs (If we're not logged in, then the gallery
+ * will redirect the user to an appropriate authentication page).
+ */
+ user: User | undefined;
+ /**
+ * Family plan related information for the logged in {@link User}.
+ */
+ familyData: Fami, setFamilyData] = useState<FamilyData>(null);
+
+
filteredData: EnteFile[];
/**
* File IDs of all the files that the user has marked as a favorite.
@@ -59,6 +73,10 @@ export interface GalleryState {
// TODO: dummy actions for gradual migration to reducers
export type GalleryAction =
+ | {
+ type: "mount",
+ user: User,
+ }
| {
type: "set";
filteredData: EnteFile[];
@@ -67,9 +85,12 @@ export type GalleryAction =
| undefined;
}
| { type: "setDerived"; favFileIDs: Set<number> }
- | { type: "setFavorites"; favFileIDs: Set<number> };
+ | { type: "setFavorites"; favFileIDs: Set<number> }
+ | { type: "setNormalAndHiddenCollections";
+ normalCollections: Collection[]; hiddenCollections: Collection[]; };
const initialGalleryState: GalleryState = {
+ user: undefined,
filteredData: [],
favFileIDs: new Set(),
activePerson: undefined,
@@ -81,6 +102,11 @@ const galleryReducer: React.Reducer<GalleryState, GalleryAction> = (
action,
) => {
switch (action.type) {
+ case "mount":
+ return {
+ ...state,
+ user: action.user
+ }
case "set":
return {
...state,
diff --git a/web/packages/new/photos/services/user.ts b/web/packages/new/photos/services/user.ts
new file mode 100644
index 0000000000..6e7b08611e
--- /dev/null
+++ b/web/packages/new/photos/services/user.ts
@@ -0,0 +1,12 @@
+export interface FamilyMember {
+ email: string;
+ usage: number;
+ id: string;
+ isAdmin: boolean;
+}
+
+export interface FamilyData {
+ storage: number;
+ expiry: number;
+ members: FamilyMember[];
+}