From 1838889a0c284f57ac7048a88d4b55629c73d13b Mon Sep 17 00:00:00 2001 From: Manuel Bustillo Date: Sun, 10 Nov 2024 20:52:48 +0100 Subject: [PATCH] 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} +
+
+ ) +}