@@ -12,15 +12,17 @@ import {
1212 DialogContent ,
1313 Typography ,
1414} from '@mui/material' ;
15+ import CardMedia from '@mui/material/CardMedia' ;
1516import { useQuery } from '@tanstack/react-query' ;
1617import { getPhoto } from 'api/api' ;
1718import { useEffect , useState } from 'react' ;
1819
1920interface PreviewProps {
2021 isOpen : boolean ;
21- image : {
22+ media : {
2223 id : string ;
2324 dateCreated : string ;
25+ mediaType ?: string ;
2426 } ;
2527 handlePrev : ( ) => void ;
2628 handleNext : ( ) => void ;
@@ -31,19 +33,19 @@ interface PreviewProps {
3133
3234const Preview = ( {
3335 isOpen,
34- image ,
36+ media ,
3537 onClose,
3638 handlePrev,
3739 handleNext,
3840 disablePrevButton,
3941 disableNextButton,
4042} : PreviewProps ) => {
4143 const { data : url , isLoading } = useQuery ( {
42- queryKey : [ 'getPhoto' , image . id ] ,
43- queryFn : ( ) => getPhoto ( image . id ) ,
44+ queryKey : [ 'getPhoto' , media . id ] ,
45+ queryFn : ( ) => getPhoto ( media . id ) ,
4446 } ) ;
4547
46- const date = new Date ( image . dateCreated ) . toDateString ( ) ;
48+ const date = new Date ( media . dateCreated ) . toDateString ( ) ;
4749
4850 const [ zoom , setZoom ] = useState ( false ) ;
4951
@@ -75,7 +77,7 @@ const Preview = ({
7577 document . removeEventListener ( 'keydown' , handleKeyLeft ) ;
7678 document . removeEventListener ( 'keydown' , handleKeyRight ) ;
7779 } ;
78- } , [ image ] ) ;
80+ } , [ media ] ) ;
7981
8082 return (
8183 < >
@@ -102,7 +104,7 @@ const Preview = ({
102104 backgroundColor : 'rgba(0, 0, 0)' ,
103105 } }
104106 >
105- < img src = { url } alt = "image" />
107+ { media . mediaType !== "video" && ( < img src = { url } alt = "image" /> ) }
106108 </ Box >
107109 </ Container >
108110 ) }
@@ -199,7 +201,7 @@ const Preview = ({
199201 position : 'relative' ,
200202 } }
201203 >
202- < img
204+ { media . mediaType !== "video" && ( < img
203205 src = { url }
204206 alt = "image"
205207 style = { {
@@ -208,7 +210,18 @@ const Preview = ({
208210 maxHeight : '100%' ,
209211 cursor : 'zoom-in' ,
210212 } }
211- />
213+ /> ) }
214+ { media . mediaType === "video" && ( < CardMedia
215+ component = 'video'
216+ src = { url }
217+ sx = { {
218+ display : 'flex' ,
219+ objectFit : 'contain' ,
220+ maxWidth : '100%' ,
221+ maxHeight : '100%'
222+ } }
223+ controls
224+ /> ) }
212225 </ Box >
213226 ) }
214227 </ Box >
0 commit comments