fix: fixing multiple calls for backup

This commit is contained in:
Chubby Granny Chaser 2024-10-20 08:09:15 +01:00
parent 0e5d37a3a0
commit b7c9b5ec54
No known key found for this signature in database
10 changed files with 101 additions and 114 deletions

View file

@ -7,6 +7,7 @@ import React, {
useCallback,
useEffect,
useMemo,
useRef,
useState,
} from "react";
import { useTranslation } from "react-i18next";
@ -66,6 +67,8 @@ export function CloudSyncContextProvider({
}: CloudSyncContextProviderProps) {
const { t } = useTranslation("game_details");
const backupPreviewLock = useRef("");
const [artifacts, setArtifacts] = useState<GameArtifact[]>([]);
const [showCloudSyncModal, setShowCloudSyncModal] = useState(false);
const [backupPreview, setBackupPreview] = useState<LudusaviBackup | null>(
@ -86,26 +89,32 @@ export function CloudSyncContextProvider({
);
const getGameBackupPreview = useCallback(async () => {
await Promise.allSettled([
window.electron.getGameArtifacts(objectId, shop).then((results) => {
setArtifacts(results);
}),
window.electron
.getGameBackupPreview(objectId, shop)
.then((preview) => {
if (preview && Object.keys(preview.games).length) {
setBackupPreview(preview);
}
})
.catch((err) => {
logger.error(
"Failed to get game backup preview",
objectId,
shop,
err
);
const backupPreviewLockKey = `${objectId}-${shop}`;
if (backupPreviewLock.current !== backupPreviewLockKey) {
backupPreviewLock.current = backupPreviewLockKey;
await Promise.allSettled([
window.electron.getGameArtifacts(objectId, shop).then((results) => {
setArtifacts(results);
}),
]);
window.electron
.getGameBackupPreview(objectId, shop)
.then((preview) => {
backupPreviewLock.current = "";
if (preview && Object.keys(preview.games).length) {
setBackupPreview(preview);
}
})
.catch((err) => {
logger.error(
"Failed to get game backup preview",
objectId,
shop,
err
);
}),
]);
}
}, [objectId, shop]);
const uploadSaveGame = useCallback(

View file

@ -1,7 +1,7 @@
import { Button, Modal, ModalProps, TextField } from "@renderer/components";
import { Modal, ModalProps } from "@renderer/components";
import { useContext, useMemo } from "react";
import { cloudSyncContext } from "@renderer/context";
import { useTranslation } from "react-i18next";
// import { useTranslation } from "react-i18next";
export interface CloudSyncFilesModalProps
extends Omit<ModalProps, "children" | "title"> {}
@ -12,7 +12,7 @@ export function CloudSyncFilesModal({
}: CloudSyncFilesModalProps) {
const { backupPreview } = useContext(cloudSyncContext);
const { t } = useTranslation("game_details");
// const { t } = useTranslation("game_details");
const files = useMemo(() => {
if (!backupPreview) {
@ -27,24 +27,6 @@ export function CloudSyncFilesModal({
});
}, [backupPreview]);
const handleChangeExecutableLocation = async () => {
const path = await selectGameExecutable();
if (path) {
const gameUsingPath =
await window.electron.verifyExecutablePathInUse(path);
if (gameUsingPath) {
showErrorToast(
t("executable_path_in_use", { game: gameUsingPath.title })
);
return;
}
window.electron.updateExecutablePath(game.id, path).then(updateGame);
}
};
return (
<Modal
visible={visible}
@ -72,7 +54,7 @@ export function CloudSyncFilesModal({
))}
</div> */}
<TextField
{/* <TextField
// value={game.executablePath || ""}
readOnly
theme="dark"
@ -87,7 +69,7 @@ export function CloudSyncFilesModal({
{t("select_directory")}
</Button>
}
/>
/> */}
<table>
<thead>

View file

@ -1,9 +1,4 @@
import {
Button,
ConfirmationModal,
Modal,
ModalProps,
} from "@renderer/components";
import { Button, Modal, ModalProps } from "@renderer/components";
import { useContext, useEffect, useMemo, useState } from "react";
import { cloudSyncContext, gameDetailsContext } from "@renderer/context";

View file

@ -107,7 +107,7 @@ export function GameOptionsModal({
};
const shouldShowWinePrefixConfiguration =
window.electron.platform === "darwin";
window.electron.platform === "linux";
return (
<>

View file

@ -52,6 +52,8 @@ export const profileDisplayName = style({
display: "flex",
alignItems: "center",
position: "relative",
textShadow:
"0 0 40px rgb(0 0 0), 0 0 20px rgb(0 0 0 / 50%), 0 0 10px rgb(0 0 0 / 20%)",
});
export const heroPanel = style({