aboutsummaryrefslogtreecommitdiff
path: root/frontend
diff options
context:
space:
mode:
Diffstat (limited to 'frontend')
-rw-r--r--frontend/src/components/UploadRunDialog.tsx55
-rw-r--r--frontend/src/css/UploadRunDialog.css30
-rw-r--r--frontend/src/hooks/UseMessage.tsx7
3 files changed, 83 insertions, 9 deletions
diff --git a/frontend/src/components/UploadRunDialog.tsx b/frontend/src/components/UploadRunDialog.tsx
index d0b5687..a0d23e7 100644
--- a/frontend/src/components/UploadRunDialog.tsx
+++ b/frontend/src/components/UploadRunDialog.tsx
@@ -46,6 +46,35 @@ const UploadRunDialog: React.FC<UploadRunDialogProps> = ({ token, open, onClose,
46 46
47 const [loading, setLoading] = React.useState<boolean>(false); 47 const [loading, setLoading] = React.useState<boolean>(false);
48 48
49 const [dragHightlight, setDragHighlight] = React.useState<boolean>(false);
50 const fileInputRef = React.useRef<HTMLInputElement>(null);
51
52 const _handle_file_click = () => {
53 fileInputRef.current?.click();
54 }
55
56 const _handle_drag_over = (e: React.DragEvent<HTMLDivElement>) => {
57 e.preventDefault();
58 e.stopPropagation();
59 setDragHighlight(true);
60 }
61
62 const _handle_drag_leave = (e: React.DragEvent<HTMLDivElement>) => {
63 e.preventDefault();
64 e.stopPropagation();
65 setDragHighlight(false);
66 }
67
68 const _handle_drop = (e: React.DragEvent<HTMLDivElement>, host: boolean) => {
69 e.preventDefault();
70 e.stopPropagation();
71 setDragHighlight(true);
72
73 console.log(e.dataTransfer.files);
74
75 _handle_file_change(e.dataTransfer.files, host);
76 }
77
49 const _handle_dropdowns = (dropdown: number) => { 78 const _handle_dropdowns = (dropdown: number) => {
50 setDropdown1Vis(false); 79 setDropdown1Vis(false);
51 setDropdown2Vis(false); 80 setDropdown2Vis(false);
@@ -72,17 +101,18 @@ const UploadRunDialog: React.FC<UploadRunDialogProps> = ({ token, open, onClose,
72 setLoading(false); 101 setLoading(false);
73 }; 102 };
74 103
75 const _handle_file_change = async (e: React.ChangeEvent<HTMLInputElement>, host: boolean) => { 104 const _handle_file_change = async (files: FileList | null, host: boolean) => {
76 if (e.target.files) { 105 console.log(files);
106 if (files) {
77 if (host) { 107 if (host) {
78 setUploadRunContent({ 108 setUploadRunContent({
79 ...uploadRunContent, 109 ...uploadRunContent,
80 host_demo: e.target.files[0], 110 host_demo: files[0],
81 }); 111 });
82 } else { 112 } else {
83 setUploadRunContent({ 113 setUploadRunContent({
84 ...uploadRunContent, 114 ...uploadRunContent,
85 partner_demo: e.target.files[0], 115 partner_demo: files[0],
86 }); 116 });
87 } 117 }
88 } 118 }
@@ -178,13 +208,26 @@ const UploadRunDialog: React.FC<UploadRunDialogProps> = ({ token, open, onClose,
178 </div> 208 </div>
179 </div> 209 </div>
180 <span>Host Demo</span> 210 <span>Host Demo</span>
181 <input type="file" name="host_demo" id="host_demo" accept=".dem" onChange={(e) => _handle_file_change(e, true)} /> 211 <div onClick={_handle_file_click} onDragOver={(e) => {_handle_drag_over(e)}} onDrop={(e) => {_handle_drop(e, true)}} onDragLeave={(e) => {_handle_drag_leave(e)}} className={`upload-run-drag-area ${dragHightlight ? "upload-run-drag-area-highlight" : ""} ${uploadRunContent.host_demo ? "upload-run-drag-area-hidden" : ""}`}>
212 <input ref={fileInputRef} type="file" name="host_demo" id="host_demo" accept=".dem" onChange={(e) => _handle_file_change(e.target.files, true)} />
213 {!uploadRunContent.host_demo ?
214 <div>
215 <span>Drag and drop</span>
216 <div>
217 <span>Or click here</span>
218 <button>Upload</button>
219 </div>
220 </div>
221 : null}
222
223 <span>{uploadRunContent.host_demo?.name}</span>
224 </div>
182 { 225 {
183 games[selectedGameID].is_coop && 226 games[selectedGameID].is_coop &&
184 ( 227 (
185 <> 228 <>
186 <span>Partner Demo</span> 229 <span>Partner Demo</span>
187 <input type="file" name="partner_demo" id="partner_demo" accept=".dem" onChange={(e) => _handle_file_change(e, false)} /> 230 <input type="file" name="partner_demo" id="partner_demo" accept=".dem" onChange={(e) => _handle_file_change(e.target.files, false)} />
188 </> 231 </>
189 ) 232 )
190 } 233 }
diff --git a/frontend/src/css/UploadRunDialog.css b/frontend/src/css/UploadRunDialog.css
index f2b7ed0..c783d2a 100644
--- a/frontend/src/css/UploadRunDialog.css
+++ b/frontend/src/css/UploadRunDialog.css
@@ -115,3 +115,33 @@ button:hover {
115 width: 100%; 115 width: 100%;
116} 116}
117 117
118#host_demo {
119 background-color: rgba(0, 0, 0, 0);
120 display: none;
121}
122
123.upload-run-drag-area {
124 border: 2px dashed grey;
125 border-radius: 10px;
126 height: 200px;
127 cursor: pointer;
128 width: 300px;
129 transition: all 0.2s ease;
130 text-align: center;
131 display: flex;
132 flex-direction: column;
133 align-items: center;
134 justify-content: center;
135}
136
137.upload-run-drag-area-highlight {
138 border: 2px dashed white;
139}
140
141.upload-run-drag-area-hidden {
142 height: fit-content;
143 text-align: left;
144 border: none;
145 align-items: flex-start;
146}
147
diff --git a/frontend/src/hooks/UseMessage.tsx b/frontend/src/hooks/UseMessage.tsx
index 6b458eb..602cf65 100644
--- a/frontend/src/hooks/UseMessage.tsx
+++ b/frontend/src/hooks/UseMessage.tsx
@@ -3,6 +3,7 @@ import MessageDialog from "../components/MessageDialog";
3 3
4const useMessage = () => { 4const useMessage = () => {
5 const [isOpen, setIsOpen] = useState(false); 5 const [isOpen, setIsOpen] = useState(false);
6
6 const [title, setTitle] = useState<string>(""); 7 const [title, setTitle] = useState<string>("");
7 const [subtitle, setSubtitle] = useState<string>(""); 8 const [subtitle, setSubtitle] = useState<string>("");
8 const [resolvePromise, setResolvePromise] = useState<(() => void) | null>(null); 9 const [resolvePromise, setResolvePromise] = useState<(() => void) | null>(null);
@@ -11,9 +12,9 @@ const useMessage = () => {
11 setIsOpen(true); 12 setIsOpen(true);
12 setTitle(title); 13 setTitle(title);
13 setSubtitle(subtitle); 14 setSubtitle(subtitle);
14 return new Promise<void>((resolve) => { 15 return new Promise((resolve) => {
15 setResolvePromise(() => resolve); 16 setResolvePromise(() => resolve);
16 }) 17 });
17 }; 18 };
18 19
19 const handleClose = () => { 20 const handleClose = () => {