diff options
Diffstat (limited to 'frontend/src/components/UploadRunDialog.tsx')
| -rw-r--r-- | frontend/src/components/UploadRunDialog.tsx | 55 |
1 files changed, 49 insertions, 6 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 | } |