Skip to content

Commit

Permalink
Merge pull request #14 from HusseinSafwan02/main
Browse files Browse the repository at this point in the history
Cleaned up code for submission for milestone-D2
  • Loading branch information
mayuanxin1234 authored Sep 30, 2024
2 parents 39aefd7 + 7d87e9a commit 1157fee
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 10 deletions.
11 changes: 5 additions & 6 deletions client/src/App.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,12 @@ import UpdateQuestionForm from "./components/UpdateQuestion/UpdateQuestionForm";

function App() {
const [questionList, setQuestionList] = useState("");
const [formType, setFormType] = useState("view"); // false = main view page. true = new qn form
const [formType, setFormType] = useState("view");
const [selectedQuestion, setSelectedQuestion] = useState(null);

const handleUpdateClick = (question) => {
setSelectedQuestion(question); // Set the selected question to update
setFormType("update"); // Show the form for updating
setSelectedQuestion(question);
setFormType("update");
};

const fetchQuestions = async () => {
Expand Down Expand Up @@ -83,12 +83,11 @@ function App() {

const handleTabChange = (event, newState) => {
if (newState === "view") {
// Ensure that we reset everything when going back to "View Questions"
setFormType("view");
setSelectedQuestion(null);
fetchQuestions(); // Reload questions when switching back to view
fetchQuestions();
} else if (newState === "add") {
setFormType("add"); // Switch to "Add" form
setFormType("add");
}
};

Expand Down
6 changes: 2 additions & 4 deletions client/src/components/UpdateQuestion/UpdateQuestionForm.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,15 +47,13 @@ function UpdateQuestionForm({ goBack, selectedQuestion, onUpdateSuccess, onDelet
updatedQuestion
);

// Call the onUpdateSuccess callback to update the parent state
onUpdateSuccess(response.data);
setSuccessMessage("Question updated successfully!");

setTimeout(() => {
setSuccessMessage("");
goBack(); // Go back after message disappears
goBack();
}, 3000);
// Go back to the list view

} catch (error) {
console.error(error);
Expand All @@ -73,7 +71,7 @@ function UpdateQuestionForm({ goBack, selectedQuestion, onUpdateSuccess, onDelet

setTimeout(() => {
setSuccessMessage("");
goBack(); // Go back after message disappears
goBack();
}, 3000);
}
} catch (error) {
Expand Down

0 comments on commit 1157fee

Please sign in to comment.