-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathLongSquareView.tsx
147 lines (139 loc) · 4.72 KB
/
LongSquareView.tsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
"use client";
import Image, { StaticImageData } from "next/image";
import React, { useState } from "react";
import placeHolderImg from "../../assets/images/placeholder.png";
import "@canopassoftware/react-file-upload/style.css";
import {
SingleFileUpload,
MultipleFileUpload,
} from "@canopassoftware/react-file-upload";
export default function App() {
// for single file upload component
const [previewFileData, setPreviewFileData] = useState(
{} as {
previewType: string;
previewUrl: string | StaticImageData | ArrayBuffer | null;
previewName: string;
isDragging: boolean;
}
);
const handleFileUploading = async (file: any) => {
await new Promise((resolve) => setTimeout(resolve, 2000));
setPreviewFileData({
previewType: "image",
previewUrl: "https://picsum.photos/300/224",
previewName: file.name,
isDragging: false,
});
};
// for multiple file upload component
const uploadedFiles = [] as Array<{
fileType: string;
fileUrl: string | StaticImageData;
fileName: string;
}>;
const handleFilesUploading = async (files: any) => {
const uploadedFiles = [];
for (var i = 0; i < files.length; i++) {
uploadedFiles.push({
fileType: "image",
fileUrl: "https://picsum.photos/300/224",
fileName: files[i].name,
});
}
await new Promise((resolve) => setTimeout(resolve, 5000));
return uploadedFiles;
};
return (
<main className="flex flex-col justify-between p-5">
<p className="mt-5 ms-6">Single File Upload</p>
<SingleFileUpload
uploadedFile={[previewFileData, setPreviewFileData]}
callback={handleFileUploading}
uploadBtnText={"Save"}
progressBtnText={"Saving..."}
>
<div className="h-[100px] w-[500px] cursor-pointer mb-10 ms-5 border rounded-2xl overflow-hidden dark:border-slate-700">
<div className="flex h-full w-full relative">
<div className="h-full w-1/4">
{previewFileData.previewType != "video" ? (
<Image
className="object-contain rounded-2xl w-full h-full"
src={
(previewFileData.previewUrl
? previewFileData.previewUrl
: placeHolderImg) as string
}
height={224}
width={300}
alt="image"
/>
) : (
<video
autoPlay
loop
className="h-64 w-72 object-contain rounded-2xl"
>
<source
src={previewFileData.previewUrl as string}
type="video/mp4"
/>
</video>
)}
</div>
<p className="break-words text-center dark:text-white flex items-center pl-5">
{previewFileData.previewName
? previewFileData.previewName
: "Click to upload or drag and drop files"}
</p>
</div>
</div>
</SingleFileUpload>
<br />
<hr />
<p className="mt-5 ms-6">Multiple File Upload</p>
<MultipleFileUpload
accept=""
uploadedFiles={uploadedFiles}
callback={handleFilesUploading}
uploadBtnText={"Upload"}
progressBtnText={"Uploading..."}
>
{(file: any) => (
<div className="h-[100px] w-[500px] cursor-pointer mb-10 ms-5 border rounded-2xl overflow-hidden dark:border-slate-700">
<div className="flex h-full w-full relative">
<div className="h-full w-1/4">
{file.previewType != "video" ? (
<Image
className="object-contain rounded-2xl w-full h-full"
src={
(file.previewUrl
? file.previewUrl
: placeHolderImg) as string
}
height={224}
width={300}
alt="image"
/>
) : (
<video
autoPlay
loop
className="h-64 w-72 object-contain rounded-2xl"
>
<source src={file.previewUrl as string} type="video/mp4" />
</video>
)}
</div>
<p className="break-words text-center dark:text-white flex items-center pl-5">
{file.previewName
? file.previewName
: "Click to upload or drag and drop files"}
</p>
</div>
</div>
)}
</MultipleFileUpload>
</main>
);
}