@@ -2,6 +2,7 @@ import React from 'react';
22import { fetchMoviesWithComments , fetchMoviesByYear , fetchDirectorStats } from '@/lib/api' ;
33import { MovieWithComments , YearlyStats , DirectorStats } from '@/types/aggregations' ;
44import styles from './aggregations.module.css' ;
5+ import ExpandableTable from '@/components/ExpandableTable/ExpandableTable' ;
56
67export default async function AggregationsPage ( ) {
78 const MOVIES_WITH_COMMENTS_LIMIT = 5 ;
@@ -38,43 +39,48 @@ export default async function AggregationsPage() {
3839 < section className = { styles . section } >
3940 < h2 className = { styles . sectionTitle } > Movies with Recent Comments</ h2 >
4041 { commentsData . success && commentsData . data ? (
41- < div className = { styles . tableContainer } >
42- < table className = { styles . table } >
43- < thead >
44- < tr >
45- < th > Movie Title</ th >
46- < th > Year</ th >
47- < th > Rating</ th >
48- < th > Total Comments</ th >
49- < th > Recent Comments</ th >
50- </ tr >
51- </ thead >
52- < tbody >
53- { ( commentsData . data as MovieWithComments [ ] ) . map ( ( movie ) => (
54- < tr key = { movie . _id } >
55- < td className = { styles . movieTitle } > { movie . title } </ td >
56- < td > { movie . year } </ td >
57- < td > { movie . imdbRating ? movie . imdbRating . toFixed ( 1 ) : 'N/A' } </ td >
58- < td > { movie . totalComments } </ td >
59- < td >
60- < div className = { styles . commentsContainer } >
61- { movie . recentComments ?. slice ( 0 , 2 ) . map ( ( comment , index ) => (
62- < div key = { `${ movie . _id } -${ comment . date } -${ index } ` } className = { styles . comment } >
63- < div className = { styles . commentText } >
64- “{ ( comment . text || 'No text' ) . slice ( 0 , 80 ) } { comment . text ?. length > 80 ? '...' : '' } ”
65- </ div >
66- < div className = { styles . commentMeta } >
67- by { comment . userName } on { new Date ( comment . date ) . toLocaleDateString ( ) }
68- </ div >
69- </ div >
70- ) ) || < div > No recent comments</ div > }
71- </ div >
72- </ td >
42+ < ExpandableTable
43+ initialRowCount = { 5 }
44+ totalRowCount = { ( commentsData . data as MovieWithComments [ ] ) . length }
45+ >
46+ < div className = { styles . tableContainer } >
47+ < table className = { styles . table } >
48+ < thead >
49+ < tr >
50+ < th > Movie Title</ th >
51+ < th > Year</ th >
52+ < th > Rating</ th >
53+ < th > Total Comments</ th >
54+ < th > Recent Comments</ th >
7355 </ tr >
74- ) ) }
75- </ tbody >
76- </ table >
77- </ div >
56+ </ thead >
57+ < tbody >
58+ { ( commentsData . data as MovieWithComments [ ] ) . map ( ( movie ) => (
59+ < tr key = { movie . _id } >
60+ < td className = { styles . movieTitle } > { movie . title } </ td >
61+ < td > { movie . year } </ td >
62+ < td > { movie . imdbRating ? movie . imdbRating . toFixed ( 1 ) : 'N/A' } </ td >
63+ < td > { movie . totalComments } </ td >
64+ < td >
65+ < div className = { styles . commentsContainer } >
66+ { movie . recentComments ?. slice ( 0 , 2 ) . map ( ( comment , index ) => (
67+ < div key = { `${ movie . _id } -${ comment . date } -${ index } ` } className = { styles . comment } >
68+ < div className = { styles . commentText } >
69+ “{ ( comment . text || 'No text' ) . slice ( 0 , 80 ) } { comment . text ?. length > 80 ? '...' : '' } ”
70+ </ div >
71+ < div className = { styles . commentMeta } >
72+ by { comment . userName } on { new Date ( comment . date ) . toLocaleDateString ( ) }
73+ </ div >
74+ </ div >
75+ ) ) || < div > No recent comments</ div > }
76+ </ div >
77+ </ td >
78+ </ tr >
79+ ) ) }
80+ </ tbody >
81+ </ table >
82+ </ div >
83+ </ ExpandableTable >
7884 ) : (
7985 < div className = { styles . error } >
8086 Failed to load movies with comments: { commentsData . error || 'Unknown error' }
@@ -86,32 +92,37 @@ export default async function AggregationsPage() {
8692 < section className = { styles . section } >
8793 < h2 className = { styles . sectionTitle } > Movies by Year Statistics</ h2 >
8894 { yearData . success && yearData . data ? (
89- < div className = { styles . tableContainer } >
90- < table className = { styles . table } >
91- < thead >
92- < tr >
93- < th > Year</ th >
94- < th > Movie Count</ th >
95- < th > Average Rating</ th >
96- < th > Highest Rating</ th >
97- < th > Lowest Rating</ th >
98- < th > Total Votes</ th >
99- </ tr >
100- </ thead >
101- < tbody >
102- { ( yearData . data as YearlyStats [ ] ) . slice ( 0 , 20 ) . map ( ( yearStats ) => (
103- < tr key = { yearStats . year } >
104- < td className = { styles . year } > { yearStats . year } </ td >
105- < td > { yearStats . movieCount } </ td >
106- < td > { yearStats . averageRating ? yearStats . averageRating . toFixed ( 2 ) : 'N/A' } </ td >
107- < td > { yearStats . highestRating ? yearStats . highestRating . toFixed ( 1 ) : 'N/A' } </ td >
108- < td > { yearStats . lowestRating ? yearStats . lowestRating . toFixed ( 1 ) : 'N/A' } </ td >
109- < td > { yearStats . totalVotes ?. toLocaleString ( ) || 'N/A' } </ td >
95+ < ExpandableTable
96+ initialRowCount = { 10 }
97+ totalRowCount = { ( yearData . data as YearlyStats [ ] ) . length }
98+ >
99+ < div className = { styles . tableContainer } >
100+ < table className = { styles . table } >
101+ < thead >
102+ < tr >
103+ < th > Year</ th >
104+ < th > Movie Count</ th >
105+ < th > Average Rating</ th >
106+ < th > Highest Rating</ th >
107+ < th > Lowest Rating</ th >
108+ < th > Total Votes</ th >
110109 </ tr >
111- ) ) }
112- </ tbody >
113- </ table >
114- </ div >
110+ </ thead >
111+ < tbody >
112+ { ( yearData . data as YearlyStats [ ] ) . map ( ( yearStats ) => (
113+ < tr key = { yearStats . year } >
114+ < td className = { styles . year } > { yearStats . year } </ td >
115+ < td > { yearStats . movieCount } </ td >
116+ < td > { yearStats . averageRating ? yearStats . averageRating . toFixed ( 2 ) : 'N/A' } </ td >
117+ < td > { yearStats . highestRating ? yearStats . highestRating . toFixed ( 1 ) : 'N/A' } </ td >
118+ < td > { yearStats . lowestRating ? yearStats . lowestRating . toFixed ( 1 ) : 'N/A' } </ td >
119+ < td > { yearStats . totalVotes ?. toLocaleString ( ) || 'N/A' } </ td >
120+ </ tr >
121+ ) ) }
122+ </ tbody >
123+ </ table >
124+ </ div >
125+ </ ExpandableTable >
115126 ) : (
116127 < div className = { styles . error } >
117128 Failed to load yearly statistics: { yearData . error || 'Unknown error' }
@@ -123,28 +134,33 @@ export default async function AggregationsPage() {
123134 < section className = { styles . section } >
124135 < h2 className = { styles . sectionTitle } > Directors with Most Movies</ h2 >
125136 { directorsData . success && directorsData . data ? (
126- < div className = { styles . tableContainer } >
127- < table className = { styles . table } >
128- < thead >
129- < tr >
130- < th > Rank</ th >
131- < th > Director</ th >
132- < th > Movie Count</ th >
133- < th > Average Rating</ th >
134- </ tr >
135- </ thead >
136- < tbody >
137- { ( directorsData . data as DirectorStats [ ] ) . map ( ( director , index ) => (
138- < tr key = { director . director } >
139- < td className = { styles . rank } > #{ index + 1 } </ td >
140- < td className = { styles . directorName } > { director . director } </ td >
141- < td > { director . movieCount } </ td >
142- < td > { director . averageRating ? director . averageRating . toFixed ( 2 ) : 'N/A' } </ td >
137+ < ExpandableTable
138+ initialRowCount = { 10 }
139+ totalRowCount = { ( directorsData . data as DirectorStats [ ] ) . length }
140+ >
141+ < div className = { styles . tableContainer } >
142+ < table className = { styles . table } >
143+ < thead >
144+ < tr >
145+ < th > Rank</ th >
146+ < th > Director</ th >
147+ < th > Movie Count</ th >
148+ < th > Average Rating</ th >
143149 </ tr >
144- ) ) }
145- </ tbody >
146- </ table >
147- </ div >
150+ </ thead >
151+ < tbody >
152+ { ( directorsData . data as DirectorStats [ ] ) . map ( ( director , index ) => (
153+ < tr key = { director . director } >
154+ < td className = { styles . rank } > #{ index + 1 } </ td >
155+ < td className = { styles . directorName } > { director . director } </ td >
156+ < td > { director . movieCount } </ td >
157+ < td > { director . averageRating ? director . averageRating . toFixed ( 2 ) : 'N/A' } </ td >
158+ </ tr >
159+ ) ) }
160+ </ tbody >
161+ </ table >
162+ </ div >
163+ </ ExpandableTable >
148164 ) : (
149165 < div className = { styles . error } >
150166 Failed to load director statistics: { directorsData . error || 'Unknown error' }
0 commit comments