11import React , { useEffect } from 'react' ;
2- import { DataGrid , GridFilterModel , GridSortModel } from '@mui/x-data-grid' ;
2+ import { DataGrid , GridCellParams , GridFilterModel , GridRowParams , GridSortModel } from '@mui/x-data-grid' ;
33import { Box , Button , Stack } from "@mui/material" ;
44import { Track } from "../models/demoData/Track" ;
55import { useService } from "../ContainerContext" ;
@@ -15,9 +15,20 @@ const Home = () => {
1515
1616 const recreateDatabase = ( ) => { apiComms . reCreateDemoDb ( ) . then ( ) . catch ( error => console . error ( error ) ) ; } ;
1717
18+ const cellClicked = ( p : GridCellParams < Track > ) => {
19+ if ( p . row . album . value )
20+ setCurrentAlbumArtwork ( p . row . album . value . inlineImage ) ;
21+ } ;
22+
23+ const rowClicked = ( p : GridRowParams < Track > ) => {
24+ if ( p . row . album . value )
25+ setCurrentAlbumArtwork ( p . row . album . value . inlineImage ) ;
26+ }
27+
1828 const [ tracks , setTracks ] = React . useState < Track [ ] > ( [ ] ) ;
1929 const [ trackCount , setTrackCount ] = React . useState < number > ( ) ;
2030 const [ tracksLoading , setTracksLoading ] = React . useState ( false ) ;
31+ const [ currentAlbumArtwork , setCurrentAlbumArtwork ] = React . useState < string > ( '' ) ;
2132
2233 const [ paginationModel , setPaginationModel ] = React . useState < PaginationState > ( new PaginationState ( ) ) ;
2334 const [ sortModel , setSortModel ] = React . useState < GridSortModel > ( [ ] ) ;
@@ -65,7 +76,7 @@ const Home = () => {
6576 columns = { colDefs }
6677 rows = { tracks }
6778 pageSizeOptions = { [ 5 , 10 , 25 ] }
68- rowCount = { trackCount ?? 0 }
79+ rowCount = { trackCount }
6980 paginationModel = { paginationModel }
7081 sortModel = { sortModel }
7182 filterModel = { filterModel }
@@ -75,8 +86,13 @@ const Home = () => {
7586 onPaginationModelChange = { setPaginationModel }
7687 onSortModelChange = { setSortModel }
7788 onFilterModelChange = { setFilterModel }
89+ onCellClick = { cellClicked }
90+ onRowClick = { rowClicked }
7891 loading = { tracksLoading } />
7992 </ div >
93+ < div style = { { display : 'flex' , flexDirection : 'column' , marginTop : '1rem' , justifyItems : 'center' , alignItems : 'center' } } >
94+ < img src = { currentAlbumArtwork } alt = { 'Album Artwork' } hidden = { ! currentAlbumArtwork } height = { 300 } width = { 300 } > </ img >
95+ </ div >
8096 </ Box >
8197 ) ;
8298}
0 commit comments