update: add comment for function toggle flag

This commit is contained in:
abiyasa05 2024-11-09 15:25:52 +07:00
parent ab29d0c1a1
commit 8347b88be2

View File

@ -264,27 +264,27 @@ console.log("unanswered questions:", unanswered.length);
}, [flaggedQuestions]); }, [flaggedQuestions]);
// Mutation function to toggle flag // Mutation function to toggle flag
const toggleFlagMutation = useMutation<ToggleFlagResponse, Error, string>({ // const toggleFlagMutation = useMutation<ToggleFlagResponse, Error, string>({
mutationFn: toggleFlagAnswer, // mutationFn: toggleFlagAnswer,
onSuccess: (response) => { // onSuccess: (response) => {
if (response && response.answer) { // if (response && response.answer) {
const { answer } = response; // const { answer } = response;
setFlaggedQuestions((prevFlags) => { // setFlaggedQuestions((prevFlags) => {
const newFlags = { // const newFlags = {
...prevFlags, // ...prevFlags,
[answer.id]: answer.isFlagged !== null ? answer.isFlagged : false, // [answer.id]: answer.isFlagged !== null ? answer.isFlagged : false,
}; // };
// Simpan perubahan ke localStorage // // Simpan perubahan ke localStorage
localStorage.setItem("flaggedQuestions", JSON.stringify(newFlags)); // localStorage.setItem("flaggedQuestions", JSON.stringify(newFlags));
return newFlags; // return newFlags;
}); // });
} // }
}, // },
onError: (error) => { // onError: (error) => {
console.error("Error toggling flag:", error); // console.error("Error toggling flag:", error);
}, // },
}); // });
// Usage of the mutation in your component // Usage of the mutation in your component
const { mutate: submitOption } = useMutation({ const { mutate: submitOption } = useMutation({