Skip to content

Commit 18d02fe

Browse files
authored
Merge pull request #2 from scalefocus/feature/ACC-1069/be_support_for_video_files
Support for video files, ACC-1069. FE video files support in Upload box
2 parents 820c644 + 3c2f9d7 commit 18d02fe

File tree

5 files changed

+57
-26
lines changed

5 files changed

+57
-26
lines changed

src/components/ImageGallery.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -83,8 +83,8 @@ export const ImageGallery: React.FC = () => {
8383
.flat()
8484
.map((thumbnail: IThumbnail, index) => (
8585
<Grid item xs={1} key={thumbnail.id}>
86-
<Paper elevation={0} onClick={() => openPreview(index)}>
87-
<ImageThumbnail id={thumbnail.id} />
86+
<Paper elevation={0} onClick={() => openPreview(index)}>
87+
<ImageThumbnail id={thumbnail.id} mediaType={thumbnail.mediaType} />
8888
</Paper>
8989
</Grid>
9090
))}
@@ -102,7 +102,7 @@ export const ImageGallery: React.FC = () => {
102102
onClose={closePreview}
103103
handleNext={handleNext}
104104
handlePrev={handlePrev}
105-
image={imageIds[currentImage]}
105+
media={imageIds[currentImage]}
106106
disablePrevButton={disablePrevButton}
107107
disableNextButton={disableNextButton}
108108
/>

src/components/ImageThumbnail.tsx

Lines changed: 29 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,45 @@
1-
import { Box, Skeleton } from '@mui/material';
1+
import PlayCircleIcon from '@mui/icons-material/PlayCircle';
2+
import { Box, IconButton, Skeleton } from '@mui/material';
23
import { useQuery } from '@tanstack/react-query';
34
import { getThumbnail } from 'api/api';
45

5-
const ImageThumbnail = ({ id }: { id: string }) => {
6+
const ImageThumbnail = ({ id, mediaType }: { id: string, mediaType?: string }) => {
67
const { data: url, isLoading } = useQuery({
78
queryKey: ['getThumbnail', id],
89
queryFn: () => getThumbnail(id),
910
refetchOnWindowFocus: false,
1011
});
1112

1213
return (
13-
<Box sx={{width: "100%", aspectRatio: '1/1'}}>
14+
<Box sx={{width: "100%", aspectRatio: '1/1', position: 'relative'}}>
1415
{isLoading ? (
1516
<Skeleton variant="rectangular" width="100%" height="100%" />
1617
) : (
17-
<img
18-
src={url}
19-
alt="thumbnail"
20-
style={{
21-
width: '100%',
22-
aspectRatio: '1/1',
23-
objectFit: 'cover',
24-
}}
25-
/>
18+
<>
19+
<img
20+
src={url}
21+
alt="thumbnail"
22+
style={{
23+
width: '100%',
24+
aspectRatio: '1/1',
25+
objectFit: 'cover',
26+
}}
27+
/>
28+
{ mediaType === "video" && (
29+
<Box display="flex" alignItems="center">
30+
<IconButton
31+
sx={{
32+
position: 'absolute',
33+
top: 0,
34+
right: 0,
35+
color: 'white',
36+
}}
37+
>
38+
<PlayCircleIcon />
39+
</IconButton>
40+
</Box>
41+
)}
42+
</>
2643
)}
2744
</Box>
2845
);

src/components/Preview.tsx

Lines changed: 22 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -12,15 +12,17 @@ import {
1212
DialogContent,
1313
Typography,
1414
} from '@mui/material';
15+
import CardMedia from '@mui/material/CardMedia';
1516
import { useQuery } from '@tanstack/react-query';
1617
import { getPhoto } from 'api/api';
1718
import { useEffect, useState } from 'react';
1819

1920
interface 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

3234
const 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>

src/components/UploadImage.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ const Upload: React.FC = () => {
113113
{isPending ? 'Uploading' : 'Browse Files'}
114114
<input
115115
type="file"
116-
accept="image/*"
116+
accept="image/*, video/*"
117117
onChange={(event) => {
118118
const files = event.target.files;
119119

src/types/types.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,11 +53,12 @@ export enum UserRoles {
5353
USER,
5454
}
5555

56-
5756
export interface IThumbnail {
5857
id: string;
5958
dateCreated: string;
59+
mediaType?: string;
6060
}
61+
6162
export interface IGetObjects {
6263
lastId: string;
6364
properties: IThumbnail[];

0 commit comments

Comments
 (0)