This commit is contained in:
Manav Rathi
2025-07-03 15:21:17 +05:30
parent 5b7d4a8806
commit 6249211bca
2 changed files with 14 additions and 9 deletions

View File

@@ -108,8 +108,8 @@ import {
import type { SearchOption } from "ente-new/photos/services/search/types";
import { initSettings } from "ente-new/photos/services/settings";
import {
initUserDetailsOrTriggerPull,
redirectToCustomerPortal,
savedUserDetailsOrTriggerPull,
userDetailsSnapshot,
verifyStripeSubscription,
} from "ente-new/photos/services/user-details";
@@ -301,7 +301,6 @@ const Page: React.FC = () => {
// One time inits.
preloadImage("/images/subscription-card-background");
initSettings();
await initUserDetailsOrTriggerPull();
setupSelectAllKeyBoardShortcutHandler();
// Show the initial state while the rest of the sequence proceeds.
@@ -318,10 +317,12 @@ const Page: React.FC = () => {
}
// Initialize the reducer.
const user = ensureLocalUser();
const userDetails = await savedUserDetailsOrTriggerPull();
dispatch({
type: "mount",
user: ensureLocalUser(),
familyData: userDetailsSnapshot()?.familyData,
user,
familyData: userDetails?.familyData,
collections: await savedCollections(),
collectionFiles: await savedCollectionFiles(),
trashItems: await savedTrashItems(),

View File

@@ -177,18 +177,22 @@ export const logoutUserDetails = () => {
};
/**
* Read in the locally persisted settings into memory, otherwise initiate a
* network requests to fetch the latest values (but don't wait for it to
* complete).
* Read in the locally persisted user details into memory and return them.
*
* If there are no locally persisted values, initiate a network requests to
* fetch the latest values (but don't wait for it to complete).
*
* This assumes that the user is already logged in.
*/
export const initUserDetailsOrTriggerPull = async () => {
export const savedUserDetailsOrTriggerPull = async () => {
const saved = await getKV("userDetails");
if (saved) {
setUserDetailsSnapshot(UserDetails.parse(saved));
const userDetails = UserDetails.parse(saved);
setUserDetailsSnapshot(userDetails);
return userDetails;
} else {
void pullUserDetails();
return undefined;
}
};