fix: adding no backup preview condition

This commit is contained in:
Chubby Granny Chaser 2024-09-25 21:07:41 +01:00
parent 89b830fe9a
commit 3e165e05fb
No known key found for this signature in database
4 changed files with 20 additions and 36 deletions

View File

@ -33,9 +33,6 @@ const getNewProfileImageUrl = async (localImageUrl: string) => {
headers: {
"Content-Type": mimeType,
},
onUploadProgress: (progressEvent) => {
console.log(progressEvent);
},
});
return profileImageUrl;

View File

@ -25,7 +25,7 @@ export interface CloudSyncContext {
setShowCloudSyncModal: React.Dispatch<React.SetStateAction<boolean>>;
downloadGameArtifact: (gameArtifactId: string) => Promise<void>;
uploadSaveGame: () => Promise<void>;
deleteGameArtifact: (gameArtifactId: string) => Promise<{ ok: boolean }>;
deleteGameArtifact: (gameArtifactId: string) => Promise<void>;
restoringBackup: boolean;
uploadingBackup: boolean;
}
@ -39,7 +39,7 @@ export const cloudSyncContext = createContext<CloudSyncContext>({
downloadGameArtifact: async () => {},
uploadSaveGame: async () => {},
artifacts: [],
deleteGameArtifact: async () => ({ ok: false }),
deleteGameArtifact: async () => {},
restoringBackup: false,
uploadingBackup: false,
});
@ -135,20 +135,26 @@ export function CloudSyncContextProvider({
async (gameArtifactId: string) => {
return window.electron.deleteGameArtifact(gameArtifactId).then(() => {
getGameBackupPreview();
return { ok: true };
});
},
[getGameBackupPreview]
);
useEffect(() => {
getGameBackupPreview();
window.electron.checkGameCloudSyncSupport(objectId, shop).then((result) => {
setSupportsCloudSync(result);
});
}, [objectId, shop, getGameBackupPreview]);
useEffect(() => {
setBackupPreview(null);
setArtifacts([]);
setSupportsCloudSync(null);
setShowCloudSyncModal(false);
setRestoringBackup(false);
setUploadingBackup(false);
}, [objectId, shop]);
useEffect(() => {
if (showCloudSyncModal) {
getGameBackupPreview();

View File

@ -46,32 +46,9 @@ export function useUserDetails() {
const updateUserDetails = useCallback(
async (userDetails: UserDetails) => {
dispatch(setUserDetails(userDetails));
if (userDetails.profileImageUrl) {
// TODO: Decide if we want to use this
// const profileBackground = await profileBackgroundFromProfileImage(
// userDetails.profileImageUrl
// ).catch((err) => {
// logger.error("profileBackgroundFromProfileImage", err);
// return `#151515B3`;
// });
// dispatch(setProfileBackground(profileBackground));
window.localStorage.setItem(
"userDetails",
JSON.stringify({ ...userDetails, profileBackground })
);
} else {
const profileBackground = `#151515B3`;
dispatch(setProfileBackground(profileBackground));
window.localStorage.setItem(
"userDetails",
JSON.stringify({ ...userDetails, profileBackground })
);
}
window.localStorage.setItem("userDetails", JSON.stringify(userDetails));
},
[dispatch, profileBackground]
[dispatch]
);
const fetchUserDetails = useCallback(async () => {

View File

@ -87,8 +87,12 @@ export function CloudSyncModal({ visible, onClose }: CloudSyncModalProps) {
);
}
return "no_backups";
}, [uploadingBackup, lastBackup, restoringBackup]);
if (!backupPreview) {
return "no_backup_preview";
}
return "no_artifacts";
}, [uploadingBackup, lastBackup, backupPreview, restoringBackup]);
const disableActions = uploadingBackup || restoringBackup || deletingArtifact;
@ -116,7 +120,7 @@ export function CloudSyncModal({ visible, onClose }: CloudSyncModalProps) {
<Button
type="button"
onClick={uploadSaveGame}
disabled={disableActions}
disabled={disableActions || !backupPreview}
>
<UploadIcon />
create_backup