@@ -7,11 +7,6 @@ import {
77 BreadcrumbSeparator ,
88} from '@/components/ui/breadcrumb'
99
10- import { MonthlyRevenueChart } from '@/components/dashboard/MonthlyRevenueChart'
11- import { MostBorrowedBookChart } from '@/components/dashboard/MostBorrowedBookChart'
12- import { MontlyBorrowChart } from '@/components/dashboard/MontlyBorrowChart'
13- import { TopMembershipChart } from '@/components/dashboard/TopMembershipChart'
14- import { getAnalysis , getBorrowingHeatmapAnalysis } from '@/lib/api/analysis'
1510import { SITE_NAME } from '@/lib/consts'
1611import type { Metadata } from 'next'
1712import { LibrarySelector } from '@/components/dashboard/LibrarySelector'
@@ -23,7 +18,17 @@ import { getListLibraries } from '@/lib/api/library'
2318import { DateRange } from 'react-day-picker'
2419import { cookies } from 'next/headers'
2520import { Suspense } from 'react'
26- import { BorrowHeatmapChart } from '@/components/dashboard/BorrowHeatmapChart'
21+ import { AnalysisChartsWrapper } from '@/components/dashboard/AnalysisChartsWrapper'
22+ import {
23+ BorrowHeatmapWrapper ,
24+ ReturnHeatmapWrapper ,
25+ } from '@/components/dashboard/HeatmapWrapper'
26+ import { PowerUsersWrapper } from '@/components/dashboard/PowerUsersWrapper'
27+ import {
28+ AnalysisChartsLoading ,
29+ HeatmapChartLoading ,
30+ PowerUsersLoading ,
31+ } from '@/components/dashboard/ChartLoadingComponents'
2732
2833export const metadata : Metadata = {
2934 title : `Dashboard · ${ SITE_NAME } ` ,
@@ -50,7 +55,7 @@ export default async function DashboardPage({
5055 redirect ( '/' , RedirectType . replace )
5156 }
5257
53- const { from, to, limit = 5 , skip = 0 } = await searchParams
58+ const { from, to, skip , limit = 5 } = await searchParams
5459
5560 const cookieStore = await cookies ( )
5661 const cookieName = process . env . LIBRARY_COOKIE_NAME as string
@@ -67,25 +72,8 @@ export default async function DashboardPage({
6772 redirect ( '?' + sp . toString ( ) , RedirectType . replace )
6873 }
6974
70- const [ res , libsRes , heatmapRes ] = await Promise . all ( [
71- getAnalysis ( {
72- skip,
73- limit,
74- from : startOfDay ( parse ( from , 'dd-MM-yyyy' , new Date ( ) ) ) . toJSON ( ) ,
75- to : endOfDay ( parse ( to , 'dd-MM-yyyy' , new Date ( ) ) ) . toJSON ( ) ,
76- library_id : libID ! ,
77- } ) ,
78- getListLibraries ( { limit : 5 } ) ,
79- getBorrowingHeatmapAnalysis ( {
80- library_id : libID ! ,
81- start : startOfDay ( parse ( from , 'dd-MM-yyyy' , new Date ( ) ) ) . toJSON ( ) ,
82- end : endOfDay ( parse ( to , 'dd-MM-yyyy' , new Date ( ) ) ) . toJSON ( ) ,
83- } ) ,
84- ] )
85-
86- if ( 'error' in res ) {
87- return < div > { res . error } </ div >
88- }
75+ const libsRes = await getListLibraries ( { limit : 5 } )
76+
8977 if ( 'error' in libsRes ) {
9078 return < div > { libsRes . error } </ div >
9179 }
@@ -117,6 +105,9 @@ export default async function DashboardPage({
117105 redirect ( './?' + sp . toString ( ) , RedirectType . replace )
118106 }
119107
108+ const start = startOfDay ( parse ( from , 'dd-MM-yyyy' , new Date ( ) ) ) . toJSON ( )
109+ const end = endOfDay ( parse ( to , 'dd-MM-yyyy' , new Date ( ) ) ) . toJSON ( )
110+
120111 return (
121112 < div >
122113 < h1 className = "text-2xl font-semibold" > Libraries</ h1 >
@@ -147,15 +138,30 @@ export default async function DashboardPage({
147138 range = { { from : fromDate , to : toDate } }
148139 onChangeAction = { onDateRangeChange }
149140 />
150- < MostBorrowedBookChart data = { res . data . book } />
151- < TopMembershipChart data = { res . data . membership } />
152- < MontlyBorrowChart data = { res . data . borrowing } />
153- < MonthlyRevenueChart data = { res . data . revenue } />
154- { 'error' in heatmapRes ? (
155- < div > { heatmapRes . error } </ div >
156- ) : (
157- < BorrowHeatmapChart data = { heatmapRes . data } />
158- ) }
141+ < Suspense fallback = { < AnalysisChartsLoading /> } >
142+ < AnalysisChartsWrapper
143+ libraryId = { libID ! }
144+ from = { start }
145+ to = { end }
146+ limit = { 5 }
147+ skip = { 0 }
148+ />
149+ </ Suspense >
150+ < Suspense fallback = { < HeatmapChartLoading /> } >
151+ < BorrowHeatmapWrapper libraryId = { libID ! } start = { start } end = { end } />
152+ </ Suspense >
153+ < Suspense fallback = { < HeatmapChartLoading /> } >
154+ < ReturnHeatmapWrapper libraryId = { libID ! } start = { start } end = { end } />
155+ </ Suspense >
156+ < Suspense fallback = { < PowerUsersLoading /> } >
157+ < PowerUsersWrapper
158+ libraryId = { libID ! }
159+ from = { start }
160+ to = { end }
161+ limit = { limit }
162+ skip = { skip }
163+ />
164+ </ Suspense >
159165 </ div >
160166 </ div >
161167 )
0 commit comments