This commit is contained in:
Manav Rathi
2024-10-19 13:34:09 +05:30
parent a6611e9631
commit 18ebc485df
3 changed files with 22 additions and 15 deletions

View File

@@ -49,7 +49,6 @@ 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";
@@ -191,7 +190,6 @@ export const GalleryContext = createContext<GalleryContextType>(
*/
export default function Gallery() {
const [state, dispatch] = useGalleryReducer();
const [familyData, setFamilyData] = useState<FamilyData>(null);
const [collections, setCollections] = useState<Collection[]>(null);
const [hiddenCollections, setHiddenCollections] =
useState<Collection[]>(null);
@@ -351,6 +349,10 @@ export default function Gallery() {
const { show: showWhatsNew, props: whatsNewVisibilityProps } =
useModalVisibility();
// TODO: Temp
const user = state.user;
const familyData = state.familyData;
const router = useRouter();
// Ensure that the keys in local storage are not malformed by verifying that
@@ -403,8 +405,7 @@ export default function Gallery() {
await splitNormalAndHiddenCollections(collections);
const trashedFiles = await getLocalTrashedFiles();
setUser(user);
setFamilyData(familyData);
dispatch({ type: "mount", user, familyData });
setFiles(files);
setTrashedFiles(trashedFiles);
setHiddenFiles(hiddenFiles);

View File

@@ -1,6 +1,6 @@
import type { FamilyData } from "@/new/photos/services/user";
import { Subscription } from "types/billing";
export interface Bonus {
storage: number;
type: string;

View File

@@ -29,6 +29,7 @@ import {
isPinnedCollection,
} from "../../services/magic-metadata";
import type { Person } from "../../services/ml/people";
import type { FamilyData } from "../../services/user";
/**
* Derived UI state backing the gallery.
@@ -50,8 +51,7 @@ export interface GalleryState {
/**
* Family plan related information for the logged in {@link User}.
*/
familyData: Fami, setFamilyData] = useState<FamilyData>(null);
familyData: FamilyData | undefined;
filteredData: EnteFile[];
/**
@@ -74,9 +74,10 @@ export interface GalleryState {
// TODO: dummy actions for gradual migration to reducers
export type GalleryAction =
| {
type: "mount",
user: User,
}
type: "mount";
user: User;
familyData: FamilyData;
}
| {
type: "set";
filteredData: EnteFile[];
@@ -85,12 +86,16 @@ export type GalleryAction =
| undefined;
}
| { type: "setDerived"; favFileIDs: Set<number> }
| { type: "setFavorites"; favFileIDs: Set<number> }
| { type: "setNormalAndHiddenCollections";
normalCollections: Collection[]; hiddenCollections: Collection[]; };
| { type: "setFavorites"; favFileIDs: Set<number> };
// | {
// type: "setNormalAndHiddenCollections";
// normalCollections: Collection[];
// hiddenCollections: Collection[];
// };
const initialGalleryState: GalleryState = {
user: undefined,
familyData: undefined,
filteredData: [],
favFileIDs: new Set(),
activePerson: undefined,
@@ -105,8 +110,9 @@ const galleryReducer: React.Reducer<GalleryState, GalleryAction> = (
case "mount":
return {
...state,
user: action.user
}
user: action.user,
familyData: action.familyData,
};
case "set":
return {
...state,