PageSourceSearch

https://weversity.org/assets/QuizTakingPage-22pKr-Km.js

js weversity.org collected 2026-10-02 01:08:39 UTC 14,410 bytes, 1 lines download raw bytes

1import{j as e}from"./index-A5apO8sf.js";import{r as x}from"./vendor-react-DXfu0YkJ.js";import{c as U}from"./confetti.module-oQXWb4Lk.js";import"./vendor-pdf-v-sEuCgt.js";import"./vendor-ui--7kLNIgQ.js";import"./vendor-charts-odGm-fv0.js";import"./vendor-icons-DAn0tkMA.js";import"./vendor-supabase-BVvKO2AB.js";function Q(l){const i=[...l];for(let d=i.length-1;d>0;d--){const c=Math.floor(Math.random()*(d+1));[i[d],i[c]]=[i[c],i[d]]}return i}const G=({question:l,answer:i,onAnswerChange:d})=>{var s;const c=n=>{d([n])};return e.jsx("div",{className:"space-y-4",children:(s=l.options)==null?void 0:s.map(n=>e.jsxs("label",{className:`flex items-center p-4 border rounded-[15px] cursor-pointer transition-all duration-200 ${i.includes(n.id)?"bg-indigo-50 border-brand-purple ring-2 ring-purple-100":"bg-white border-gray-200 hover:border-brand-purple"}`,children:[e.jsx("input",{type:"radio",name:`question_${l.id}`,checked:i.includes(n.id),onChange:()=>c(n.id),className:"h-5 w-5 text-brand-purple focus:ring-brand-purple border-gray-300"}),e.jsx("span",{className:"ml-4 text-base font-bold text-gray-700",children:n.text})]},n.id))})},V=({question:l,answer:i,onAnswerChange:d})=>{var s;const c=n=>{if(l.allowMultipleCorrect){const o=i.includes(n)?i.filter(m=>m!==n):[...i,n];d(o)}else d([n])};return e.jsx("div",{className:"space-y-4",children:(s=l.options)==null?void 0:s.map(n=>e.jsxs("label",{className:`flex items-center p-4 border rounded-[15px] cursor-pointer transition-all duration-200 ${i.includes(n.id)?"bg-indigo-50 border-brand-purple ring-2 ring-purple-100":"bg-white border-gray-200 hover:border-brand-purple"}`,children:[e.jsx("input",{type:l.allowMultipleCorrect?"checkbox":"radio",name:`question_${l.id}`,checked:i.includes(n.id),onChange:()=>c(n.id),className:"h-5 w-5 text-brand-purple focus:ring-brand-purple border-gray-300 rounded"}),e.jsx("span",{className:"ml-4 text-base font-bold text-gray-700",children:n.text})]},n.id))})},q=({question:l,answer:i,onAnswerChange:d,type:c})=>{const s=c==="short"?"input":"textarea";return e.jsx(s,{value:i[0]||"",onChange:n=>d([n.target.value]),className:"w-full px-4 py-3 border border-gray-300 rounded-[15px] text-base focus:ring-2 focus:ring-brand-purple focus:border-transparent outline-none transition-all",rows:c==="long"?6:void 0,placeholder:"Type your answer here..."})},Y=({question:l,answer:i,onAnswerChange:d})=>e.jsxs("div",{className:"space-y-4",children:[l.imageUrl&&e.jsx("img",{src:l.imageUrl,alt:"Question image",className:"max-w-full h-auto rounded-[15px] border shadow-sm mx-auto"}),e.jsx("input",{type:"text",value:i[0]||"",onChange:c=>d([c.target.value]),className:"w-full px-4 py-3 border border-gray-300 rounded-[15px] text-base focus:ring-2 focus:ring-brand-purple outline-none",placeholder:"Type your answer..."})]}),H=({question:l,answer:i,onAnswerChange:d})=>{const c=x.useMemo(()=>{var o;return((o=l.content)==null?void 0:o.split(/(\[\[.*?\]\])/g))||[]},[l.content]),s=(o,m)=>{const a=[...i];a[o]=m,d(a)};let n=-1;return e.jsx("div",{className:"text-lg leading-loose font-medium text-gray-800",children:c.map((o,m)=>{if(o.startsWith("[[")&&o.endsWith("]]")){n++;const a=n;return e.jsx("input",{type:"text",value:i[a]||"",onChange:u=>s(a,u.target.value),className:"inline-block w-40 mx-2 px-2 py-1 border-b-2 border-brand-purple focus:outline-none bg-purple-50 rounded-t-md text-base text-center"},m)}return e.jsx("span",{children:o},m)})})},K=({question:l,answer:i,onAnswerChange:d})=>{const[c,s]=x.useState([]),n=x.useRef(null),o=x.useRef(null);x.useEffect(()=>{var a;if(i&&i.length===((a=l.options)==null?void 0:a.length)){const u=i.map(j=>l.options.find(g=>g.id===j)).filter(Boolean);s(u)}else s(Q(l.options||[]))},[l.options]);const m=()=>{const a=[...c];if(n.current!==null&&o.current!==null){const u=a.splice(n.current,1)[0];a.splice(o.current,0,u)}n.current=null,o.current=null,s(a),d(a.map(u=>u.id))};return e.jsxs("div",{className:"space-y-3",children:[e.jsxs("div",{className:"flex items-start gap-3 p-3 mb-4 rounded-xl bg-purple-50 border border-purple-100 text-brand-purple",children:[e.jsx("svg",{className:"w-5 h-5 flex-shrink-0 mt-0.5",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",children:e.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M7 16V4m0 0L3 8m4-4l4 4m6 0v12m0 0l4-4m-4 4l-4-4"})}),e.jsxs("div",{className:"text-sm",children:[e.jsx("p",{className:"font-bold",children:"Drag & Drop"}
1),e.jsx("p",{className:"text-brand-purple/80 font-medium mt-0.5",children:"Drag and drop the items below to arrange them in the correct order."})]})]}),c.map((a,u)=>e.jsxs("div",{draggable:!0,onDragStart:()=>n.current=u,onDragEnter:()=>o.current=u,onDragEnd:m,onDragOver:j=>j.preventDefault(),className:"flex items-center p-4 border border-gray-200 rounded-[15px] bg-white cursor-grab active:cursor-grabbing active:bg-indigo-50 shadow-sm transition-all hover:border-brand-purple",children:[e.jsx("svg",{className:"w-5 h-5 text-gray-400 mr-4",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",children:e.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M4 6h16M4 12h16m-7 6h7"})}),e.jsx("span",{className:"text-base font-bold text-gray-700",children:a.text})]},a.id))]})},X=({question:l,answer:i,onAnswerChange:d})=>{const c=x.useMemo(()=>Q((l.options||[]).map(o=>o.match||"")),[l.options]),s=new Map((i||[]).map(o=>o.split(":",2))),n=(o,m)=>{const a=new Map(s);a.set(o,m);const u=Array.from(a.entries()).map(([j,g])=>`${j}:${g}`);d(u)};return e.jsx("div",{className:"space-y-4",children:(l.options||[]).map(o=>e.jsxs("div",{className:"grid grid-cols-2 gap-4 items-center",children:[e.jsx("div",{className:"p-4 border border-gray-200 rounded-[15px] bg-gray-50 text-gray-800 font-bold",children:o.text}),e.jsxs("select",{value:s.get(o.id)||"",onChange:m=>n(o.id,m.target.value),className:"w-full px-4 py-3 border border-gray-200 rounded-[15px] text-sm bg-white focus:ring-2 focus:ring-brand-purple outline-none font-semibold transition-all",children:[e.jsx("option",{value:"",disabled:!0,children:"Select match..."}),c.map((m,a)=>e.jsx("option",{value:m,children:m},a))]})]},o.id))})},oe=({quizState:l,onQuizComplete:i,onBackToCourse:d,session:c})=>{const{quiz:s,courseId:n}=l,[o,m]=x.useState(!1),a=x.useMemo(()=>{let t=s.questions||[];return s.questionOrder==="Random"&&(t=Q(t)),s.maxQuestionsAllowed&&s.maxQuestionsAllowed>0&&(t=t.slice(0,s.maxQuestionsAllowed)),t},[s]),[u,j]=x.useState(0),[g,W]=x.useState({}),[M,J]=x.useState(s.timeLimit?s.timeLimit*60:null);x.useEffect(()=>{if(M===null)return;if(M<=0){F();return}const t=setInterval(()=>J(y=>y?y-1:0),1e3);return()=>clearInterval(t)},[M]);const v=(t,y)=>W(N=>({...N,[t]:y})),r=a[u],S=x.useMemo(()=>{var y,N,k;const t=g[r.id];if(!t||t.length===0)return!1;switch(r.type){case"Open Ended/Essay":case"Short Answer":case"Image Answering":return t[0]&&t[0].trim().length>0;case"Fill in the Blanks":const z=((N=(y=r.content)==null?void 0:y.match(/\[\[.*?\]\]/g))==null?void 0:N.length)||0;return t.filter(_=>_&&_.trim().length>0).length>=z;case"Matching":case"Ordering":return t.length===(((k=r.options)==null?void 0:k.length)||0);case"True/False":case"Multiple Choice":default:return t.length>0}},[g,r]),P=()=>{window.confirm("Are you sure you want to exit the quiz? Your progress may be lost.")&&d()},F=async()=>{if(o||!S)return;m(!0);let t=0,y=0,N=0;a.forEach(p=>{var E,I,B,O,D,T,$;const A=p.points||0;t+=A;const h=g[p.id]||[];let b=!1;if(p.type==="True/False"||p.type==="Multiple Choice"){const f=((E=p.options)==null?void 0:E.filter(w=>w.isCorrect).map(w=>w.id))||[];p.allowMultipleCorrect?b=h.length>0&&JSON.stringify([...h].sort())===JSON.stringify([...f].sort()):b=h.length===1&&f.includes(h[0])}else if(p.type==="Fill in the Blanks"){const f=((B=(I=p.content)==null?void 0:I.match(/\[\[(.*?)\]\]/g))==null?void 0:B.map(w=>w.slice(2,-2)))||[];b=f.length===h.length&&f.every((w,C)=>w.toLowerCase()===(h[C]||"").toLowerCase())}else if(p.type==="Ordering"){const f=((O=p.options)==null?void 0:O.map(w=>w.id))||[];b=JSON.stringify(f)===JSON.stringify(h)}else if(p.type==="Matching"){const f=new Map((D=p.options)==null?void 0:D.map(C=>[C.id,C.match])),w=new Map(h.map(C=>C.split(":",2)));b=f.size===w.size&&Array.from(f.entries()).every(([C,R])=>w.get(C)===R)}else if(p.type==="Image Answering"){const f=(($=(T=p.options)==null?void 0:T[0])==null?void 0:$.text)||"";b=(h[0]||"").toLowerCase().trim()===f.toLowerCase().trim()}b&&(N++,y+=A)});const k=t>0?y/t*100:0,z=k>=(s.passingGrade||80),L=isNaN(Number(s.id))?s.id:Number(s.id),_={student_id:c.user.id,course_id:n,quiz_id:L,quiz_title:s.title,questions:a,answers:g,score:k,total_marks:t,correct_answers:N,incorrect_answers:a.length-N,passed:z,time_limit:s.timeLimit,time_unit:s.timeUnit,passing_grade:s.passingGrade};try{const{error:p}=await window.supabase.from("quiz_attempts").insert(_);if(p){console.error("Quiz save error:",p),alert(`Failed to save quiz results: ${p.message}. Please try again.`),m(!1);return}if(z){try{const{data:h,error:b}=await window.supabase.rpc("handle_quiz_reward",{p_student_id:c.user.id,p_course_id:n,p_quiz_id:L,p_quiz_title:s.title,p_score:k});!b&&(h!=null&&h.success)&&U({particleCount:k>=90?150:100,spread:70,origin:{y:.6},colors:k>=90?["#FFD700","#FFA500","#FF4500"]:["#7C3AED","#10B981"]})}catch(h){console.error("Error awarding quiz reward:",h)}const{data:A}=await window.supabase.from("enrollments").select("completed_lessons").eq("student_id",c.user.id).eq("course_id",n).single();if(A){const h=Array.isArray(A.completed_lessons)?A.completed_lessons:[],b=String(s.id);h.includes(b)||await window.supabase.from("enrollments").update({completed_lessons:[...h,b]}).eq("student_id",c.user.id).eq("course_id",n)}}i({..._,quiz_id:String(s.id)})}catch(p){console.error("Unexpected error during quiz submission:",p),alert("An unexpected error occurred while saving your results. Please check your connection."),m(!1)}};return a.length===0?e.jsxs("div",{className:"flex flex-col items-center justify-center h-screen",children:[e.jsx("p",{children:"No questions."}),e.jsx("button",{onClick:d,children:"Back"})]}):e.jsxs("div",{className:"flex flex-col h-screen bg-[#F8F9FD]",children:[e.jsxs("header",{className:"bg-brand-purple text-white flex items-center justify-between px-6 h-16 shadow-lg z-10",children:[e.jsxs("div",{className:"flex items-center",children:[e.jsx("button",{onClick:P,className:"mr-4 p-2 hover:bg-white/10 rounded-full transition-colors group",title:"Exit Quiz",children:e.jsx("svg",{className:"w-6 h-6 transform group-hover:scale-110 transition-transform",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",children:e.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2.5,d:"M6 18L18 6M6 6l12 12"})})}),e.jsx("h1",{className:"font-black tracking-tight text-lg truncate max-w-[200px] sm:max-w-md",children:s.title})]}),e.jsxs("div",{className:"flex items-center space-x-4",children:[e.jsxs("span",{className:"text-sm font-bold uppercase tracking-wider hidden sm:inline",children:["Question:"," ",e.jsxs("strong",{children:[u+1,"/",a.length]})]}),e.jsx("span",{className:"text-sm font-bold sm:hidden",children:e.jsxs("strong",{children:[u+1,"/",a.length]})}),M!==null&&e.jsxs("div",{className:`px-4 py-1.5 rounded-full font-mono font-black text-sm border-2 ${M<60?"bg-red-500 border-white animate-pulse":"bg-white/20 border-white/30"}`,children:[Math.floor(M/60),":",(M%60).toString().padStart(2,"0")]})]})]}),e.jsxs("main",{className:"flex-1 overflow-y-auto p-4 sm:p-10 flex flex-col items-center",children:[e.jsxs("div",{className:"w-full max-w-4xl bg-white p-6 sm:p-8 rounded-[15p
1x] shadow-xl border border-gray-100 animate-fade-in mb-6",children:[e.jsxs("div",{className:"mb-6",children:[e.jsxs("span",{className:"text-[10px] font-black text-gray-400 uppercase tracking-[0.2em] mb-2 block",children:["Question ",u+1]}),e.jsx("h2",{className:"text-xl sm:text-2xl font-black text-gray-900 leading-tight",children:r.title})]}),e.jsxs("div",{className:"mb-6",children:[r.type==="True/False"&&e.jsx(G,{question:r,answer:g[r.id]||[],onAnswerChange:t=>v(r.id,t)}),r.type==="Multiple Choice"&&e.jsx(V,{question:r,answer:g[r.id]||[],onAnswerChange:t=>v(r.id,t)}),r.type==="Open Ended/Essay"&&e.jsx(q,{question:r,answer:g[r.id]||[],onAnswerChange:t=>v(r.id,t),type:"long"}),r.type==="Short Answer"&&e.jsx(q,{question:r,answer:g[r.id]||[],onAnswerChange:t=>v(r.id,t),type:"short"}),r.type==="Image Answering"&&e.jsx(Y,{question:r,answer:g[r.id]||[],onAnswerChange:t=>v(r.id,t)}),r.type==="Fill in the Blanks"&&e.jsx(H,{question:r,answer:g[r.id]||[],onAnswerChange:t=>v(r.id,t)}),r.type==="Ordering"&&e.jsx(K,{question:r,answer:g[r.id]||[],onAnswerChange:t=>v(r.id,t)}),r.type==="Matching"&&e.jsx(X,{question:r,answer:g[r.id]||[],onAnswerChange:t=>v(r.id,t)})]}),e.jsxs("div",{className:"flex items-center justify-between pt-6 border-t border-gray-100 gap-4",children:[e.jsxs("button",{onClick:()=>j(t=>t-1),disabled:u===0,className:"px-8 py-3 bg-gray-100 text-gray-700 font-black uppercase tracking-widest text-[10px] rounded-[15px] hover:bg-gray-200 transition-all disabled:opacity-30 disabled:cursor-not-allowed flex items-center gap-2",children:[e.jsx("svg",{className:"w-4 h-4",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",children:e.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:3,d:"M15 19l-7-7 7-7"})}),"Back"]}),e.jsxs("button",{onClick:()=>u<a.length-1?j(t=>t+1):F(),disabled:o||!S,className:`px-10 py-3 font-black uppercase tracking-widest text-[10px] rounded-[15px] transition-all transform active:scale-95 flex items-center gap-2 shadow-lg ${S?"bg-brand-purple text-white hover:bg-brand-purple-dark shadow-purple-500/20":"bg-gray-200 text-gray-400 cursor-not-allowed shadow-none"}`,children:[o?"Submitting...":u===a.length-1?"Finish Quiz":"Next Question",u<a.length-1&&e.jsx("svg",{className:"w-4 h-4",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",children:e.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:3,d:"M9 5l7 7-7 7"})})]})]}),!S&&e.jsx("p",{className:"text-center text-[10px] font-bold text-red-400 uppercase tracking-widest mt-4 animate-pulse",children:"Please provide an answer to continue"})]}),e.jsx("p",{className:"text-gray-400 text-[10px] font-bold uppercase tracking-widest mb-10",children:u+1<a.length?`Next: Question ${u+2}`:"This is the last question"})]})]})};export{oe as default};

Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.