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