From 471317b213d293569c74389067f13beeca6e0732 Mon Sep 17 00:00:00 2001 From: Alexander Date: Mon, 3 Jun 2024 19:24:45 +0100 Subject: [PATCH] Updates --- assets/{index-BPW6ToxG.js => index-uzNBgupo.js} | 2 +- index.html | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) rename assets/{index-BPW6ToxG.js => index-uzNBgupo.js} (95%) diff --git a/assets/index-BPW6ToxG.js b/assets/index-uzNBgupo.js similarity index 95% rename from assets/index-BPW6ToxG.js rename to assets/index-uzNBgupo.js index e7b7d7d..f32aa66 100644 --- a/assets/index-BPW6ToxG.js +++ b/assets/index-uzNBgupo.js @@ -64,4 +64,4 @@ Error generating stack: `+o.message+` * LICENSE.md file in the root directory of this source tree. * * @license MIT - */function ai(){return ai=Object.assign?Object.assign.bind():function(e){for(var t=1;t=0)&&(n[l]=e[l]);return n}function wh(e){return!!(e.metaKey||e.altKey||e.ctrlKey||e.shiftKey)}function xh(e,t){return e.button===0&&(!t||t==="_self")&&!wh(e)}const Sh=["onClick","relative","reloadDocument","replace","state","target","to","preventScrollReset","unstable_viewTransition"],kh="6";try{window.__reactRouterVersion=kh}catch{}const Eh="startTransition",xs=yf[Eh];function Ch(e){let{basename:t,children:n,future:r,window:l}=e,o=E.useRef();o.current==null&&(o.current=Lp({window:l,v5Compat:!0}));let i=o.current,[u,s]=E.useState({action:i.action,location:i.location}),{v7_startTransition:a}=r||{},h=E.useCallback(p=>{a&&xs?xs(()=>s(p)):s(p)},[s,a]);return E.useLayoutEffect(()=>i.listen(h),[i,h]),E.createElement(vh,{basename:t,children:n,location:u.location,navigationType:u.action,navigator:i,future:r})}const Nh=typeof window<"u"&&typeof window.document<"u"&&typeof window.document.createElement<"u",_h=/^(?:[a-z][a-z0-9+.-]*:|\/\/)/i,Ss=E.forwardRef(function(t,n){let{onClick:r,relative:l,reloadDocument:o,replace:i,state:u,target:s,to:a,preventScrollReset:h,unstable_viewTransition:p}=t,m=gh(t,Sh),{basename:g}=E.useContext(Ut),w,x=!1;if(typeof a=="string"&&_h.test(a)&&(w=a,Nh))try{let d=new URL(window.location.href),y=a.startsWith("//")?new URL(d.protocol+a):new URL(a),k=lu(y.pathname,g);y.origin===d.origin&&k!=null?a=k+y.search+y.hash:x=!0}catch{}let C=th(a,{relative:l}),f=Ph(a,{replace:i,state:u,target:s,preventScrollReset:h,relative:l,unstable_viewTransition:p});function c(d){r&&r(d),d.defaultPrevented||f(d)}return E.createElement("a",ai({},m,{href:w||C,onClick:x||o?r:c,ref:n,target:s}))});var ks;(function(e){e.UseScrollRestoration="useScrollRestoration",e.UseSubmit="useSubmit",e.UseSubmitFetcher="useSubmitFetcher",e.UseFetcher="useFetcher",e.useViewTransitionState="useViewTransitionState"})(ks||(ks={}));var Es;(function(e){e.UseFetcher="useFetcher",e.UseFetchers="useFetchers",e.UseScrollRestoration="useScrollRestoration"})(Es||(Es={}));function Ph(e,t){let{target:n,replace:r,state:l,preventScrollReset:o,relative:i,unstable_viewTransition:u}=t===void 0?{}:t,s=Dl(),a=Ol(),h=Yc(e,{relative:i});return E.useCallback(p=>{if(xh(p,n)){p.preventDefault();let m=r!==void 0?r:dl(a)===dl(h);s(e,{replace:m,state:l,preventScrollReset:o,relative:i,unstable_viewTransition:u})}},[a,s,h,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 Cs({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 jh=()=>["Science","Geography","History","Mathematics","Pop Culture","Music","Literature","Favourited"],Lh=()=>["easy","medium","hard","all"];function po(){const e=jh(),t=Lh(),[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=h=>{r(h.target.value)},a=h=>{o(h.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(Cs,{name:"Category",contentArr:e,handleDropdown:s}),v.jsx(Cs,{name:"Difficulty",contentArr:t,handleDropdown:a})]}),v.jsx(lr,{name:"START QUIZ",color:"orange",handler:u})]})}function zh(){return v.jsx(v.Fragment,{children:v.jsx("h1",{children:"Quiz component "})})}var Zc={color:void 0,size:void 0,className:void 0,style:void 0,attr:void 0},Ns=He.createContext&&He.createContext(Zc),Th=["attr","size","title"];function Rh(e,t){if(e==null)return{};var n=Oh(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 Oh(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),Jc(t.child)))}function Il(e){return t=>He.createElement(Fh,hl({attr:ml({},e.attr)},t),Jc(e.child))}function Fh(e){var t=n=>{var{attr:r,size:l,title:o}=e,i=Rh(e,Th),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 Ns!==void 0?He.createElement(Ns.Consumer,null,n=>t(n)):t(Zc)}function Uh(e){return Il({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 $h(e){return Il({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 Bh(e){return Il({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 Ah(e){return Il({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 Vh({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(Bh,{}),handler:n,name:"Edit"}),v.jsx(lr,{color:"red",preIcon:v.jsx(Ah,{}),handler:t,name:"Delete"})]})]})}function Wh({questions:e,setAllQuestions:t}){const n=o=>{console.log(`Deleting question with id: ${o}`),fetch(`http://localhost:3000/delete-post/${o}`,{method:"DELETE",headers:{"Content-Type":"application/json"}}).then(i=>{if(!i.ok)throw new Error(`HTTP error! status: ${i.status}`);return i.text()}).then(i=>{console.log("Delete response:",i),t(u=>u.filter(s=>s.id!==o))}).catch(i=>{console.error("Error:",i)})},r=Dl(),l=o=>{console.log(`Editing question with id: ${o}`),r(`/questionbank/editquestion/${o}`)};return v.jsx("div",{className:"question-bank-table",children:e.map(o=>v.jsx(Vh,{question:o,onDelete:()=>n(o.id),onEdit:()=>l(o.id)},o.id))})}var Qh={};function Hh(){const[e,t]=E.useState([]),n=Dl(),r=Qh.apiURL,l=()=>{n("/home")};function o(){n("/questionbank/addquestion")}return E.useEffect(()=>{console.log(`${r}`),fetch(`${r}`,{method:"GET",headers:{"Content-Type":"application/json"}}).then(i=>i.json()).then(i=>{t(i)}).catch(i=>{console.error("Error:",i)})},[]),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(Wh,{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=l=>{l.preventDefault(),fetch("http://localhost:3000/create-question",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(e)}).then(o=>o.json()).then(o=>{console.log(o)}).catch(o=>{console.error("Error:",o)})},r=l=>{const{name:o,type:i,checked:u,value:s}=l.target;t(a=>({...a,[o]:i==="checkbox"?u:s}))};return v.jsxs("form",{onSubmit:n,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:r,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:r,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:r,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:r,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:r,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:r,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:r,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:r,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:r,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:r,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:r,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});E.useEffect(()=>{(async()=>{try{console.log("Fetched ID:",e);const i=Number(e);if(isNaN(i))throw new Error("Invalid ID");const a=(await(await fetch(`http://localhost:3000/get-question-by-id/${e}`)).json())[0];a.timestamp=new Date(a.timestamp),n(a)}catch(i){console.error("Error fetching data:",i)}})()},[e]);const r=o=>{const{name:i,type:u,checked:s,value:a}=o.currentTarget;n(h=>({...h,[i]:u==="checkbox"?s:a}))},l=o=>{o.preventDefault(),console.log(t)};return v.jsxs("form",{onSubmit:l,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:r,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:r,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:r,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:r,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:r,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:r,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:r,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:r,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:r,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:r,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}=rh();return v.jsx(Xh,{id:Number(e)})},Zh=()=>v.jsxs(yh,{children:[v.jsx(be,{path:"/",element:v.jsx(po,{})}),v.jsx(be,{path:"/home",element:v.jsx(po,{})}),v.jsx(be,{path:"/P1DAAF-Frontend/",element:v.jsx(po,{})}),v.jsx(be,{path:"/quiz",element:v.jsx(zh,{})}),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(Ss,{to:"/home",className:"text-white flex items-center space-x-2 hover:text-gray-400",children:[v.jsx(Uh,{}),v.jsx("span",{children:"Home"})]})}),v.jsx("li",{children:v.jsxs(Ss,{to:"/questionbank",className:"text-white flex items-center space-x-2 hover:text-gray-400",children:[v.jsx($h,{}),v.jsx("span",{children:"Question Bank"})]})})]})});function qh(){return v.jsx(Ch,{children:v.jsxs("div",{children:[v.jsx(Jh,{}),v.jsx(Zh,{})]})})}ho.createRoot(document.getElementById("root")).render(v.jsx(He.StrictMode,{children:v.jsx(qh,{})})); + */function ai(){return ai=Object.assign?Object.assign.bind():function(e){for(var t=1;t=0)&&(n[l]=e[l]);return n}function wh(e){return!!(e.metaKey||e.altKey||e.ctrlKey||e.shiftKey)}function xh(e,t){return e.button===0&&(!t||t==="_self")&&!wh(e)}const Sh=["onClick","relative","reloadDocument","replace","state","target","to","preventScrollReset","unstable_viewTransition"],kh="6";try{window.__reactRouterVersion=kh}catch{}const Eh="startTransition",xs=yf[Eh];function Ch(e){let{basename:t,children:n,future:r,window:l}=e,o=E.useRef();o.current==null&&(o.current=Lp({window:l,v5Compat:!0}));let i=o.current,[u,s]=E.useState({action:i.action,location:i.location}),{v7_startTransition:a}=r||{},h=E.useCallback(p=>{a&&xs?xs(()=>s(p)):s(p)},[s,a]);return E.useLayoutEffect(()=>i.listen(h),[i,h]),E.createElement(vh,{basename:t,children:n,location:u.location,navigationType:u.action,navigator:i,future:r})}const Nh=typeof window<"u"&&typeof window.document<"u"&&typeof window.document.createElement<"u",_h=/^(?:[a-z][a-z0-9+.-]*:|\/\/)/i,Ss=E.forwardRef(function(t,n){let{onClick:r,relative:l,reloadDocument:o,replace:i,state:u,target:s,to:a,preventScrollReset:h,unstable_viewTransition:p}=t,m=gh(t,Sh),{basename:g}=E.useContext(Ut),w,x=!1;if(typeof a=="string"&&_h.test(a)&&(w=a,Nh))try{let d=new URL(window.location.href),y=a.startsWith("//")?new URL(d.protocol+a):new URL(a),k=lu(y.pathname,g);y.origin===d.origin&&k!=null?a=k+y.search+y.hash:x=!0}catch{}let C=th(a,{relative:l}),f=Ph(a,{replace:i,state:u,target:s,preventScrollReset:h,relative:l,unstable_viewTransition:p});function c(d){r&&r(d),d.defaultPrevented||f(d)}return E.createElement("a",ai({},m,{href:w||C,onClick:x||o?r:c,ref:n,target:s}))});var ks;(function(e){e.UseScrollRestoration="useScrollRestoration",e.UseSubmit="useSubmit",e.UseSubmitFetcher="useSubmitFetcher",e.UseFetcher="useFetcher",e.useViewTransitionState="useViewTransitionState"})(ks||(ks={}));var Es;(function(e){e.UseFetcher="useFetcher",e.UseFetchers="useFetchers",e.UseScrollRestoration="useScrollRestoration"})(Es||(Es={}));function Ph(e,t){let{target:n,replace:r,state:l,preventScrollReset:o,relative:i,unstable_viewTransition:u}=t===void 0?{}:t,s=Dl(),a=Ol(),h=Yc(e,{relative:i});return E.useCallback(p=>{if(xh(p,n)){p.preventDefault();let m=r!==void 0?r:dl(a)===dl(h);s(e,{replace:m,state:l,preventScrollReset:o,relative:i,unstable_viewTransition:u})}},[a,s,h,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 Cs({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 jh=()=>["Science","Geography","History","Mathematics","Pop Culture","Music","Literature","Favourited"],Lh=()=>["easy","medium","hard","all"];function po(){const e=jh(),t=Lh(),[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=h=>{r(h.target.value)},a=h=>{o(h.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(Cs,{name:"Category",contentArr:e,handleDropdown:s}),v.jsx(Cs,{name:"Difficulty",contentArr:t,handleDropdown:a})]}),v.jsx(lr,{name:"START QUIZ",color:"orange",handler:u})]})}function zh(){return v.jsx(v.Fragment,{children:v.jsx("h1",{children:"Quiz component "})})}var Zc={color:void 0,size:void 0,className:void 0,style:void 0,attr:void 0},Ns=He.createContext&&He.createContext(Zc),Th=["attr","size","title"];function Rh(e,t){if(e==null)return{};var n=Oh(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 Oh(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),Jc(t.child)))}function Il(e){return t=>He.createElement(Fh,hl({attr:ml({},e.attr)},t),Jc(e.child))}function Fh(e){var t=n=>{var{attr:r,size:l,title:o}=e,i=Rh(e,Th),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 Ns!==void 0?He.createElement(Ns.Consumer,null,n=>t(n)):t(Zc)}function Uh(e){return Il({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 $h(e){return Il({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 Bh(e){return Il({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 Ah(e){return Il({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 Vh({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(Bh,{}),handler:n,name:"Edit"}),v.jsx(lr,{color:"red",preIcon:v.jsx(Ah,{}),handler:t,name:"Delete"})]})]})}function Wh({questions:e,setAllQuestions:t}){const n=o=>{console.log(`Deleting question with id: ${o}`),fetch(`http://localhost:3000/delete-post/${o}`,{method:"DELETE",headers:{"Content-Type":"application/json"}}).then(i=>{if(!i.ok)throw new Error(`HTTP error! status: ${i.status}`);return i.text()}).then(i=>{console.log("Delete response:",i),t(u=>u.filter(s=>s.id!==o))}).catch(i=>{console.error("Error:",i)})},r=Dl(),l=o=>{console.log(`Editing question with id: ${o}`),r(`/questionbank/editquestion/${o}`)};return v.jsx("div",{className:"question-bank-table",children:e.map(o=>v.jsx(Vh,{question:o,onDelete:()=>n(o.id),onEdit:()=>l(o.id)},o.id))})}var Qh={};function Hh(){const[e,t]=E.useState([]),n=Dl(),r=Qh.apiURL,l=()=>{n("/home")};function o(){n("/questionbank/addquestion")}return E.useEffect(()=>{console.log(`URL es: ${r}`),fetch(`${r}`,{method:"GET",headers:{"Content-Type":"application/json"}}).then(i=>i.json()).then(i=>{t(i)}).catch(i=>{console.error("Error:",i)})},[]),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(Wh,{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=l=>{l.preventDefault(),fetch("http://localhost:3000/create-question",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(e)}).then(o=>o.json()).then(o=>{console.log(o)}).catch(o=>{console.error("Error:",o)})},r=l=>{const{name:o,type:i,checked:u,value:s}=l.target;t(a=>({...a,[o]:i==="checkbox"?u:s}))};return v.jsxs("form",{onSubmit:n,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:r,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:r,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:r,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:r,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:r,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:r,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:r,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:r,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:r,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:r,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:r,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});E.useEffect(()=>{(async()=>{try{console.log("Fetched ID:",e);const i=Number(e);if(isNaN(i))throw new Error("Invalid ID");const a=(await(await fetch(`http://localhost:3000/get-question-by-id/${e}`)).json())[0];a.timestamp=new Date(a.timestamp),n(a)}catch(i){console.error("Error fetching data:",i)}})()},[e]);const r=o=>{const{name:i,type:u,checked:s,value:a}=o.currentTarget;n(h=>({...h,[i]:u==="checkbox"?s:a}))},l=o=>{o.preventDefault(),console.log(t)};return v.jsxs("form",{onSubmit:l,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:r,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:r,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:r,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:r,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:r,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:r,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:r,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:r,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:r,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:r,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}=rh();return v.jsx(Xh,{id:Number(e)})},Zh=()=>v.jsxs(yh,{children:[v.jsx(be,{path:"/",element:v.jsx(po,{})}),v.jsx(be,{path:"/home",element:v.jsx(po,{})}),v.jsx(be,{path:"/P1DAAF-Frontend/",element:v.jsx(po,{})}),v.jsx(be,{path:"/quiz",element:v.jsx(zh,{})}),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(Ss,{to:"/home",className:"text-white flex items-center space-x-2 hover:text-gray-400",children:[v.jsx(Uh,{}),v.jsx("span",{children:"Home"})]})}),v.jsx("li",{children:v.jsxs(Ss,{to:"/questionbank",className:"text-white flex items-center space-x-2 hover:text-gray-400",children:[v.jsx($h,{}),v.jsx("span",{children:"Question Bank"})]})})]})});function qh(){return v.jsx(Ch,{children:v.jsxs("div",{children:[v.jsx(Jh,{}),v.jsx(Zh,{})]})})}ho.createRoot(document.getElementById("root")).render(v.jsx(He.StrictMode,{children:v.jsx(qh,{})})); diff --git a/index.html b/index.html index fece27f..a86bafa 100644 --- a/index.html +++ b/index.html @@ -5,7 +5,7 @@ Vite + React + TS - +