// islands/QuizConfigure.tsx import { useEffect, useState } from "preact/hooks"; import { QuizConfig } from "../utils/types.ts"; import { User } from "../db/interfaces.ts"; export interface QuizConfigProps { quizConfig: QuizConfig; // kvObj: KvObj; quizOrder: { index: number; slots: string[] }; quizMode: string; } export default function QuizConfigure( { quizConfig, quizOrder, quizMode }: QuizConfigProps, ) { // Theme classes are defined in styles.css with @media (prefers-color-scheme: dark) const [thisQuizConfig, setQuizConfig] = useState(quizConfig); const [orderedQuizStr, setOrderQuizStr] = useState( JSON.stringify(thisQuizConfig), ); const [thisQuizConfigStr, setQuizConfigStr] = useState( JSON.stringify({ theUpdate: null, quiz: quizConfig, //kvObj: kvObj, quizOrder: quizOrder, }), ); const [selectedSlot, setSelectedSlot] = useState(0); //const [changeMode, setChangeMode] = useState<{ mode: string } | null>(null); const [nameError, setNameError] = useState(false); const [thisQuizOder, setThisQuizOrder] = useState(quizOrder); const [randomOrder, setRandomOrder] = useState(true); const [modeType, setModeType] = useState(quizMode); //const [isLoading, setIsLoading] = useState(true); const [count, setCount] = useState(0); const handleClick = () => { setCount((prev) => { const newCount = prev + 1; return newCount; }); }; // const handleQuizNameChange = (e: Event) => { // const target = e.target as HTMLInputElement; // if (!target.value) { // setNameError(true); // } else { // thisQuizConfig.quiz_name = target.value; // setQuizConfig(thisQuizConfig); // setChangeMode((prev) => { // if (!prev) { // return { mode: "quiz" }; // } // // // // return prev; // }); // } // setQuizConfigStr( // JSON.stringify({ // theUpdate: changeMode?.mode, // quiz: thisQuizConfig, // kvObj: kvObj, // quizOrder: thisQuizOder, // }), // ); // }; const handleQuizModeChange = (e: Event) => { const target = e.target as HTMLSelectElement; // setQuizConfig((prev) => { // if (!prev) return null; // const updated = { ...prev, quiz_mode: target.value }; // //saveQuizConfig(updated); // Save the updated config // return updated; // }); }; if (!thisQuizConfig) { return
Error: Unable to load quiz configuration
; } function handleOwnerChange( event: Event, selectedUser: User | undefined, ): void { if (selectedUser) { //("selected ", selectedUser.id); thisQuizConfig.owner_id = selectedUser.id; setQuizConfig(thisQuizConfig); //console.log("thisQuizConfig ", thisQuizConfig.owner_id); } //console.log("on user change ", JSON.stringify(event)); //throw new Error("Function not implemented."); } useEffect(() => { //console.log("setting mode!!",quizConfig.quiz_mode) if (quizConfig.quiz_mode) { setModeType(quizConfig.quiz_mode); } }, []); return ( <>
setRandomOrder((e.target as HTMLInputElement).checked)} className="h-5 w-5 text-blue-600 focus:ring-blue-500 border-gray-300 rounded" />

Study Quiz

); }