diff options
Diffstat (limited to 'frontend/src/components')
| -rw-r--r-- | frontend/src/components/Leaderboards.tsx | 9 | ||||
| -rw-r--r-- | frontend/src/components/UploadRunDialog.tsx | 56 |
2 files changed, 49 insertions, 16 deletions
diff --git a/frontend/src/components/Leaderboards.tsx b/frontend/src/components/Leaderboards.tsx index f86aa7b..b9e071c 100644 --- a/frontend/src/components/Leaderboards.tsx +++ b/frontend/src/components/Leaderboards.tsx | |||
| @@ -4,6 +4,7 @@ import { Link } from 'react-router-dom'; | |||
| 4 | import { DownloadIcon, ThreedotIcon } from '../images/Images'; | 4 | import { DownloadIcon, ThreedotIcon } from '../images/Images'; |
| 5 | import { MapLeaderboard } from '../types/Map'; | 5 | import { MapLeaderboard } from '../types/Map'; |
| 6 | import { ticks_to_time, time_ago } from '../utils/Time'; | 6 | import { ticks_to_time, time_ago } from '../utils/Time'; |
| 7 | import useMessage from "../hooks/UseMessage"; | ||
| 7 | import "../css/Maps.css" | 8 | import "../css/Maps.css" |
| 8 | 9 | ||
| 9 | interface LeaderboardsProps { | 10 | interface LeaderboardsProps { |
| @@ -12,6 +13,7 @@ interface LeaderboardsProps { | |||
| 12 | 13 | ||
| 13 | const Leaderboards: React.FC<LeaderboardsProps> = ({ data }) => { | 14 | const Leaderboards: React.FC<LeaderboardsProps> = ({ data }) => { |
| 14 | 15 | ||
| 16 | const { message, MessageDialogComponent } = useMessage(); | ||
| 15 | const [pageNumber, setPageNumber] = React.useState<number>(1); | 17 | const [pageNumber, setPageNumber] = React.useState<number>(1); |
| 16 | 18 | ||
| 17 | if (!data) { | 19 | if (!data) { |
| @@ -31,6 +33,10 @@ const Leaderboards: React.FC<LeaderboardsProps> = ({ data }) => { | |||
| 31 | }; | 33 | }; |
| 32 | 34 | ||
| 33 | return ( | 35 | return ( |
| 36 | <div> | ||
| 37 | <div style={{position: "absolute", width: "100%", height: "100%", top: "0px", left: "-350px"}}> | ||
| 38 | {MessageDialogComponent} | ||
| 39 | </div> | ||
| 34 | <section id='section6' className='summary2'> | 40 | <section id='section6' className='summary2'> |
| 35 | 41 | ||
| 36 | <div id='leaderboard-top' | 42 | <div id='leaderboard-top' |
| @@ -94,7 +100,7 @@ const Leaderboards: React.FC<LeaderboardsProps> = ({ data }) => { | |||
| 94 | ) : r.kind === "singleplayer" && ( | 100 | ) : r.kind === "singleplayer" && ( |
| 95 | 101 | ||
| 96 | <span> | 102 | <span> |
| 97 | <button onClick={() => { window.alert(`Demo ID: ${r.demo_id}`) }}><img src={ThreedotIcon} alt="demo_id" /></button> | 103 | <button onClick={() => { message("Demo information", `Demo ID: ${r.demo_id}`) }}><img src={ThreedotIcon} alt="demo_id" /></button> |
| 98 | <button onClick={() => window.location.href = `/api/v1/demos?uuid=${r.demo_id}`}><img src={DownloadIcon} alt="download" /></button> | 104 | <button onClick={() => window.location.href = `/api/v1/demos?uuid=${r.demo_id}`}><img src={DownloadIcon} alt="download" /></button> |
| 99 | </span> | 105 | </span> |
| 100 | )} | 106 | )} |
| @@ -102,6 +108,7 @@ const Leaderboards: React.FC<LeaderboardsProps> = ({ data }) => { | |||
| 102 | ))} | 108 | ))} |
| 103 | </div> | 109 | </div> |
| 104 | </section> | 110 | </section> |
| 111 | </div> | ||
| 105 | ); | 112 | ); |
| 106 | }; | 113 | }; |
| 107 | 114 | ||
diff --git a/frontend/src/components/UploadRunDialog.tsx b/frontend/src/components/UploadRunDialog.tsx index a0d23e7..212a792 100644 --- a/frontend/src/components/UploadRunDialog.tsx +++ b/frontend/src/components/UploadRunDialog.tsx | |||
| @@ -47,22 +47,36 @@ const UploadRunDialog: React.FC<UploadRunDialogProps> = ({ token, open, onClose, | |||
| 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); | 49 | const [dragHightlight, setDragHighlight] = React.useState<boolean>(false); |
| 50 | const [dragHightlightPartner, setDragHighlightPartner] = React.useState<boolean>(false); | ||
| 50 | const fileInputRef = React.useRef<HTMLInputElement>(null); | 51 | const fileInputRef = React.useRef<HTMLInputElement>(null); |
| 51 | 52 | const fileInputRefPartner = React.useRef<HTMLInputElement>(null); | |
| 52 | const _handle_file_click = () => { | 53 | |
| 53 | fileInputRef.current?.click(); | 54 | const _handle_file_click = (host: boolean) => { |
| 55 | if (host) { | ||
| 56 | fileInputRef.current?.click(); | ||
| 57 | } else { | ||
| 58 | fileInputRefPartner.current?.click(); | ||
| 59 | } | ||
| 54 | } | 60 | } |
| 55 | 61 | ||
| 56 | const _handle_drag_over = (e: React.DragEvent<HTMLDivElement>) => { | 62 | const _handle_drag_over = (e: React.DragEvent<HTMLDivElement>, host: boolean) => { |
| 57 | e.preventDefault(); | 63 | e.preventDefault(); |
| 58 | e.stopPropagation(); | 64 | e.stopPropagation(); |
| 59 | setDragHighlight(true); | 65 | if (host) { |
| 66 | setDragHighlight(true); | ||
| 67 | } else { | ||
| 68 | setDragHighlightPartner(true); | ||
| 69 | } | ||
| 60 | } | 70 | } |
| 61 | 71 | ||
| 62 | const _handle_drag_leave = (e: React.DragEvent<HTMLDivElement>) => { | 72 | const _handle_drag_leave = (e: React.DragEvent<HTMLDivElement>, host: boolean) => { |
| 63 | e.preventDefault(); | 73 | e.preventDefault(); |
| 64 | e.stopPropagation(); | 74 | e.stopPropagation(); |
| 65 | setDragHighlight(false); | 75 | if (host) { |
| 76 | setDragHighlight(false); | ||
| 77 | } else { | ||
| 78 | setDragHighlightPartner(false); | ||
| 79 | } | ||
| 66 | } | 80 | } |
| 67 | 81 | ||
| 68 | const _handle_drop = (e: React.DragEvent<HTMLDivElement>, host: boolean) => { | 82 | const _handle_drop = (e: React.DragEvent<HTMLDivElement>, host: boolean) => { |
| @@ -70,8 +84,6 @@ const UploadRunDialog: React.FC<UploadRunDialogProps> = ({ token, open, onClose, | |||
| 70 | e.stopPropagation(); | 84 | e.stopPropagation(); |
| 71 | setDragHighlight(true); | 85 | setDragHighlight(true); |
| 72 | 86 | ||
| 73 | console.log(e.dataTransfer.files); | ||
| 74 | |||
| 75 | _handle_file_change(e.dataTransfer.files, host); | 87 | _handle_file_change(e.dataTransfer.files, host); |
| 76 | } | 88 | } |
| 77 | 89 | ||
| @@ -102,7 +114,6 @@ const UploadRunDialog: React.FC<UploadRunDialogProps> = ({ token, open, onClose, | |||
| 102 | }; | 114 | }; |
| 103 | 115 | ||
| 104 | const _handle_file_change = async (files: FileList | null, host: boolean) => { | 116 | const _handle_file_change = async (files: FileList | null, host: boolean) => { |
| 105 | console.log(files); | ||
| 106 | if (files) { | 117 | if (files) { |
| 107 | if (host) { | 118 | if (host) { |
| 108 | setUploadRunContent({ | 119 | setUploadRunContent({ |
| @@ -155,13 +166,16 @@ const UploadRunDialog: React.FC<UploadRunDialogProps> = ({ token, open, onClose, | |||
| 155 | 166 | ||
| 156 | const [ success, response ] = await API.post_record(token, uploadRunContent); | 167 | const [ success, response ] = await API.post_record(token, uploadRunContent); |
| 157 | await message("Upload Record", response); | 168 | await message("Upload Record", response); |
| 158 | console.log("weweew") | ||
| 159 | onClose(success); | 169 | onClose(success); |
| 170 | navigate("/profile"); | ||
| 160 | } | 171 | } |
| 161 | }; | 172 | }; |
| 162 | 173 | ||
| 163 | React.useEffect(() => { | 174 | React.useEffect(() => { |
| 164 | if (open) { | 175 | if (open) { |
| 176 | |||
| 177 | setDragHighlightPartner(false); | ||
| 178 | setDragHighlight(false); | ||
| 165 | _handle_game_select("1", "Portal 2 - Singleplayer"); // a different approach?. | 179 | _handle_game_select("1", "Portal 2 - Singleplayer"); // a different approach?. |
| 166 | } | 180 | } |
| 167 | }, [open]); | 181 | }, [open]); |
| @@ -208,14 +222,14 @@ const UploadRunDialog: React.FC<UploadRunDialogProps> = ({ token, open, onClose, | |||
| 208 | </div> | 222 | </div> |
| 209 | </div> | 223 | </div> |
| 210 | <span>Host Demo</span> | 224 | <span>Host Demo</span> |
| 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" : ""}`}> | 225 | <div onClick={() => {_handle_file_click(true)}} onDragOver={(e) => {_handle_drag_over(e, true)}} onDrop={(e) => {_handle_drop(e, true)}} onDragLeave={(e) => {_handle_drag_leave(e, true)}} 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)} /> | 226 | <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 ? | 227 | {!uploadRunContent.host_demo ? |
| 214 | <div> | 228 | <div> |
| 215 | <span>Drag and drop</span> | 229 | <span>Drag and drop</span> |
| 216 | <div> | 230 | <div> |
| 217 | <span>Or click here</span> | 231 | <span style={{fontFamily: "BarlowSemiCondensed-Regular"}}>Or click here</span><br/> |
| 218 | <button>Upload</button> | 232 | <button style={{borderRadius: "24px", padding: "5px 8px", margin: "5px 0px"}}>Upload</button> |
| 219 | </div> | 233 | </div> |
| 220 | </div> | 234 | </div> |
| 221 | : null} | 235 | : null} |
| @@ -227,7 +241,19 @@ const UploadRunDialog: React.FC<UploadRunDialogProps> = ({ token, open, onClose, | |||
| 227 | ( | 241 | ( |
| 228 | <> | 242 | <> |
| 229 | <span>Partner Demo</span> | 243 | <span>Partner Demo</span> |
| 230 | <input type="file" name="partner_demo" id="partner_demo" accept=".dem" onChange={(e) => _handle_file_change(e.target.files, false)} /> | 244 | <div onClick={() => {_handle_file_click(false)}} onDragOver={(e) => {_handle_drag_over(e, false)}} onDrop={(e) => {_handle_drop(e, false)}} onDragLeave={(e) => {_handle_drag_leave(e, false)}} className={`upload-run-drag-area ${dragHightlightPartner ? "upload-run-drag-area-highlight-partner" : ""} ${uploadRunContent.partner_demo ? "upload-run-drag-area-hidden" : ""}`}> |
| 245 | <input ref={fileInputRefPartner} type="file" name="partner_demo" id="partner_demo" accept=".dem" onChange={(e) => _handle_file_change(e.target.files, false)} /> {!uploadRunContent.partner_demo ? | ||
| 246 | <div> | ||
| 247 | <span>Drag and drop</span> | ||
| 248 | <div> | ||
| 249 | <span>Or click here</span><br/> | ||
| 250 | <button>Upload</button> | ||
| 251 | </div> | ||
| 252 | </div> | ||
| 253 | : null} | ||
| 254 | |||
| 255 | <span>{uploadRunContent.partner_demo?.name}</span> | ||
| 256 | </div> | ||
| 231 | </> | 257 | </> |
| 232 | ) | 258 | ) |
| 233 | } | 259 | } |