From 305d37b9d4a18f3c4ad7c0d1b7189564d42014b5 Mon Sep 17 00:00:00 2001 From: Sebastian Sebald Date: Tue, 31 Oct 2023 14:01:00 +0100 Subject: [PATCH] loading stuff --- app/(stats)/composition/[id]/loading.tsx | 15 +---- .../compositions/[[...range]]/loading.tsx | 19 +++++++ .../compositions/[[...range]]/page.tsx | 29 ++++++---- lib/db/db.ts | 13 +++-- ui/skeleton.tsx | 56 +++++++++++++++++++ 5 files changed, 103 insertions(+), 29 deletions(-) create mode 100644 app/(stats)/compositions/[[...range]]/loading.tsx diff --git a/app/(stats)/composition/[id]/loading.tsx b/app/(stats)/composition/[id]/loading.tsx index 09cce41f..6ae7020f 100644 --- a/app/(stats)/composition/[id]/loading.tsx +++ b/app/(stats)/composition/[id]/loading.tsx @@ -2,21 +2,12 @@ import { Skeleton, HeadlineSkeleton, CardChartSkeleton } from '@/ui'; export const Loading = () => ( - -
- {' '} - {' '} - -
-
- - -
- - +
+ +
); diff --git a/app/(stats)/compositions/[[...range]]/loading.tsx b/app/(stats)/compositions/[[...range]]/loading.tsx new file mode 100644 index 00000000..af34d7ab --- /dev/null +++ b/app/(stats)/compositions/[[...range]]/loading.tsx @@ -0,0 +1,19 @@ +import { Skeleton, HeadlineSkeleton, CardTableSkeleton } from '@/ui'; + +export const Loading = () => ( + + +
+ {' '} + {' '} + +
+
+ + +
+ +
+); + +export default Loading; diff --git a/app/(stats)/compositions/[[...range]]/page.tsx b/app/(stats)/compositions/[[...range]]/page.tsx index 3c85a779..50e260d8 100644 --- a/app/(stats)/compositions/[[...range]]/page.tsx +++ b/app/(stats)/compositions/[[...range]]/page.tsx @@ -7,7 +7,7 @@ import { getTournamentsCount } from '@/lib/db/tournaments'; import { formatDate, fromDate, toDate, today } from '@/lib/utils/date.utils'; import { fromDateRange } from '@/lib/utils/url.utils'; -import { Caption, Inline, Title } from '@/ui'; +import { Caption, CardTableSkeleton, Inline, Title } from '@/ui'; import { Calendar, Rocket, Trophy } from '@/ui/icons'; import { StatsHint } from '@/ui/stats/stats-hint'; @@ -63,6 +63,13 @@ const getStats = async (from: Date, to: Date | undefined) => { }; }; +// Content (wrapped for suspense) +// --------------- +const Content = async ({ from, to }: { from: Date; to?: Date }) => { + const { stats } = await getStats(from, to); + return ; +}; + // Props // --------------- interface PageProps { @@ -83,7 +90,7 @@ const CompositionsPage = async ({ params }: PageProps) => { const from = fromDate(range ? range.from : pointsUpdateDate); const to = range && range.to ? fromDate(range.to) : undefined; - const { stats, meta } = await getStats(from, to); + const { meta } = await getStats(from, to); return ( <> @@ -113,16 +120,16 @@ const CompositionsPage = async ({ params }: PageProps) => { - loading...}> -
-
- -
-
- -
+
+
+ }> + +
- +
+ +
+
); }; diff --git a/lib/db/db.ts b/lib/db/db.ts index 952adcdd..e1a2dd4f 100644 --- a/lib/db/db.ts +++ b/lib/db/db.ts @@ -45,12 +45,13 @@ export interface Database { // --------------- export const db = new Kysely({ dialect: new MysqlDialect({ - pool: createPool({ - host: process.env.DATABASE_HOST, - user: process.env.DATABASE_USERNAME, - password: process.env.DATABASE_PASSWORD, - database: 'main', - }), + pool: async () => + createPool({ + host: process.env.DATABASE_HOST, + user: process.env.DATABASE_USERNAME, + password: process.env.DATABASE_PASSWORD, + database: 'main', + }), }), // log: ['query', 'error'], }); diff --git a/ui/skeleton.tsx b/ui/skeleton.tsx index c90f90b2..2612ff45 100644 --- a/ui/skeleton.tsx +++ b/ui/skeleton.tsx @@ -104,3 +104,59 @@ export const CardChartSkeleton = () => ( ); + +// Loading: Chart with Card +// --------------- +const Row = ({ className }: { className?: string }) => ( + <> +
+ +
+
+ +
+
+ +
+
+ +
+
+ +
+
+ +
+
+ +
+
+ +
+
+ +
+ +); + +export const RowDivider = () => ( +
+); + +export const CardTableSkeleton = () => ( + +
+ + + + + + + + + + + +
+
+);