Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

VPS-79/Make scenario desync less frightening #251

Merged
merged 2 commits into from
Oct 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 11 additions & 4 deletions frontend/src/features/playScenario/PlayScenarioPage.jsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { useContext, useState, useEffect } from "react";
import { useParams, useHistory } from "react-router-dom";
import axios from "axios";
import toast from "react-hot-toast";

import AuthenticationContext from "context/AuthenticationContext";
import { usePost } from "hooks/crudHooks";
Expand Down Expand Up @@ -51,10 +52,18 @@ export default function PlayScenarioPage() {
const [addFlags, setAddFlags] = useState([]);
const [removeFlags, setRemoveFlags] = useState([]);

const reload = () => {
setPrevious(null);
history.replace(`/play/${scenarioId}/singleplayer`);
};

const handleError = (error) => {
if (!error) return;
if (error.status === 409) {
history.push(`/play/${scenarioId}/desync`);
reload();
toast.success(
"A move from somewhere else was made, but you're back on track!"
);
} else {
history.push(`/play/${scenarioId}/error`);
}
Expand Down Expand Up @@ -93,9 +102,7 @@ export default function PlayScenarioPage() {
return;
}

console.log("reset");
setPrevious(null);
history.replace(`/play/${scenarioId}/singleplayer`);
reload();
};

if (loading) return <LoadingPage text="Loading Scene..." />;
Expand Down
13 changes: 10 additions & 3 deletions frontend/src/features/playScenario/PlayScenarioPageMulti.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -69,10 +69,18 @@ export default function PlayScenarioPageMulti({ group }) {
const [removeFlags, setRemoveFlags] = useState([]);
const [resources, setResources] = useState([]);

const reload = () => {
setPrevious(null);
history.replace(`/play/${scenarioId}/multiplayer`);
};

const handleError = (error) => {
if (!error) return;
if (error.status === 409) {
history.push(`/play/${scenarioId}/desync`);
reload();
toast.success(
"Someone else made a move first, but you're back on track!"
);
} else if (error.status === 403) {
const roles = JSON.stringify(error.meta.roles_with_access);
history.push(`/play/${scenarioId}/invalid-role?roles=${roles}`);
Expand Down Expand Up @@ -115,8 +123,7 @@ export default function PlayScenarioPageMulti({ group }) {

setAddFlags([]);
setRemoveFlags([]);
setPrevious(null);
history.replace(`/play/${scenarioId}/multiplayer`);
reload();
} catch (error) {
console.error("Error during reset:", error);
}
Expand Down
41 changes: 0 additions & 41 deletions frontend/src/features/status/DesyncPage.jsx

This file was deleted.

Loading