diff --git a/frontend/app/actions.ts b/frontend/app/actions.ts index 1c5d6e5..d78f225 100644 --- a/frontend/app/actions.ts +++ b/frontend/app/actions.ts @@ -11,6 +11,7 @@ import { TutorFormEventsQuery, TutorFormEventsDocument, } from "@/lib/gql/generated/graphql"; +import {eventBroker} from "@/lib/eventBroker"; export const getEvents = async (): Promise => { await new Promise((resolve) => setTimeout(resolve, 250)); @@ -28,7 +29,7 @@ export const addTutor = async (formState: FormState, formData: FormData) => { const firstName = formData.get("fn")?.toString() || ""; const lastName = formData.get("sn")?.toString() || ""; const email = formData.get("email")?.toString() || ""; - const eventsAvailable = [1, 2]; + const eventsAvailable = eventBroker.getEvents(); const vars: AddTutorMutationVariables = { firstName, diff --git a/frontend/app/form-tutor/ui/table/columns.tsx b/frontend/app/form-tutor/ui/table/columns.tsx index 5ba33bb..e11653a 100644 --- a/frontend/app/form-tutor/ui/table/columns.tsx +++ b/frontend/app/form-tutor/ui/table/columns.tsx @@ -3,6 +3,7 @@ import { ColumnDef } from "@tanstack/react-table"; import { Checkbox } from "@/components/ui/checkbox"; import { TutorFormEventsQuery } from "@/lib/gql/generated/graphql"; +import { eventBroker } from "@/lib/eventBroker"; export const columns: ColumnDef[] = [ { @@ -13,7 +14,16 @@ export const columns: ColumnDef[] = [ row.toggleSelected(!!value)} + onCheckedChange={(value) => { + row.toggleSelected(!!value) + + if(row.getIsSelected()){ + eventBroker.removeEvent(row.original.ID) + } else { + eventBroker.addEvent(row.original.ID) + } + + }} aria-label="Ich kann diese Vorlesung halten" /> diff --git a/frontend/lib/eventBroker.ts b/frontend/lib/eventBroker.ts new file mode 100644 index 0000000..ae12be0 --- /dev/null +++ b/frontend/lib/eventBroker.ts @@ -0,0 +1,18 @@ +class EventBroker { + selectedEvents: number[] = [] + + addEvent(eventID: number):void { + this.selectedEvents.push(eventID) + } + + removeEvent(eventID: number): void { + const index = this.selectedEvents.indexOf(eventID) + if (index > -1) this.selectedEvents.splice(index, 1) + } + + getEvents(): number[] { + return this.selectedEvents + } +} + +export let eventBroker = new EventBroker() \ No newline at end of file