fix: preserve upload progress across page navigation
This commit is contained in:
1 parent
ae8e175376
commit
fa82c99a52
5 files changed
+197
-37
No files matched your search
@@ -7,6 +7,7 @@ import { Cover, ErrorNote, Spinner } from "../ui/Bits";
|
||||
import { F95Fetch } from "../ui/F95Fetch";
|
||||
import { Icon } from "../ui/Icon";
|
||||
import { useUi } from "../ui/Ui";
|
||||
import { useUploads } from "../uploads";
|
||||
|
||||
const STATUS: Record<Version["status"], string> = {
|
||||
uploading: "Загружается",
|
||||
@@ -27,6 +28,7 @@ export function GamePage() {
|
||||
const { gameId } = useParams();
|
||||
const navigate = useNavigate();
|
||||
const ui = useUi();
|
||||
const { start: startUpload, tasks: uploads } = useUploads();
|
||||
const { me, can } = useAuth();
|
||||
const [game, setGame] = useState<GameDetail | null>(null);
|
||||
const [error, setError] = useState("");
|
||||
@@ -44,6 +46,11 @@ export function GamePage() {
|
||||
void load();
|
||||
}, [load]);
|
||||
|
||||
const uploadedVersions = uploads.filter((task) => task.gameId === Number(gameId) && task.version).map((task) => task.version!.id).join(",");
|
||||
useEffect(() => {
|
||||
if (uploadedVersions) void load();
|
||||
}, [uploadedVersions, load]);
|
||||
|
||||
// poll while something is being converted
|
||||
const busy = game?.versions.some((v) => BUSY.includes(v.status));
|
||||
useEffect(() => {
|
||||
@@ -122,8 +129,7 @@ export function GamePage() {
|
||||
confirmLabel: "Загрузить",
|
||||
});
|
||||
if (name)
|
||||
void run(() => uploadRaw("POST", `/api/games/${game.id}/upload?filename=${encodeURIComponent(file.name)}&name=${encodeURIComponent(name)}`,
|
||||
file, () => {}), "Архив загружен, началась конвертация");
|
||||
startUpload({ file, gameId: game.id, name });
|
||||
};
|
||||
|
||||
const removeVersion = async (v: Version) => {
|
||||
|
||||
Reference in new issue
Block a user