diff --git a/client/src/components/base/loading/CloneChildren.tsx b/client/src/components/base/loading/CloneChildren.tsx new file mode 100644 index 0000000..1a04974 --- /dev/null +++ b/client/src/components/base/loading/CloneChildren.tsx @@ -0,0 +1,36 @@ +import React, { useMemo } from "react"; + +type CloneChildrenProps = { + count: number; +} & React.PropsWithChildren; + +/** Creates an array of cloned children elements with the specified count. Useful for creating loading skeletons. + * @param count The number of times to clone the children. + * @returns An array of cloned children elements. + * @example + * ```tsx + * + *
Child
+ *
+ * + * //The above example will render: + *
Child
+ *
Child
+ *
Child
+ * ``` + */ +export const CloneChildren = ({ + count, + children, +}: CloneChildrenProps) => { + + const childrenArray = useMemo(() => { + const array:React.ReactNode[] = [] + for (let i = 0; i < count; i++) { + array.push(< React.Fragment key={i}>{children}) + } + return array; + },[count,children]) + + return <>{childrenArray}; +}; \ No newline at end of file diff --git a/client/src/pages/dashboard/DashboardHomePage.tsx b/client/src/pages/dashboard/DashboardHomePage.tsx index 9fe9530..bd1bd6e 100644 --- a/client/src/pages/dashboard/DashboardHomePage.tsx +++ b/client/src/pages/dashboard/DashboardHomePage.tsx @@ -2,14 +2,15 @@ import {FaPlus} from "react-icons/all"; import {Link} from "wouter"; import {poll} from "@/api/call"; import {isLoaded} from "@/state/isLoaded"; -import {Skeleton} from "@/components/base/loading/Skeleton"; import {SortableTable} from "@/components/tables/SortedTable"; +import { CloneChildren } from "@/components/base/loading/CloneChildren"; +import { Skeleton } from "@/components/base/loading/Skeleton"; export default function DashboardHomePage() { const renderCounts = poll.use('getMonthlyRenderCounts'); if (!isLoaded(renderCounts)) { - return + return } return renderCounts ? : ; @@ -36,6 +37,24 @@ function MonthlyRenderTable({renderCounts}: {renderCounts: {month: string, rende ); } +function TableSkeleton({rows, cols}:{ rows: number, cols: number}){ + return ( +
+
+ +
+ +
+ +
+
+
+
+
+
+ ) +} + function EmptyDashboard() { return (