This commit is contained in:
adueck 2022-10-11 15:41:14 +05:00
parent f7f06a7ebc
commit cb3237c51c
1 changed files with 20 additions and 15 deletions

View File

@ -17,21 +17,26 @@ function ChapterFeedback({ chapter }: { chapter: string }) {
function handleRatingClick(v: number) { function handleRatingClick(v: number) {
setRating(o => o === v ? undefined : v); setRating(o => o === v ? undefined : v);
} }
useEffect(() => { // automatic sending of emoji click feedback if someone leaves the chapter without
return () => { // filling in and sending the feedback textbox
if (rating === undefined || feedbackStatus === "sent") return; // not doing this yet because not sure if it's a clean setup like "componentWillUnmount"
fetch("https://account.lingdocs.com/feedback", { // or if it unecessarily unmounts and re-renders
method: "PUT", // useEffect(() => {
credentials: "include", // return () => {
headers: { // if (rating === undefined || feedbackStatus === "sent") return;
"Content-Type": "application/json", // fetch("https://account.lingdocs.com/feedback", {
}, // method: "PUT",
body: JSON.stringify({ feedback: "", rating }), // credentials: "include",
}).catch(() => { // headers: {
console.error("couldn't send chapter feedback"); // "Content-Type": "application/json",
}); // },
} // body: JSON.stringify({ feedback: "", rating }),
}, []); // }).catch(() => {
// console.error("couldn't send chapter feedback");
// });
// }
// // eslint-disable-next-line
// }, []);
function handleSendFeedback() { function handleSendFeedback() {
const toSend = { const toSend = {
chapter, chapter,