Skip to content

Commit 831215c

Browse files
committed
Fix Question Not Being Updated Bug
1 parent 1e76297 commit 831215c

File tree

2 files changed

+17
-13
lines changed

2 files changed

+17
-13
lines changed

Frontend/src/Components/QuestionList/QuestionEdit.jsx

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -42,19 +42,22 @@ export const QuestionEdit = ({ q, index, updateQ, setEdit }) => {
4242
}
4343
};
4444

45-
const handleSubmit = (toggleEdit, editQ) => async e => {
46-
e.preventDefault();
45+
const handleSubmit = async (toggleEdit, editQ) => {
46+
// e.preventDefault();
4747
if(isEmpty(title) || isEmpty(difficulty) || isEmpty(topic) || isEmpty(description)) {
48-
setIsMissingField(true);
48+
setIsMissingField(true);
4949
} else {
50-
setIsMissingField(false);
51-
const response = await editQ(q._id, title, description, difficulty, topic, language);
52-
if(response.status === 200) {
53-
toggleEdit(false);
54-
} else {
55-
let res = await response.json();
56-
setErrorVar(res.errors)
57-
}
50+
51+
setIsMissingField(false);
52+
53+
const response = await editQ(q._id, title, description, difficulty, topic, language);
54+
55+
if(response.status === 200) {
56+
toggleEdit(false);
57+
} else {
58+
let res = await response.json();
59+
setErrorVar(res.errors)
60+
}
5861
}
5962
}
6063

@@ -94,6 +97,7 @@ export const QuestionEdit = ({ q, index, updateQ, setEdit }) => {
9497
<div className="btn-container">
9598
<button type = "cancel" className="cancel-btn" onClick = {(e)=> {setEdit(false)}}>Cancel</button>
9699
<button className="submit-btn" onClick = {(e) => {
100+
e.preventDefault();
97101
handleSubmit(setEdit, updateQ);
98102
}}>Submit
99103
</button>

Frontend/src/Components/QuestionList/QuestionList.jsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -86,8 +86,8 @@ export const Questions = () => {
8686

8787
if (response.status === 200) {
8888
setFilterApplied(false);
89-
fetchQuestions();
90-
return [];
89+
await fetchQuestions();
90+
return response;
9191
} else {
9292
return ['Unable to edit question'];
9393
}

0 commit comments

Comments
 (0)