Skip to content

Commit 9b3372c

Browse files
committed
[FEAT]: add onWatch prop on FileItem component
1 parent 6922134 commit 9b3372c

File tree

2 files changed

+17
-2
lines changed

2 files changed

+17
-2
lines changed

src/components/file-item/components/FileItem/FileItem.tsx

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ const FileItem: FC<FileItemProps> = (props: FileItemProps) => {
2222
file,
2323
onDelete,
2424
onSee,
25+
onWatch,
2526
style,
2627
preview,
2728
onlyImage,
@@ -58,6 +59,7 @@ const FileItem: FC<FileItemProps> = (props: FileItemProps) => {
5859
const sizeFormatted: string = file ? fileSizeFormater(file.size) : "0 KB";
5960

6061
const [isImage, setIsImage] = useState<boolean>(false);
62+
const [isVideo, setIsVideo] = useState<boolean>(false);
6163
const [url, setUrl] = useState<string>("");
6264
const [imageSource, setImageSource] = useState<string | undefined>(undefined);
6365
//alwaysActive
@@ -68,6 +70,7 @@ const FileItem: FC<FileItemProps> = (props: FileItemProps) => {
6870
return () => {
6971
setImageSource(undefined);
7072
setIsImage(false);
73+
setIsVideo(false);
7174
};
7275
}, [file, valid, preview, imageUrl]);
7376

@@ -90,6 +93,7 @@ const FileItem: FC<FileItemProps> = (props: FileItemProps) => {
9093
} else {
9194
const headerMime = file.type ? file.type.split("/")[0] : "octet";
9295
setIsImage(headerMime === "image");
96+
setIsVideo(headerMime === "video");
9397
if (preview && valid && headerMime === "image") {
9498
const response = await readImagePromise(file);
9599
if (response) {
@@ -117,6 +121,11 @@ const FileItem: FC<FileItemProps> = (props: FileItemProps) => {
117121

118122
setShowInfo(false);
119123
};
124+
const handleOpenVideo = async () => {
125+
if (file) {
126+
onWatch?.(file);
127+
}
128+
};
120129
const handleOpenImage = async () => {
121130
if (imageSource && file) {
122131
if (hd) {
@@ -159,6 +168,8 @@ const FileItem: FC<FileItemProps> = (props: FileItemProps) => {
159168
fileName={file.name}
160169
onDelete={onDelete ? handleDelete : undefined}
161170
onOpenImage={onSee && preview ? handleOpenImage : undefined}
171+
onOpenVideo={onWatch && preview ? handleOpenVideo : undefined}
172+
isVideo={isVideo}
162173
onOpenInfo={handleOpenInfo}
163174
info={info || false}
164175
valid={valid || false}

src/components/file-item/components/FileItem/FileItemProps.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,11 +33,15 @@ export interface FileItemProps extends PaperProps {
3333
/**
3434
* A function of what to do when close button is pressed or clicked
3535
*/
36-
onDelete?: (imageUrl: number | string | undefined) => void;
36+
onDelete?: (fileId: number | string | undefined) => void;
3737
/**
38-
* A function of what to do when "see" button is pressed or clicked
38+
* A function that return a file object when "see" button is pressed or clicked
3939
*/
4040
onSee?: (imageUrl: string) => void;
41+
/**
42+
* A function that return a file object when "play" button is presssed or clicked
43+
*/
44+
onWatch?: (videoUrl: File) => void;
4145
/**
4246
* Whether to see as grid or inline (horizontal list)
4347
*/

0 commit comments

Comments
 (0)