From 6bf37b74a2a92624a54b986e947ef71a514fbd24 Mon Sep 17 00:00:00 2001 From: AlexVOiceover Date: Tue, 4 Jun 2024 13:00:49 +0100 Subject: [PATCH] Updates --- assets/{index-DjqE0FB3.js => index-DcyJMOrd.js} | 2 +- index.html | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) rename assets/{index-DjqE0FB3.js => index-DcyJMOrd.js} (95%) diff --git a/assets/index-DjqE0FB3.js b/assets/index-DcyJMOrd.js similarity index 95% rename from assets/index-DjqE0FB3.js rename to assets/index-DcyJMOrd.js index c300d16..1b622e9 100644 --- a/assets/index-DjqE0FB3.js +++ b/assets/index-DcyJMOrd.js @@ -64,4 +64,4 @@ Error generating stack: `+o.message+` * LICENSE.md file in the root directory of this source tree. * * @license MIT - */function ci(){return ci=Object.assign?Object.assign.bind():function(e){for(var t=1;t=0)&&(n[l]=e[l]);return n}function xh(e){return!!(e.metaKey||e.altKey||e.ctrlKey||e.shiftKey)}function Sh(e,t){return e.button===0&&(!t||t==="_self")&&!xh(e)}const kh=["onClick","relative","reloadDocument","replace","state","target","to","preventScrollReset","unstable_viewTransition"],Eh="6";try{window.__reactRouterVersion=Eh}catch{}const Ch="startTransition",Ss=gf[Ch];function Nh(e){let{basename:t,children:n,future:r,window:l}=e,o=E.useRef();o.current==null&&(o.current=zp({window:l,v5Compat:!0}));let i=o.current,[u,s]=E.useState({action:i.action,location:i.location}),{v7_startTransition:a}=r||{},p=E.useCallback(h=>{a&&Ss?Ss(()=>s(h)):s(h)},[s,a]);return E.useLayoutEffect(()=>i.listen(p),[i,p]),E.createElement(yh,{basename:t,children:n,location:u.location,navigationType:u.action,navigator:i,future:r})}const _h=typeof window<"u"&&typeof window.document<"u"&&typeof window.document.createElement<"u",Ph=/^(?:[a-z][a-z0-9+.-]*:|\/\/)/i,ks=E.forwardRef(function(t,n){let{onClick:r,relative:l,reloadDocument:o,replace:i,state:u,target:s,to:a,preventScrollReset:p,unstable_viewTransition:h}=t,m=wh(t,kh),{basename:g}=E.useContext(Ut),w,x=!1;if(typeof a=="string"&&Ph.test(a)&&(w=a,_h))try{let d=new URL(window.location.href),y=a.startsWith("//")?new URL(d.protocol+a):new URL(a),k=ou(y.pathname,g);y.origin===d.origin&&k!=null?a=k+y.search+y.hash:x=!0}catch{}let C=nh(a,{relative:l}),f=jh(a,{replace:i,state:u,target:s,preventScrollReset:p,relative:l,unstable_viewTransition:h});function c(d){r&&r(d),d.defaultPrevented||f(d)}return E.createElement("a",ci({},m,{href:w||C,onClick:x||o?r:c,ref:n,target:s}))});var Es;(function(e){e.UseScrollRestoration="useScrollRestoration",e.UseSubmit="useSubmit",e.UseSubmitFetcher="useSubmitFetcher",e.UseFetcher="useFetcher",e.useViewTransitionState="useViewTransitionState"})(Es||(Es={}));var Cs;(function(e){e.UseFetcher="useFetcher",e.UseFetchers="useFetchers",e.UseScrollRestoration="useScrollRestoration"})(Cs||(Cs={}));function jh(e,t){let{target:n,replace:r,state:l,preventScrollReset:o,relative:i,unstable_viewTransition:u}=t===void 0?{}:t,s=Dl(),a=Ol(),p=Xc(e,{relative:i});return E.useCallback(h=>{if(Sh(h,n)){h.preventDefault();let m=r!==void 0?r:dl(a)===dl(p);s(e,{replace:m,state:l,preventScrollReset:o,relative:i,unstable_viewTransition:u})}},[a,s,p,r,l,n,e,o,i,u])}function lr({name:e,preIcon:t,postIcon:n,handler:r,color:l="blue"}){const o={blue:"bg-blue-500 hover:bg-blue-700 text-white",red:"bg-red-500 hover:bg-red-700 text-white",yellow:"bg-yellow-500 hover:bg-yellow-700 text-black",black:"bg-black hover:bg-gray-800 text-white",grey:"bg-gray-500 hover:bg-gray-700 text-white",green:"bg-green-500 hover:bg-green-700 text-white",orange:"bg-orange-500 hover:bg-orange-700 text-white"},i=o[l]||o.blue;return v.jsxs("button",{className:`${i} font-bold py-2 px-4 rounded flex w-min text-nowrap items-center focus:outline-none`,onClick:r,children:[t&&v.jsx("span",{children:t}),e&&v.jsx("span",{className:"mx-2",children:e}),n&&v.jsx("span",{children:n})]})}function Ns({name:e,contentArr:t,handleDropdown:n}){return v.jsx("div",{className:"flex justify-evenly",children:v.jsxs("select",{name:e,onChange:r=>n(r),className:"bg-blue-500 hover:bg-blue-700 text-white font-bold py-2 px-4 rounded flex items-center",children:[v.jsxs("option",{value:"",children:["Please choose ",e]}),t==null?void 0:t.map((r,l)=>v.jsx("option",{value:r,children:r},l))]})})}const Lh=()=>["Science","Geography","History","Mathematics","Pop Culture","Music","Literature","Favourited"],zh=()=>["easy","medium","hard","all"],Il="https://18.175.120.83:8443";function ho(){const e=Lh(),t=zh(),[n,r]=E.useState(void 0),[l,o]=E.useState(void 0);console.log("Category selected "+n),console.log("Difficulty selected "+l);const i=Dl(),u=()=>{i("/quiz")},s=p=>{r(p.target.value)},a=p=>{o(p.target.value)};return v.jsxs("div",{className:"container mx-auto flex flex-col items-center mt-10 p-5",children:[v.jsx("h1",{className:"text-4xl font-bold mb-4 text-white",children:"Take a Quiz"}),v.jsx("section",{className:"mb-6 text-gray-400 text-center",children:v.jsx("p",{children:"This is the main page for the quiz."})}),v.jsxs("div",{className:"flex flex-col md:flex-row space-y-4 md:space-y-0 md:space-x-4 mb-6",children:[v.jsx(Ns,{name:"Category",contentArr:e,handleDropdown:s}),v.jsx(Ns,{name:"Difficulty",contentArr:t,handleDropdown:a})]}),v.jsx(lr,{name:"START QUIZ",color:"orange",handler:u})]})}function Th(){return v.jsx(v.Fragment,{children:v.jsx("h1",{children:"Quiz component "})})}var Jc={color:void 0,size:void 0,className:void 0,style:void 0,attr:void 0},_s=He.createContext&&He.createContext(Jc),Rh=["attr","size","title"];function Oh(e,t){if(e==null)return{};var n=Dh(e,t),r,l;if(Object.getOwnPropertySymbols){var o=Object.getOwnPropertySymbols(e);for(l=0;l=0)&&Object.prototype.propertyIsEnumerable.call(e,r)&&(n[r]=e[r])}return n}function Dh(e,t){if(e==null)return{};var n={};for(var r in e)if(Object.prototype.hasOwnProperty.call(e,r)){if(t.indexOf(r)>=0)continue;n[r]=e[r]}return n}function hl(){return hl=Object.assign?Object.assign.bind():function(e){for(var t=1;tHe.createElement(t.tag,ml({key:n},t.attr),qc(t.child)))}function Ml(e){return t=>He.createElement(Uh,hl({attr:ml({},e.attr)},t),qc(e.child))}function Uh(e){var t=n=>{var{attr:r,size:l,title:o}=e,i=Oh(e,Rh),u=l||n.size||"1em",s;return n.className&&(s=n.className),e.className&&(s=(s?s+" ":"")+e.className),He.createElement("svg",hl({stroke:"currentColor",fill:"currentColor",strokeWidth:"0"},n.attr,r,i,{className:s,style:ml(ml({color:e.color||n.color},n.style),e.style),height:u,width:u,xmlns:"http://www.w3.org/2000/svg"}),o&&He.createElement("title",null,o),e.children)};return _s!==void 0?He.createElement(_s.Consumer,null,n=>t(n)):t(Jc)}function $h(e){return Ml({tag:"svg",attr:{viewBox:"0 0 576 512"},child:[{tag:"path",attr:{d:"M280.37 148.26L96 300.11V464a16 16 0 0 0 16 16l112.06-.29a16 16 0 0 0 15.92-16V368a16 16 0 0 1 16-16h64a16 16 0 0 1 16 16v95.64a16 16 0 0 0 16 16.05L464 480a16 16 0 0 0 16-16V300L295.67 148.26a12.19 12.19 0 0 0-15.3 0zM571.6 251.47L488 182.56V44.05a12 12 0 0 0-12-12h-56a12 12 0 0 0-12 12v72.61L318.47 43a48 48 0 0 0-61 0L4.34 251.47a12 12 0 0 0-1.6 16.9l25.5 31A12 12 0 0 0 45.15 301l235.22-193.74a12.19 12.19 0 0 1 15.3 0L530.9 301a12 12 0 0 0 16.9-1.6l25.5-31a12 12 0 0 0-1.7-16.93z"},child:[]}]})(e)}function Bh(e){return Ml({tag:"svg",attr:{viewBox:"0 0 512 512"},child:[{tag:"path",attr:{d:"M504 256c0 136.997-111.043 248-248 248S8 392.997 8 256C8 119.083 119.043 8 256 8s248 111.083 248 248zM262.655 90c-54.497 0-89.255 22.957-116.549 63.758-3.536 5.286-2.353 12.415 2.715 16.258l34.699 26.31c5.205 3.947 12.621 3.008 16.665-2.122 17.864-22.658 30.113-35.797 57.303-35.797 20.429 0 45.698 13.148 45.698 32.958 0 14.976-12.363 22.667-32.534 33.976C247.128 238.528 216 254.941 216 296v4c0 6.627 5.373 12 12 12h56c6.627 0 12-5.373 12-12v-1.333c0-28.462 83.186-29.647 83.186-106.667 0-58.002-60.165-102-116.531-102zM256 338c-25.365 0-46 20.635-46 46 0 25.364 20.635 46 46 46s46-20.636 46-46c0-25.365-20.635-46-46-46z"},child:[]}]})(e)}function Ah(e){return Ml({tag:"svg",attr:{viewBox:"0 0 576 512"},child:[{tag:"path",attr:{d:"M402.3 344.9l32-32c5-5 13.7-1.5 13.7 5.7V464c0 26.5-21.5 48-48 48H48c-26.5 0-48-21.5-48-48V112c0-26.5 21.5-48 48-48h273.5c7.1 0 10.7 8.6 5.7 13.7l-32 32c-1.5 1.5-3.5 2.3-5.7 2.3H48v352h352V350.5c0-2.1.8-4.1 2.3-5.6zm156.6-201.8L296.3 405.7l-90.4 10c-26.2 2.9-48.5-19.2-45.6-45.6l10-90.4L432.9 17.1c22.9-22.9 59.9-22.9 82.7 0l43.2 43.2c22.9 22.9 22.9 60 .1 82.8zM460.1 174L402 115.9 216.2 301.8l-7.3 65.3 65.3-7.3L460.1 174zm64.8-79.7l-43.2-43.2c-4.1-4.1-10.8-4.1-14.8 0L436 82l58.1 58.1 30.9-30.9c4-4.2 4-10.8-.1-14.9z"},child:[]}]})(e)}function Vh(e){return Ml({tag:"svg",attr:{viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round"},child:[{tag:"path",attr:{d:"M21 4H8l-7 8 7 8h13a2 2 0 0 0 2-2V6a2 2 0 0 0-2-2z"},child:[]},{tag:"line",attr:{x1:"18",y1:"9",x2:"12",y2:"15"},child:[]},{tag:"line",attr:{x1:"12",y1:"9",x2:"18",y2:"15"},child:[]}]})(e)}function Wh({question:e,onDelete:t,onEdit:n}){return v.jsxs("div",{className:"flex justify-between items-center bg-gray-100 p-2 rounded border-b border-gray-600 w-full",children:[v.jsx("span",{className:"text-gray-700 mr-2 ml-2 justify-self-start",children:e.question}),v.jsxs("div",{className:"flex space-x-2",children:[v.jsx(lr,{preIcon:v.jsx(Ah,{}),handler:n,name:"Edit"}),v.jsx(lr,{color:"red",preIcon:v.jsx(Vh,{}),handler:t,name:"Delete"})]})]})}function Qh({questions:e,setAllQuestions:t}){const n=Il;console.log(n);const r=i=>{console.log(`Deleting question with id: ${i}`),fetch(`${n}/delete-post/${i}`,{method:"DELETE",headers:{"Content-Type":"application/json"}}).then(u=>{if(!u.ok)throw new Error(`HTTP error! status: ${u.status}`);return u.text()}).then(u=>{console.log("Delete response:",u),t(s=>s.filter(a=>a.id!==i))}).catch(u=>{console.error("Error:",u)})},l=Dl(),o=i=>{console.log(`Editing question with id: ${i}`),l(`/questionbank/editquestion/${i}`)};return v.jsx("div",{className:"question-bank-table",children:e.map(i=>v.jsx(Wh,{question:i,onDelete:()=>r(i.id),onEdit:()=>o(i.id)},i.id))})}function Hh(){const[e,t]=E.useState([]),n=Dl(),r=Il,l=()=>{n("/home")};function o(){n("/questionbank/addquestion")}return E.useEffect(()=>{fetch(`${r}`,{method:"GET",headers:{"Content-Type":"application/json"}}).then(i=>i.json()).then(i=>{t(i)}).catch(i=>{console.error("Error:",i)})},[r]),v.jsxs("div",{className:"container mx-auto flex flex-col items-center mt-10 p-5",children:[v.jsx("h1",{className:"text-4xl font-bold mb-4 text-white",children:"Question bank"}),v.jsx("section",{className:"mb-6 text-gray-400 text-center",children:v.jsx("p",{children:"Create - Edit - Delete questions."})}),v.jsxs("div",{className:"flex flex-col space-y-4",children:[v.jsx(lr,{name:"CREATE QUESTION",color:"blue",handler:o}),v.jsx(Qh,{questions:e,setAllQuestions:t}),v.jsx(lr,{name:"BACK",color:"orange",handler:l})]})]})}function Kh(){const[e,t]=E.useState({id:9,category:"test",difficulty:"easy",question:"How many",options:["01/07/1998","07/07/1998","02/02/1961","09/09/1990"],answer:"",favourited:!1,timestamp:new Date}),n=Il,r=o=>{o.preventDefault(),fetch(`${n}/create-question`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(e)}).then(i=>i.json()).then(i=>{console.log(i)}).catch(i=>{console.error("Error:",i)})},l=o=>{const{name:i,type:u,checked:s,value:a}=o.target;t(p=>({...p,[i]:u==="checkbox"?s:a}))};return v.jsxs("form",{onSubmit:r,className:" text-black p-4 bg-gray-100 rounded shadow-md ",children:[v.jsxs("div",{className:"grid grid-cols-2 gap-2 auto-cols-min",children:[v.jsx("label",{className:"block text-gray-700 font-bold mb-2 self-end",children:"ID:"}),v.jsx("input",{type:"text",name:"id",value:e.id,onChange:l,className:"w-full px-3 py-2 border rounded bg-white"}),v.jsx("label",{className:"block text-gray-700 self-end font-bold mb-2",children:"Category:"}),v.jsx("input",{type:"text",name:"category",value:e.category,onChange:l,className:"w-full px-3 py-2 border rounded bg-white"}),v.jsx("label",{className:"block text-gray-700 font-bold mb-2 self-end",children:"Difficulty:"}),v.jsx("input",{type:"text",name:"difficulty",value:e.difficulty,onChange:l,className:"w-full px-3 py-2 border rounded bg-white"}),v.jsx("label",{className:"block text-gray-700 font-bold mb-2 self-end",children:"Question:"}),v.jsx("input",{type:"text",name:"question",value:e.question,onChange:l,className:"w-full px-3 py-2 border rounded bg-white"}),v.jsx("label",{className:"block text-gray-700 font-bold mb-2 self-end",children:"Option 0:"}),v.jsx("input",{type:"text",name:"options",value:e.options[0],onChange:l,className:"w-full px-3 py-2 border rounded bg-white"}),v.jsx("label",{className:"block text-gray-700 font-bold mb-2 self-end",children:"Option 1:"}),v.jsx("input",{type:"text",name:"options",value:e.options[1],onChange:l,className:"w-full px-3 py-2 border rounded bg-white"}),v.jsx("label",{className:"block text-gray-700 font-bold mb-2 self-end",children:"Option 2:"}),v.jsx("input",{type:"text",name:"options",value:e.options[2],onChange:l,className:"w-full px-3 py-2 border rounded bg-white"}),v.jsx("label",{className:"block text-gray-700 font-bold mb-2 self-end",children:"Option 3:"}),v.jsx("input",{type:"text",name:"options",value:e.options[3],onChange:l,className:"w-full px-3 py-2 border rounded bg-white"}),v.jsx("label",{className:"block text-gray-700 font-bold mb-2 self-end",children:"Answer:"}),v.jsx("input",{type:"text",name:"answer",value:e.answer,onChange:l,className:"w-full px-3 py-2 border rounded bg-white"}),v.jsx("label",{className:"block text-gray-700 font-bold mb-2 self-end",children:"Favourited:"}),v.jsx("input",{type:"checkbox",name:"favourited",checked:e.favourited,onChange:l,className:"w-full px-3 py-2 border rounded bg-white"}),v.jsx("label",{className:"block text-gray-700 font-bold mb-2 self-end",children:"Timestamp:"}),v.jsx("input",{type:"date",name:"timestamp",value:e.timestamp.toISOString().split("T")[0],onChange:l,className:"w-full px-3 py-2 border rounded bg-white"})]}),v.jsx("button",{type:"submit",children:"Add question"})]})}function Yh(){return v.jsx(v.Fragment,{children:v.jsx(Kh,{})})}const Xh=({id:e})=>{const[t,n]=E.useState({id:0,category:"",difficulty:"medium",question:"Default start values",options:["a","b","c","d"],answer:"",favourited:!1,timestamp:new Date}),r=Il;E.useEffect(()=>{(async()=>{try{console.log("Fetched ID:",e);const u=Number(e);if(isNaN(u))throw new Error("Invalid ID");const p=(await(await fetch(`${r}/get-question-by-id/${e}`)).json())[0];p.timestamp=new Date(p.timestamp),n(p)}catch(u){console.error("Error fetching data:",u)}})()},[e,r]);const l=i=>{const{name:u,type:s,checked:a,value:p}=i.currentTarget;n(h=>({...h,[u]:s==="checkbox"?a:p}))},o=i=>{i.preventDefault(),console.log(t)};return v.jsxs("form",{onSubmit:o,className:"text-black p-4 bg-gray-100 rounded shadow-md",children:[v.jsxs("div",{className:"grid grid-cols-2 gap-2 auto-cols-min",children:[v.jsx("label",{className:"block text-gray-700 self-end font-bold mb-2",children:"Category:"}),v.jsx("input",{type:"text",name:"category",value:t.category,onChange:l,className:"w-full px-3 py-2 border rounded bg-white"}),v.jsx("label",{className:"block text-gray-700 font-bold mb-2 self-end",children:"Difficulty:"}),v.jsx("input",{type:"text",name:"difficulty",value:t.difficulty,onChange:l,className:"w-full px-3 py-2 border rounded bg-white"}),v.jsx("label",{className:"block text-gray-700 font-bold mb-2 self-end",children:"Question:"}),v.jsx("input",{type:"text",name:"question",value:t.question,onChange:l,className:"w-full px-3 py-2 border rounded bg-white"}),v.jsx("label",{className:"block text-gray-700 font-bold mb-2 self-end",children:"Option 0:"}),v.jsx("input",{type:"text",name:"options",value:t.options[0],onChange:l,className:"w-full px-3 py-2 border rounded bg-white"}),v.jsx("label",{className:"block text-gray-700 font-bold mb-2 self-end",children:"Option 1:"}),v.jsx("input",{type:"text",name:"options",value:t.options[1],onChange:l,className:"w-full px-3 py-2 border rounded bg-white"}),v.jsx("label",{className:"block text-gray-700 font-bold mb-2 self-end",children:"Option 2:"}),v.jsx("input",{type:"text",name:"options",value:t.options[2],onChange:l,className:"w-full px-3 py-2 border rounded bg-white"}),v.jsx("label",{className:"block text-gray-700 font-bold mb-2 self-end",children:"Option 3:"}),v.jsx("input",{type:"text",name:"options",value:t.options[3],onChange:l,className:"w-full px-3 py-2 border rounded bg-white"}),v.jsx("label",{className:"block text-gray-700 font-bold mb-2 self-end",children:"Answer:"}),v.jsx("input",{type:"text",name:"answer",value:t.answer,onChange:l,className:"w-full px-3 py-2 border rounded bg-white"}),v.jsx("label",{className:"block text-gray-700 font-bold mb-2 self-end",children:"Favourited:"}),v.jsx("input",{type:"checkbox",name:"favourited",checked:t.favourited,onChange:l,className:"w-full px-3 py-2 border rounded bg-white"}),v.jsx("label",{className:"block text-gray-700 font-bold mb-2 self-end",children:"Timestamp:"}),v.jsx("input",{type:"date",name:"timestamp",value:t.timestamp.toISOString().substr(0,10),onChange:l,className:"w-full px-3 py-2 border rounded bg-white"})]}),v.jsx("button",{type:"submit",className:"mt-4 px-4 py-2 bg-blue-500 text-white rounded",children:"Edit question"})]})},Gh=()=>{const{id:e}=lh();return v.jsx(Xh,{id:Number(e)})},Zh=()=>v.jsxs(gh,{children:[v.jsx(be,{path:"/",element:v.jsx(ho,{})}),v.jsx(be,{path:"/home",element:v.jsx(ho,{})}),v.jsx(be,{path:"/P1DAAF-Frontend/",element:v.jsx(ho,{})}),v.jsx(be,{path:"/quiz",element:v.jsx(Th,{})}),v.jsx(be,{path:"/questionbank",element:v.jsx(Hh,{})}),v.jsx(be,{path:"/questionbank/addquestion",element:v.jsx(Yh,{})}),v.jsx(be,{path:"/questionbank/editquestion/:id",element:v.jsx(Gh,{})})]}),Jh=()=>v.jsx("nav",{className:"bg-gray-700 p-4 w-full top-0 z-50",children:v.jsxs("ul",{className:"flex space-x-8",children:[v.jsx("li",{children:v.jsxs(ks,{to:"/home",className:"text-white flex items-center space-x-2 hover:text-gray-400",children:[v.jsx($h,{}),v.jsx("span",{children:"Home"})]})}),v.jsx("li",{children:v.jsxs(ks,{to:"/questionbank",className:"text-white flex items-center space-x-2 hover:text-gray-400",children:[v.jsx(Bh,{}),v.jsx("span",{children:"Question Bank"})]})})]})});function qh(){return v.jsx(Nh,{children:v.jsxs("div",{children:[v.jsx(Jh,{}),v.jsx(Zh,{})]})})}mo.createRoot(document.getElementById("root")).render(v.jsx(He.StrictMode,{children:v.jsx(qh,{})})); + */function ci(){return ci=Object.assign?Object.assign.bind():function(e){for(var t=1;t=0)&&(n[l]=e[l]);return n}function xh(e){return!!(e.metaKey||e.altKey||e.ctrlKey||e.shiftKey)}function Sh(e,t){return e.button===0&&(!t||t==="_self")&&!xh(e)}const kh=["onClick","relative","reloadDocument","replace","state","target","to","preventScrollReset","unstable_viewTransition"],Eh="6";try{window.__reactRouterVersion=Eh}catch{}const Ch="startTransition",Ss=gf[Ch];function Nh(e){let{basename:t,children:n,future:r,window:l}=e,o=E.useRef();o.current==null&&(o.current=zp({window:l,v5Compat:!0}));let i=o.current,[u,s]=E.useState({action:i.action,location:i.location}),{v7_startTransition:a}=r||{},p=E.useCallback(h=>{a&&Ss?Ss(()=>s(h)):s(h)},[s,a]);return E.useLayoutEffect(()=>i.listen(p),[i,p]),E.createElement(yh,{basename:t,children:n,location:u.location,navigationType:u.action,navigator:i,future:r})}const _h=typeof window<"u"&&typeof window.document<"u"&&typeof window.document.createElement<"u",Ph=/^(?:[a-z][a-z0-9+.-]*:|\/\/)/i,ks=E.forwardRef(function(t,n){let{onClick:r,relative:l,reloadDocument:o,replace:i,state:u,target:s,to:a,preventScrollReset:p,unstable_viewTransition:h}=t,m=wh(t,kh),{basename:g}=E.useContext(Ut),w,x=!1;if(typeof a=="string"&&Ph.test(a)&&(w=a,_h))try{let d=new URL(window.location.href),y=a.startsWith("//")?new URL(d.protocol+a):new URL(a),k=ou(y.pathname,g);y.origin===d.origin&&k!=null?a=k+y.search+y.hash:x=!0}catch{}let C=nh(a,{relative:l}),f=jh(a,{replace:i,state:u,target:s,preventScrollReset:p,relative:l,unstable_viewTransition:h});function c(d){r&&r(d),d.defaultPrevented||f(d)}return E.createElement("a",ci({},m,{href:w||C,onClick:x||o?r:c,ref:n,target:s}))});var Es;(function(e){e.UseScrollRestoration="useScrollRestoration",e.UseSubmit="useSubmit",e.UseSubmitFetcher="useSubmitFetcher",e.UseFetcher="useFetcher",e.useViewTransitionState="useViewTransitionState"})(Es||(Es={}));var Cs;(function(e){e.UseFetcher="useFetcher",e.UseFetchers="useFetchers",e.UseScrollRestoration="useScrollRestoration"})(Cs||(Cs={}));function jh(e,t){let{target:n,replace:r,state:l,preventScrollReset:o,relative:i,unstable_viewTransition:u}=t===void 0?{}:t,s=Dl(),a=Ol(),p=Xc(e,{relative:i});return E.useCallback(h=>{if(Sh(h,n)){h.preventDefault();let m=r!==void 0?r:dl(a)===dl(p);s(e,{replace:m,state:l,preventScrollReset:o,relative:i,unstable_viewTransition:u})}},[a,s,p,r,l,n,e,o,i,u])}function lr({name:e,preIcon:t,postIcon:n,handler:r,color:l="blue"}){const o={blue:"bg-blue-500 hover:bg-blue-700 text-white",red:"bg-red-500 hover:bg-red-700 text-white",yellow:"bg-yellow-500 hover:bg-yellow-700 text-black",black:"bg-black hover:bg-gray-800 text-white",grey:"bg-gray-500 hover:bg-gray-700 text-white",green:"bg-green-500 hover:bg-green-700 text-white",orange:"bg-orange-500 hover:bg-orange-700 text-white"},i=o[l]||o.blue;return v.jsxs("button",{className:`${i} font-bold py-2 px-4 rounded flex w-min text-nowrap items-center focus:outline-none`,onClick:r,children:[t&&v.jsx("span",{children:t}),e&&v.jsx("span",{className:"mx-2",children:e}),n&&v.jsx("span",{children:n})]})}function Ns({name:e,contentArr:t,handleDropdown:n}){return v.jsx("div",{className:"flex justify-evenly",children:v.jsxs("select",{name:e,onChange:r=>n(r),className:"bg-blue-500 hover:bg-blue-700 text-white font-bold py-2 px-4 rounded flex items-center",children:[v.jsxs("option",{value:"",children:["Please choose ",e]}),t==null?void 0:t.map((r,l)=>v.jsx("option",{value:r,children:r},l))]})})}const Lh=()=>["Science","Geography","History","Mathematics","Pop Culture","Music","Literature","Favourited"],zh=()=>["easy","medium","hard","all"],Il="https://18.175.120.83:8443";function ho(){const e=Lh(),t=zh(),[n,r]=E.useState(void 0),[l,o]=E.useState(void 0);console.log("Category selected "+n),console.log("Difficulty selected "+l);const i=Dl(),u=()=>{i("/quiz")},s=p=>{r(p.target.value)},a=p=>{o(p.target.value)};return v.jsxs("div",{className:"container mx-auto flex flex-col items-center mt-10 p-5",children:[v.jsx("h1",{className:"text-4xl font-bold mb-4 text-white",children:"Take a Quiz"}),v.jsx("section",{className:"mb-6 text-gray-400 text-center",children:v.jsx("p",{children:"This is the main page for the quiz."})}),v.jsxs("div",{className:"flex flex-col md:flex-row space-y-4 md:space-y-0 md:space-x-4 mb-6",children:[v.jsx(Ns,{name:"Category",contentArr:e,handleDropdown:s}),v.jsx(Ns,{name:"Difficulty",contentArr:t,handleDropdown:a})]}),v.jsx(lr,{name:"START QUIZ",color:"orange",handler:u})]})}function Th(){return v.jsx(v.Fragment,{children:v.jsx("h1",{children:"Quiz component "})})}var Jc={color:void 0,size:void 0,className:void 0,style:void 0,attr:void 0},_s=He.createContext&&He.createContext(Jc),Rh=["attr","size","title"];function Oh(e,t){if(e==null)return{};var n=Dh(e,t),r,l;if(Object.getOwnPropertySymbols){var o=Object.getOwnPropertySymbols(e);for(l=0;l=0)&&Object.prototype.propertyIsEnumerable.call(e,r)&&(n[r]=e[r])}return n}function Dh(e,t){if(e==null)return{};var n={};for(var r in e)if(Object.prototype.hasOwnProperty.call(e,r)){if(t.indexOf(r)>=0)continue;n[r]=e[r]}return n}function hl(){return hl=Object.assign?Object.assign.bind():function(e){for(var t=1;tHe.createElement(t.tag,ml({key:n},t.attr),qc(t.child)))}function Ml(e){return t=>He.createElement(Uh,hl({attr:ml({},e.attr)},t),qc(e.child))}function Uh(e){var t=n=>{var{attr:r,size:l,title:o}=e,i=Oh(e,Rh),u=l||n.size||"1em",s;return n.className&&(s=n.className),e.className&&(s=(s?s+" ":"")+e.className),He.createElement("svg",hl({stroke:"currentColor",fill:"currentColor",strokeWidth:"0"},n.attr,r,i,{className:s,style:ml(ml({color:e.color||n.color},n.style),e.style),height:u,width:u,xmlns:"http://www.w3.org/2000/svg"}),o&&He.createElement("title",null,o),e.children)};return _s!==void 0?He.createElement(_s.Consumer,null,n=>t(n)):t(Jc)}function $h(e){return Ml({tag:"svg",attr:{viewBox:"0 0 576 512"},child:[{tag:"path",attr:{d:"M280.37 148.26L96 300.11V464a16 16 0 0 0 16 16l112.06-.29a16 16 0 0 0 15.92-16V368a16 16 0 0 1 16-16h64a16 16 0 0 1 16 16v95.64a16 16 0 0 0 16 16.05L464 480a16 16 0 0 0 16-16V300L295.67 148.26a12.19 12.19 0 0 0-15.3 0zM571.6 251.47L488 182.56V44.05a12 12 0 0 0-12-12h-56a12 12 0 0 0-12 12v72.61L318.47 43a48 48 0 0 0-61 0L4.34 251.47a12 12 0 0 0-1.6 16.9l25.5 31A12 12 0 0 0 45.15 301l235.22-193.74a12.19 12.19 0 0 1 15.3 0L530.9 301a12 12 0 0 0 16.9-1.6l25.5-31a12 12 0 0 0-1.7-16.93z"},child:[]}]})(e)}function Bh(e){return Ml({tag:"svg",attr:{viewBox:"0 0 512 512"},child:[{tag:"path",attr:{d:"M504 256c0 136.997-111.043 248-248 248S8 392.997 8 256C8 119.083 119.043 8 256 8s248 111.083 248 248zM262.655 90c-54.497 0-89.255 22.957-116.549 63.758-3.536 5.286-2.353 12.415 2.715 16.258l34.699 26.31c5.205 3.947 12.621 3.008 16.665-2.122 17.864-22.658 30.113-35.797 57.303-35.797 20.429 0 45.698 13.148 45.698 32.958 0 14.976-12.363 22.667-32.534 33.976C247.128 238.528 216 254.941 216 296v4c0 6.627 5.373 12 12 12h56c6.627 0 12-5.373 12-12v-1.333c0-28.462 83.186-29.647 83.186-106.667 0-58.002-60.165-102-116.531-102zM256 338c-25.365 0-46 20.635-46 46 0 25.364 20.635 46 46 46s46-20.636 46-46c0-25.365-20.635-46-46-46z"},child:[]}]})(e)}function Ah(e){return Ml({tag:"svg",attr:{viewBox:"0 0 576 512"},child:[{tag:"path",attr:{d:"M402.3 344.9l32-32c5-5 13.7-1.5 13.7 5.7V464c0 26.5-21.5 48-48 48H48c-26.5 0-48-21.5-48-48V112c0-26.5 21.5-48 48-48h273.5c7.1 0 10.7 8.6 5.7 13.7l-32 32c-1.5 1.5-3.5 2.3-5.7 2.3H48v352h352V350.5c0-2.1.8-4.1 2.3-5.6zm156.6-201.8L296.3 405.7l-90.4 10c-26.2 2.9-48.5-19.2-45.6-45.6l10-90.4L432.9 17.1c22.9-22.9 59.9-22.9 82.7 0l43.2 43.2c22.9 22.9 22.9 60 .1 82.8zM460.1 174L402 115.9 216.2 301.8l-7.3 65.3 65.3-7.3L460.1 174zm64.8-79.7l-43.2-43.2c-4.1-4.1-10.8-4.1-14.8 0L436 82l58.1 58.1 30.9-30.9c4-4.2 4-10.8-.1-14.9z"},child:[]}]})(e)}function Vh(e){return Ml({tag:"svg",attr:{viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round"},child:[{tag:"path",attr:{d:"M21 4H8l-7 8 7 8h13a2 2 0 0 0 2-2V6a2 2 0 0 0-2-2z"},child:[]},{tag:"line",attr:{x1:"18",y1:"9",x2:"12",y2:"15"},child:[]},{tag:"line",attr:{x1:"12",y1:"9",x2:"18",y2:"15"},child:[]}]})(e)}function Wh({question:e,onDelete:t,onEdit:n}){return v.jsxs("div",{className:"flex justify-between items-center bg-gray-100 p-2 rounded border-b border-gray-600 w-full",children:[v.jsx("span",{className:"text-gray-700 mr-2 ml-2 justify-self-start",children:e.question}),v.jsxs("div",{className:"flex space-x-2",children:[v.jsx(lr,{preIcon:v.jsx(Ah,{}),handler:n,name:"Edit"}),v.jsx(lr,{color:"red",preIcon:v.jsx(Vh,{}),handler:t,name:"Delete"})]})]})}function Qh({questions:e,setAllQuestions:t}){const n=Il;console.log(`APIRUL is: ${n}`);const r=i=>{console.log(`Deleting question with id: ${i}`),fetch(`${n}/delete-post/${i}`,{method:"DELETE",headers:{"Content-Type":"application/json"}}).then(u=>{if(!u.ok)throw new Error(`HTTP error! status: ${u.status}`);return u.text()}).then(u=>{console.log("Delete response:",u),t(s=>s.filter(a=>a.id!==i))}).catch(u=>{console.error("Error:",u)})},l=Dl(),o=i=>{console.log(`Editing question with id: ${i}`),l(`/questionbank/editquestion/${i}`)};return v.jsx("div",{className:"question-bank-table",children:e.map(i=>v.jsx(Wh,{question:i,onDelete:()=>r(i.id),onEdit:()=>o(i.id)},i.id))})}function Hh(){const[e,t]=E.useState([]),n=Dl(),r=Il,l=()=>{n("/home")};function o(){n("/questionbank/addquestion")}return E.useEffect(()=>{fetch(`${r}`,{method:"GET",headers:{"Content-Type":"application/json"}}).then(i=>i.json()).then(i=>{t(i)}).catch(i=>{console.error("Error:",i)})},[r]),v.jsxs("div",{className:"container mx-auto flex flex-col items-center mt-10 p-5",children:[v.jsx("h1",{className:"text-4xl font-bold mb-4 text-white",children:"Question bank"}),v.jsx("section",{className:"mb-6 text-gray-400 text-center",children:v.jsx("p",{children:"Create - Edit - Delete questions."})}),v.jsxs("div",{className:"flex flex-col space-y-4",children:[v.jsx(lr,{name:"CREATE QUESTION",color:"blue",handler:o}),v.jsx(Qh,{questions:e,setAllQuestions:t}),v.jsx(lr,{name:"BACK",color:"orange",handler:l})]})]})}function Kh(){const[e,t]=E.useState({id:9,category:"test",difficulty:"easy",question:"How many",options:["01/07/1998","07/07/1998","02/02/1961","09/09/1990"],answer:"",favourited:!1,timestamp:new Date}),n=Il,r=o=>{o.preventDefault(),fetch(`${n}/create-question`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(e)}).then(i=>i.json()).then(i=>{console.log(i)}).catch(i=>{console.error("Error:",i)})},l=o=>{const{name:i,type:u,checked:s,value:a}=o.target;t(p=>({...p,[i]:u==="checkbox"?s:a}))};return v.jsxs("form",{onSubmit:r,className:" text-black p-4 bg-gray-100 rounded shadow-md ",children:[v.jsxs("div",{className:"grid grid-cols-2 gap-2 auto-cols-min",children:[v.jsx("label",{className:"block text-gray-700 font-bold mb-2 self-end",children:"ID:"}),v.jsx("input",{type:"text",name:"id",value:e.id,onChange:l,className:"w-full px-3 py-2 border rounded bg-white"}),v.jsx("label",{className:"block text-gray-700 self-end font-bold mb-2",children:"Category:"}),v.jsx("input",{type:"text",name:"category",value:e.category,onChange:l,className:"w-full px-3 py-2 border rounded bg-white"}),v.jsx("label",{className:"block text-gray-700 font-bold mb-2 self-end",children:"Difficulty:"}),v.jsx("input",{type:"text",name:"difficulty",value:e.difficulty,onChange:l,className:"w-full px-3 py-2 border rounded bg-white"}),v.jsx("label",{className:"block text-gray-700 font-bold mb-2 self-end",children:"Question:"}),v.jsx("input",{type:"text",name:"question",value:e.question,onChange:l,className:"w-full px-3 py-2 border rounded bg-white"}),v.jsx("label",{className:"block text-gray-700 font-bold mb-2 self-end",children:"Option 0:"}),v.jsx("input",{type:"text",name:"options",value:e.options[0],onChange:l,className:"w-full px-3 py-2 border rounded bg-white"}),v.jsx("label",{className:"block text-gray-700 font-bold mb-2 self-end",children:"Option 1:"}),v.jsx("input",{type:"text",name:"options",value:e.options[1],onChange:l,className:"w-full px-3 py-2 border rounded bg-white"}),v.jsx("label",{className:"block text-gray-700 font-bold mb-2 self-end",children:"Option 2:"}),v.jsx("input",{type:"text",name:"options",value:e.options[2],onChange:l,className:"w-full px-3 py-2 border rounded bg-white"}),v.jsx("label",{className:"block text-gray-700 font-bold mb-2 self-end",children:"Option 3:"}),v.jsx("input",{type:"text",name:"options",value:e.options[3],onChange:l,className:"w-full px-3 py-2 border rounded bg-white"}),v.jsx("label",{className:"block text-gray-700 font-bold mb-2 self-end",children:"Answer:"}),v.jsx("input",{type:"text",name:"answer",value:e.answer,onChange:l,className:"w-full px-3 py-2 border rounded bg-white"}),v.jsx("label",{className:"block text-gray-700 font-bold mb-2 self-end",children:"Favourited:"}),v.jsx("input",{type:"checkbox",name:"favourited",checked:e.favourited,onChange:l,className:"w-full px-3 py-2 border rounded bg-white"}),v.jsx("label",{className:"block text-gray-700 font-bold mb-2 self-end",children:"Timestamp:"}),v.jsx("input",{type:"date",name:"timestamp",value:e.timestamp.toISOString().split("T")[0],onChange:l,className:"w-full px-3 py-2 border rounded bg-white"})]}),v.jsx("button",{type:"submit",children:"Add question"})]})}function Yh(){return v.jsx(v.Fragment,{children:v.jsx(Kh,{})})}const Xh=({id:e})=>{const[t,n]=E.useState({id:0,category:"",difficulty:"medium",question:"Default start values",options:["a","b","c","d"],answer:"",favourited:!1,timestamp:new Date}),r=Il;E.useEffect(()=>{(async()=>{try{console.log("Fetched ID:",e);const u=Number(e);if(isNaN(u))throw new Error("Invalid ID");const p=(await(await fetch(`${r}/get-question-by-id/${e}`)).json())[0];p.timestamp=new Date(p.timestamp),n(p)}catch(u){console.error("Error fetching data:",u)}})()},[e,r]);const l=i=>{const{name:u,type:s,checked:a,value:p}=i.currentTarget;n(h=>({...h,[u]:s==="checkbox"?a:p}))},o=i=>{i.preventDefault(),console.log(t)};return v.jsxs("form",{onSubmit:o,className:"text-black p-4 bg-gray-100 rounded shadow-md",children:[v.jsxs("div",{className:"grid grid-cols-2 gap-2 auto-cols-min",children:[v.jsx("label",{className:"block text-gray-700 self-end font-bold mb-2",children:"Category:"}),v.jsx("input",{type:"text",name:"category",value:t.category,onChange:l,className:"w-full px-3 py-2 border rounded bg-white"}),v.jsx("label",{className:"block text-gray-700 font-bold mb-2 self-end",children:"Difficulty:"}),v.jsx("input",{type:"text",name:"difficulty",value:t.difficulty,onChange:l,className:"w-full px-3 py-2 border rounded bg-white"}),v.jsx("label",{className:"block text-gray-700 font-bold mb-2 self-end",children:"Question:"}),v.jsx("input",{type:"text",name:"question",value:t.question,onChange:l,className:"w-full px-3 py-2 border rounded bg-white"}),v.jsx("label",{className:"block text-gray-700 font-bold mb-2 self-end",children:"Option 0:"}),v.jsx("input",{type:"text",name:"options",value:t.options[0],onChange:l,className:"w-full px-3 py-2 border rounded bg-white"}),v.jsx("label",{className:"block text-gray-700 font-bold mb-2 self-end",children:"Option 1:"}),v.jsx("input",{type:"text",name:"options",value:t.options[1],onChange:l,className:"w-full px-3 py-2 border rounded bg-white"}),v.jsx("label",{className:"block text-gray-700 font-bold mb-2 self-end",children:"Option 2:"}),v.jsx("input",{type:"text",name:"options",value:t.options[2],onChange:l,className:"w-full px-3 py-2 border rounded bg-white"}),v.jsx("label",{className:"block text-gray-700 font-bold mb-2 self-end",children:"Option 3:"}),v.jsx("input",{type:"text",name:"options",value:t.options[3],onChange:l,className:"w-full px-3 py-2 border rounded bg-white"}),v.jsx("label",{className:"block text-gray-700 font-bold mb-2 self-end",children:"Answer:"}),v.jsx("input",{type:"text",name:"answer",value:t.answer,onChange:l,className:"w-full px-3 py-2 border rounded bg-white"}),v.jsx("label",{className:"block text-gray-700 font-bold mb-2 self-end",children:"Favourited:"}),v.jsx("input",{type:"checkbox",name:"favourited",checked:t.favourited,onChange:l,className:"w-full px-3 py-2 border rounded bg-white"}),v.jsx("label",{className:"block text-gray-700 font-bold mb-2 self-end",children:"Timestamp:"}),v.jsx("input",{type:"date",name:"timestamp",value:t.timestamp.toISOString().substr(0,10),onChange:l,className:"w-full px-3 py-2 border rounded bg-white"})]}),v.jsx("button",{type:"submit",className:"mt-4 px-4 py-2 bg-blue-500 text-white rounded",children:"Edit question"})]})},Gh=()=>{const{id:e}=lh();return v.jsx(Xh,{id:Number(e)})},Zh=()=>v.jsxs(gh,{children:[v.jsx(be,{path:"/",element:v.jsx(ho,{})}),v.jsx(be,{path:"/home",element:v.jsx(ho,{})}),v.jsx(be,{path:"/P1DAAF-Frontend/",element:v.jsx(ho,{})}),v.jsx(be,{path:"/quiz",element:v.jsx(Th,{})}),v.jsx(be,{path:"/questionbank",element:v.jsx(Hh,{})}),v.jsx(be,{path:"/questionbank/addquestion",element:v.jsx(Yh,{})}),v.jsx(be,{path:"/questionbank/editquestion/:id",element:v.jsx(Gh,{})})]}),Jh=()=>v.jsx("nav",{className:"bg-gray-700 p-4 w-full top-0 z-50",children:v.jsxs("ul",{className:"flex space-x-8",children:[v.jsx("li",{children:v.jsxs(ks,{to:"/home",className:"text-white flex items-center space-x-2 hover:text-gray-400",children:[v.jsx($h,{}),v.jsx("span",{children:"Home"})]})}),v.jsx("li",{children:v.jsxs(ks,{to:"/questionbank",className:"text-white flex items-center space-x-2 hover:text-gray-400",children:[v.jsx(Bh,{}),v.jsx("span",{children:"Question Bank"})]})})]})});function qh(){return v.jsx(Nh,{children:v.jsxs("div",{children:[v.jsx(Jh,{}),v.jsx(Zh,{})]})})}mo.createRoot(document.getElementById("root")).render(v.jsx(He.StrictMode,{children:v.jsx(qh,{})})); diff --git a/index.html b/index.html index 0a4a3ed..a27a985 100644 --- a/index.html +++ b/index.html @@ -5,7 +5,7 @@ Vite + React + TS - +