import LayoutPage from "@/components/templates/LayoutPage"; import useNavbarStore from "@/stores/NavbarStore"; import useTebakHurufStore from "@/stores/TebakHurufStore"; import { useEffect, useState } from "react"; import { HiOutlineHome } from "react-icons/hi"; import { Link, useNavigate } from "react-router-dom"; import Swal from "sweetalert2"; import { AnimatePresence, motion } from "framer-motion"; import Carousel from "@/components/organisms/CarouselTebakHuruf"; import { IoCloseOutline } from "react-icons/io5"; const TebakHuruf = () => { const quizStore = useTebakHurufStore(); const store = useNavbarStore(); useEffect(() => { store.setNavSelected("kuis"); }, []); const shuffleSoal = () => { const arr = [ "A", "B", "C", "D", "E", "F", "G", "H", "I", "K", "L", "M", "N", "O", "P", "Q", "R", "S", "T", "U", "V", "W", "X", "Y", ]; const shuffledArr = arr.sort(() => 0.5 - Math.random()).slice(0, 10); return shuffledArr; }; const saveData = async () => { let score = 0; let benar = 0; let salah = 0; try { quizStore.jawaban.forEach((jawaban) => { if (jawaban.isCorrect) { score += 10; benar += 1; } else { salah += 1; } }); await fetch("https://ksuli-api.deno.dev/proses-kuis", { method: "POST", headers: { "Content-Type": "application/json", Authorization: `Bearer KSULI_TOKEN_321`, }, body: JSON.stringify({ kategori_id: "rec_cuum78tqrj678tmbcjh0", person_name: quizStore.name, score: score, }), }); Swal.close(); } catch (error) { console.error("Error saving data:", error); Swal.fire({ icon: "error", title: "Oops...", text: "Something went wrong while saving your data!", }); } Swal.fire({ icon: "success", title: "Kuis telah selesai", html: `
Anda menyelesaikan kuis dengan score: ${score}
Jawaban benar: ${benar}
Jawaban salah: ${salah}
`, }); }; const router = useNavigate(); const ProsesKuis = () => { if (quizStore.name === "") { Swal.fire({ icon: "error", title: "Oops...", text: "Isi nama terlebih dahulu", }); return; } quizStore.setSoalIndex(0); quizStore.setSession(true); quizStore.setListSoal(shuffleSoal()); router("/kuis/tebak-huruf/app"); }; useEffect(() => { if (quizStore.isFinish) { saveData(); } return () => { quizStore.setIsFinish(false); }; }, [quizStore.isFinish]); const [showDialog, setShowDialog] = useState(false); return (Home