Skip to content

Commit

Permalink
⚠️Added toast warning if updating a question using mode random (#181)
Browse files Browse the repository at this point in the history
  • Loading branch information
Rllyyy committed Oct 13, 2022
1 parent ac45c27 commit 740cb83
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 5 deletions.
19 changes: 19 additions & 0 deletions cypress/e2e/updateQuestion.cy.js
Original file line number Diff line number Diff line change
Expand Up @@ -139,3 +139,22 @@ describe("Updating a Question using the Question editor", () => {
});
});
});

describe("Update question using mode random", () => {
beforeEach(() => {
cy.fixture("repeatio-module-cypress_1.json").then((value) => {
localStorage.setItem("repeatio-module-cypress_1", JSON.stringify(value));
});
cy.visit("/module/cypress_1");
cy.get("article[data-cy='Practice'").contains("button", "Random").click();
cy.get("button[aria-label='Edit Question']").click();
cy.get("div.ReactModal__Overlay").scrollIntoView();
});

it("should show warning if trying to update question", () => {
cy.contains("button", "Update").click();
cy.contains(
"Can't edit this questions while using mode random! Navigate to this question using the question overview."
).should("exist");
});
});
2 changes: 1 addition & 1 deletion src/components/Home/CreateModule.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -161,8 +161,8 @@ export const CreateModule = ({ handleModalClose }) => {
>
{/* language values are defined in ISO-639-1 */}
<option value=''></option>
<option value='de'>German</option>
<option value='en'>English</option>
<option value='de'>German</option>
</select>
</div>
{/* Compatibility Info (Version of repeatio) */}
Expand Down
20 changes: 16 additions & 4 deletions src/components/QuestionEditor/QuestionEditor.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -112,16 +112,28 @@ export const Form = ({ prevQuestionID, handleModalClose }) => {
//Return if there are any errors
if (Object.keys(errors).length > 0) return;

//Setup variables
hasSubmitted.current = true;
let onSubmitErrors = {};

if (isElectron()) {
toast.warn("Can't edit question in electron for this time. Use your browser instead!");
handleModalClose();
return;
}

//Don't allow question editing when using mode random
if (new URLSearchParams(search).get("mode") === "random") {
//TODO fix this
toast.warn(
"Can't edit this questions while using mode random! Navigate to this question using the question overview.",
{
autoClose: 12000,
}
);
return;
}

//Setup variables
hasSubmitted.current = true;
let onSubmitErrors = {};

//Prevent adding to types module as it is originally saved in the public folder
//Adding a question would create a module in the localStorage with the same id.
if (moduleData?.id === "types_1") {
Expand Down
1 change: 1 addition & 0 deletions src/components/toast/toast.css
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@

/* Set font size */
.Toastify__toast p,
.Toastify__toast .Toastify__toast-body span,
.Toastify__toast a span,
.Toastify__toast a {
font-size: 16px;
Expand Down

0 comments on commit 740cb83

Please sign in to comment.