added a dynamic category page
Signed-off-by: Alex Stan <alex.stan.2010@proton.me>
This commit is contained in:
parent
3b362da028
commit
43db39291e
3 changed files with 112 additions and 32 deletions
|
@ -1,20 +1,20 @@
|
|||
'use client';
|
||||
import { useState } from "react";
|
||||
|
||||
const Form = <T,>({ initialData, submitFunction }) => {
|
||||
const [formData, setFormData] = useState( initialData );
|
||||
export enum FieldType {
|
||||
number = 'number',
|
||||
text = 'text'
|
||||
}
|
||||
|
||||
const handleSubmit = async (event) => {
|
||||
event.preventDefault();
|
||||
export type FormFields = {
|
||||
type: FieldType,
|
||||
name: string,
|
||||
label: string,
|
||||
required: boolean
|
||||
}
|
||||
|
||||
//q = formData;
|
||||
|
||||
//addQuestion( q );
|
||||
|
||||
//console.log( `Adding question ${JSON.stringify(q)}` );
|
||||
|
||||
await submitFunction( formData );
|
||||
}
|
||||
const Form = <T,>({ fields, onSubmit }) => {
|
||||
const [formData, setFormData] = useState({});
|
||||
|
||||
const handleChange = (event) => {
|
||||
const { name, value } = event.target;
|
||||
|
@ -24,20 +24,26 @@ const Form = <T,>({ initialData, submitFunction }) => {
|
|||
}));
|
||||
}
|
||||
|
||||
const handleSubmit = (event) => {
|
||||
event.preventDefault();
|
||||
onSubmit( formData );
|
||||
}
|
||||
|
||||
return (
|
||||
<form onSubmit={handleSubmit} className="flex">
|
||||
<div>
|
||||
{Object.entries( initialData ).map( (elem) => {
|
||||
return(
|
||||
<form onSubmit={handleSubmit}>
|
||||
{fields.map( (field) => {
|
||||
return (
|
||||
<div key={field.name}>
|
||||
<label>{field.label}</label>
|
||||
<input
|
||||
type = { typeof( elem[1] ) == typeof( 0 ) ? "number" : "text" /* pretty hacky, we should change this */ }
|
||||
id = {elem[0]}
|
||||
name = {elem[0]}
|
||||
value = {formData[elem[0]]}
|
||||
onChange = {handleChange}
|
||||
required
|
||||
/>)})}
|
||||
type={field.type}
|
||||
name={field.name}
|
||||
value={formData[field.name] || ''}
|
||||
onChange={handleChange}
|
||||
required={field.required}
|
||||
/>
|
||||
</div>
|
||||
)})}
|
||||
<button type="submit">Submit</button>
|
||||
</form>
|
||||
);
|
||||
|
|
67
app/learn/[category]/page.tsx
Normal file
67
app/learn/[category]/page.tsx
Normal file
|
@ -0,0 +1,67 @@
|
|||
'use client';
|
||||
import { useState } from 'react'
|
||||
import { Dialog, DialogPanel } from '@headlessui/react'
|
||||
import { Bars3Icon, XMarkIcon } from '@heroicons/react/24/outline'
|
||||
|
||||
const Page = ({ params }: { params: { category: string }}) => {
|
||||
const [mobileMenuOpen, setMobileMenuOpen] = useState(false)
|
||||
|
||||
return (
|
||||
<div className="bg-black">
|
||||
|
||||
<div className="relative isolate px-6 pt-14 lg:px-8">
|
||||
<div style={{ display:"flex", alignItems: 'center', justifyContent: 'center', paddingTop:'40px'}}><img className="flex" src="/logo-no-background.png" height="auto" width="40%" style={{ alignSelf: 'center'}}></img></div>
|
||||
<div
|
||||
className="absolute inset-x-0 -top-40 -z-10 transform-gpu overflow-hidden blur-3xl sm:-top-80"
|
||||
aria-hidden="true"
|
||||
>
|
||||
<div
|
||||
className="relative left-[calc(50%-11rem)] aspect-[1155/678] w-[36.125rem] -translate-x-1/2 rotate-[30deg] bg-gradient-to-tr from-[#ff80b5] to-[#9089fc] opacity-30 sm:left-[calc(50%-30rem)] sm:w-[72.1875rem]"
|
||||
style={{
|
||||
clipPath:
|
||||
'polygon(74.1% 44.1%, 100% 61.6%, 97.5% 26.9%, 85.5% 0.1%, 80.7% 2%, 72.5% 32.5%, 60.2% 62.4%, 52.4% 68.1%, 47.5% 58.3%, 45.2% 34.5%, 27.5% 76.7%, 0.1% 64.9%, 17.9% 100%, 27.6% 76.8%, 76.1% 97.7%, 74.1% 44.1%)',
|
||||
}}
|
||||
/>
|
||||
</div>
|
||||
<div className="mx-auto max-w-2xl py-32 sm:py-48 lg:py-56">
|
||||
<div className="text-center">
|
||||
<h1 className="text-4xl font-bold tracking-tight text-gray-50">
|
||||
[insert question about {params.category}]
|
||||
</h1>
|
||||
<p className="mt-6 text-lg leading-8 text-gray-200">
|
||||
[Insert hidden answer]
|
||||
</p>
|
||||
<a href="#" className="text-sm font-semibold leading-6 text-gray-200">
|
||||
Show answer
|
||||
</a>
|
||||
<div className="mt-10 flex items-center justify-center gap-x-6">
|
||||
<a
|
||||
href="#"
|
||||
className="rounded-md bg-indigo-600 px-3.5 py-2.5 text-sm font-semibold text-white shadow-sm hover:bg-indigo-500 focus-visible:outline focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-indigo-600"
|
||||
>
|
||||
I knew that!
|
||||
</a>
|
||||
<a href="#" className="text-sm font-semibold leading-6 text-gray-300">
|
||||
I didn't know that!
|
||||
</a>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div
|
||||
className="absolute inset-x-0 top-[calc(100%-13rem)] -z-10 transform-gpu overflow-hidden blur-3xl sm:top-[calc(100%-30rem)]"
|
||||
aria-hidden="true"
|
||||
>
|
||||
<div
|
||||
className="relative left-[calc(50%+3rem)] aspect-[1155/678] w-[36.125rem] -translate-x-1/2 bg-gradient-to-tr from-[#ff80b5] to-[#9089fc] opacity-30 sm:left-[calc(50%+36rem)] sm:w-[72.1875rem]"
|
||||
style={{
|
||||
clipPath:
|
||||
'polygon(74.1% 44.1%, 100% 61.6%, 97.5% 26.9%, 85.5% 0.1%, 80.7% 2%, 72.5% 32.5%, 60.2% 62.4%, 52.4% 68.1%, 47.5% 58.3%, 45.2% 34.5%, 27.5% 76.7%, 0.1% 64.9%, 17.9% 100%, 27.6% 76.8%, 76.1% 97.7%, 74.1% 44.1%)',
|
||||
}}
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
export default Page;
|
|
@ -8,6 +8,13 @@ export type Session = {
|
|||
// user: string;
|
||||
}
|
||||
|
||||
export type SessionState = {
|
||||
answered: number;
|
||||
wrong: number;
|
||||
right: number;
|
||||
category: string;
|
||||
}
|
||||
|
||||
export const getSession = async (id: number): Promise<Session> => {
|
||||
return makeGetRequest( `sessions/${id}/` );
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue