From 1838889a0c284f57ac7048a88d4b55629c73d13b Mon Sep 17 00:00:00 2001 From: Manuel Bustillo Date: Sun, 10 Nov 2024 20:52:48 +0100 Subject: [PATCH 1/3] Extract a common TableOfContents component --- app/ui/arrangements/arrangements-table.tsx | 57 ++++++++-------------- app/ui/components/table-of-contents.tsx | 26 ++++++++++ 2 files changed, 45 insertions(+), 38 deletions(-) create mode 100644 app/ui/components/table-of-contents.tsx diff --git a/app/ui/arrangements/arrangements-table.tsx b/app/ui/arrangements/arrangements-table.tsx index 5f2f164..66e41d4 100644 --- a/app/ui/arrangements/arrangements-table.tsx +++ b/app/ui/arrangements/arrangements-table.tsx @@ -5,6 +5,7 @@ import React, { useState } from "react" import { TableArrangement } from '@/app/lib/definitions'; import { classNames } from "../components/button"; +import TableOfContents from "../components/table-of-contents"; export default function ArrangementsTable ({onArrangementSelected}: {onArrangementSelected: (arrangementId: string) => void}) { const [arrangements, setArrangements] = useState>([]); @@ -32,43 +33,23 @@ export default function ArrangementsTable ({onArrangementSelected}: {onArrangeme arrangements.length === 0 && loadArrangements(); return( -
- - - - - - - - - - - {arrangements.map((arrangement) => ( - - - - - - ))} - -
- Simulations -

- There are {arrangements.length} simmulations in the list -

-
- Name - - Discomfort - - Actions -
- {arrangement.name} - - {arrangement.discomfort} - - -
-
+ ( + + + {arrangement.name} + + + {arrangement.discomfort} + + + + + + )} + /> ); } \ No newline at end of file diff --git a/app/ui/components/table-of-contents.tsx b/app/ui/components/table-of-contents.tsx new file mode 100644 index 0000000..209af87 --- /dev/null +++ b/app/ui/components/table-of-contents.tsx @@ -0,0 +1,26 @@ +export default function TableOfContents({ headers, caption, elements, rowRender }: { headers: string[], caption: string, elements: Type[], rowRender: (element: Type) => JSX.Element }) { + return ( +
+ + + + + {headers.map((header) => ( + + ))} + + + + {elements.map((element) => rowRender(element))} + +
+ {caption} +

+ There are {elements.length} elements in the list +

+
+ {header} +
+
+ ) +} From 79b4e9ac82938b8f211137d74cd5ea9a2059c112 Mon Sep 17 00:00:00 2001 From: Manuel Bustillo Date: Sun, 10 Nov 2024 19:53:34 +0000 Subject: [PATCH 2/3] Add copyright notice --- app/ui/components/table-of-contents.tsx | 2 ++ 1 file changed, 2 insertions(+) diff --git a/app/ui/components/table-of-contents.tsx b/app/ui/components/table-of-contents.tsx index 209af87..70c39e2 100644 --- a/app/ui/components/table-of-contents.tsx +++ b/app/ui/components/table-of-contents.tsx @@ -1,3 +1,5 @@ +/* Copyright (C) 2024 Manuel Bustillo*/ + export default function TableOfContents({ headers, caption, elements, rowRender }: { headers: string[], caption: string, elements: Type[], rowRender: (element: Type) => JSX.Element }) { return (
From 2ea1fd26678706993c4b0b35232cda5136aa4211 Mon Sep 17 00:00:00 2001 From: Manuel Bustillo Date: Sun, 10 Nov 2024 20:55:03 +0100 Subject: [PATCH 3/3] Reuse the table of contents component for the guests list --- app/ui/guests/table.tsx | 110 ++++++++++++++++------------------------ 1 file changed, 45 insertions(+), 65 deletions(-) diff --git a/app/ui/guests/table.tsx b/app/ui/guests/table.tsx index 9df0f30..3504089 100644 --- a/app/ui/guests/table.tsx +++ b/app/ui/guests/table.tsx @@ -7,6 +7,7 @@ import React, { useState, useEffect } from 'react'; import { Guest } from '@/app/lib/definitions'; import { getCsrfToken } from '@/app/lib/utils'; import {classNames} from '@/app/ui/components/button'; +import TableOfContents from '../components/table-of-contents'; export default function guestsTable() { const [guests, setGuests] = useState>([]); @@ -50,69 +51,48 @@ export default function guestsTable() { guests.length === 0 && loadGuests(); return ( -
- - - - - - - - - - - - {guests.map((guest) => ( - - - - - - - ))} - -
- Guests -

- There are {guests.length} guests in the list -

-
- Name - - Group - - Status - Actions
- {guest.name} - - {guest.group_name} - - - - - {guest.status} - - - {guest.status === 'Considered' && ()} - {(guest.status === 'Invited' || guest.status === 'Tentative') && ( - <> - - {guest.status != 'Tentative' && } - - - )} -
-
- ); + ( + + + {guest.name} + + + {guest.group_name} + + + + + + {guest.status} + + + + {guest.status === 'Considered' && ()} + {(guest.status === 'Invited' || guest.status === 'Tentative') && ( + <> + + {guest.status != 'Tentative' && } + + + )} + + + )} + /> + ); }