Skip to content

Commit

Permalink
fix: made frontend flags state reset
Browse files Browse the repository at this point in the history
  • Loading branch information
codecreator127 committed Sep 23, 2024
1 parent 66ccd5a commit bb02dd0
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 5 deletions.
13 changes: 9 additions & 4 deletions backend/src/routes/api/navigate/group.js
Original file line number Diff line number Diff line change
Expand Up @@ -213,6 +213,7 @@ export const groupNavigate = async (req) => {

export const groupReset = async (req) => {
const { uid, currentScene } = req.body;
const groupId = req.params.groupId;
const group = await getGroupByIdAndUser(req.params.groupId, uid);
if (!group) {
throw new HttpError("Group not found", STATUS.NOT_FOUND);
Expand All @@ -233,12 +234,16 @@ export const groupReset = async (req) => {
const hasReset = scene.components.some((c) => c.type === "RESET_BUTTON");
if (!hasReset) throw new HttpError("Invalid reset", STATUS.FORBIDDEN);

if (!(await deleteAllFlags(group)))
throw new HttpError("Failed to delete flags", STATUS.INTERNAL_SERVER_ERROR);
await Group.updateOne(
{ _id: groupId },
{ $set: { path: [], currentFlags: [] } }
).exec();

const groupTest = await Group.findById(groupId).lean();

if (!(await deleteAllPaths(group)))
throw new HttpError("Failed to delete paths", STATUS.INTERNAL_SERVER_ERROR);
console.log(groupTest);

console.log(`${Date.now()} reset done`)
return { status: STATUS.OK };
};

Expand Down
4 changes: 3 additions & 1 deletion frontend/src/features/playScenario/PlayScenarioPageMulti.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -107,12 +107,14 @@ export default function PlayScenarioPageMulti({ group }) {

const reset = async () => {
try {
const res = await usePost(
await usePost(
`api/navigate/group/reset/${group._id}`,
{ currentScene: sceneId },
user.getIdToken.bind(user)
);

setAddFlags([]);
setRemoveFlags([]);
setPrevious(null);
history.replace(`/play/${scenarioId}/multiplayer`);
} catch (error) {
Expand Down

0 comments on commit bb02dd0

Please sign in to comment.