diff options
| author | Wolfboy248 <georgejvindkarlsen@gmail.com> | 2024-10-29 10:09:17 +0100 |
|---|---|---|
| committer | Wolfboy248 <georgejvindkarlsen@gmail.com> | 2024-10-29 10:09:17 +0100 |
| commit | 35946dbb2feb7f9d1cbab16fb0602ce0303562e9 (patch) | |
| tree | 3ba530c1b3f5a1742ec41dfee5b74b43353619e2 /frontend/src/pages | |
| parent | Merge branch 'typescript' of https://github.com/pektezol/LeastPortalsHub into... (diff) | |
| download | lphub-35946dbb2feb7f9d1cbab16fb0602ce0303562e9.tar.gz lphub-35946dbb2feb7f9d1cbab16fb0602ce0303562e9.tar.bz2 lphub-35946dbb2feb7f9d1cbab16fb0602ce0303562e9.zip | |
refactor: upload run dialog, useMessage update, added loader spinner
Diffstat (limited to 'frontend/src/pages')
| -rw-r--r-- | frontend/src/pages/Profile.tsx | 15 | ||||
| -rw-r--r-- | frontend/src/pages/Rankings.tsx | 25 |
2 files changed, 28 insertions, 12 deletions
diff --git a/frontend/src/pages/Profile.tsx b/frontend/src/pages/Profile.tsx index 5d1c75d..3dba3ae 100644 --- a/frontend/src/pages/Profile.tsx +++ b/frontend/src/pages/Profile.tsx | |||
| @@ -103,10 +103,12 @@ const Profile: React.FC<ProfileProps> = ({ profile, token, gameData, onDeleteRec | |||
| 103 | }; | 103 | }; |
| 104 | 104 | ||
| 105 | return ( | 105 | return ( |
| 106 | <main> | 106 | <div> |
| 107 | {ConfirmDialogComponent} | 107 | {MessageDialogComponent} |
| 108 | {MessageDialogComponent} | 108 | {ConfirmDialogComponent} |
| 109 | <section id='section1' className='profile'> | 109 | |
| 110 | <main> | ||
| 111 | <section id='section1' className='profile'> | ||
| 110 | 112 | ||
| 111 | {profile.profile | 113 | {profile.profile |
| 112 | ? ( | 114 | ? ( |
| @@ -266,7 +268,7 @@ const Profile: React.FC<ProfileProps> = ({ profile, token, gameData, onDeleteRec | |||
| 266 | <span>{e.date.split("T")[0]}</span> | 268 | <span>{e.date.split("T")[0]}</span> |
| 267 | <span style={{ flexDirection: "row-reverse" }}> | 269 | <span style={{ flexDirection: "row-reverse" }}> |
| 268 | 270 | ||
| 269 | <button style={{ marginRight: "10px" }} onClick={() => { window.alert(`Demo ID: ${e.demo_id}`) }}><img src={ThreedotIcon} alt="demo_id" /></button> | 271 | <button style={{ marginRight: "10px" }} onClick={() => { message("Demo information", `Demo ID: ${e.demo_id}`) }}><img src={ThreedotIcon} alt="demo_id" /></button> |
| 270 | <button onClick={() => { _delete_submission(r.map_id, e.record_id) }}><img src={DeleteIcon}></img></button> | 272 | <button onClick={() => { _delete_submission(r.map_id, e.record_id) }}><img src={DeleteIcon}></img></button> |
| 271 | <button onClick={() => window.location.href = `/api/v1/demos?uuid=${e.demo_id}`}><img src={DownloadIcon} alt="download" /></button> | 273 | <button onClick={() => window.location.href = `/api/v1/demos?uuid=${e.demo_id}`}><img src={DownloadIcon} alt="download" /></button> |
| 272 | {i === 0 && r.scores.length > 1 ? <button onClick={() => { | 274 | {i === 0 && r.scores.length > 1 ? <button onClick={() => { |
| @@ -312,7 +314,7 @@ const Profile: React.FC<ProfileProps> = ({ profile, token, gameData, onDeleteRec | |||
| 312 | <span>{record!.scores[i].date.split("T")[0]}</span> | 314 | <span>{record!.scores[i].date.split("T")[0]}</span> |
| 313 | <span style={{ flexDirection: "row-reverse" }}> | 315 | <span style={{ flexDirection: "row-reverse" }}> |
| 314 | 316 | ||
| 315 | <button onClick={() => { window.alert(`Demo ID: ${e.demo_id}`) }}><img src={ThreedotIcon} alt="demo_id" /></button> | 317 | <button onClick={() => { message("Demo information", `Demo ID: ${e.demo_id}`) }}><img src={ThreedotIcon} alt="demo_id" /></button> |
| 316 | <button onClick={() => { _delete_submission(r.id, e.record_id) }}><img src={DeleteIcon}></img></button> | 318 | <button onClick={() => { _delete_submission(r.id, e.record_id) }}><img src={DeleteIcon}></img></button> |
| 317 | <button onClick={() => window.location.href = `/api/v1/demos?uuid=${e.demo_id}`}><img src={DownloadIcon} alt="download" /></button> | 319 | <button onClick={() => window.location.href = `/api/v1/demos?uuid=${e.demo_id}`}><img src={DownloadIcon} alt="download" /></button> |
| 318 | {i === 0 && record!.scores.length > 1 ? <button onClick={() => { | 320 | {i === 0 && record!.scores.length > 1 ? <button onClick={() => { |
| @@ -333,6 +335,7 @@ const Profile: React.FC<ProfileProps> = ({ profile, token, gameData, onDeleteRec | |||
| 333 | </div> | 335 | </div> |
| 334 | </section> | 336 | </section> |
| 335 | </main> | 337 | </main> |
| 338 | </div> | ||
| 336 | ); | 339 | ); |
| 337 | }; | 340 | }; |
| 338 | 341 | ||
diff --git a/frontend/src/pages/Rankings.tsx b/frontend/src/pages/Rankings.tsx index 9280b02..1830815 100644 --- a/frontend/src/pages/Rankings.tsx +++ b/frontend/src/pages/Rankings.tsx | |||
| @@ -13,6 +13,9 @@ const Rankings: React.FC = () => { | |||
| 13 | official, | 13 | official, |
| 14 | unofficial | 14 | unofficial |
| 15 | } | 15 | } |
| 16 | const [currentRankingType, setCurrentRankingType] = React.useState<LeaderboardTypes>(LeaderboardTypes.official); | ||
| 17 | |||
| 18 | const [leaderboardLoad, setLeaderboardLoad] = React.useState<boolean>(false); | ||
| 16 | 19 | ||
| 17 | enum RankingCategories { | 20 | enum RankingCategories { |
| 18 | rankings_overall, | 21 | rankings_overall, |
| @@ -23,6 +26,7 @@ const Rankings: React.FC = () => { | |||
| 23 | const [load, setLoad] = React.useState<boolean>(false); | 26 | const [load, setLoad] = React.useState<boolean>(false); |
| 24 | 27 | ||
| 25 | const _fetch_rankings = async () => { | 28 | const _fetch_rankings = async () => { |
| 29 | setLeaderboardLoad(false); | ||
| 26 | const rankings = await API.get_official_rankings(); | 30 | const rankings = await API.get_official_rankings(); |
| 27 | setLeaderboardData(rankings); | 31 | setLeaderboardData(rankings); |
| 28 | if (currentLeaderboardType == RankingCategories.rankings_singleplayer) { | 32 | if (currentLeaderboardType == RankingCategories.rankings_singleplayer) { |
| @@ -33,10 +37,12 @@ const Rankings: React.FC = () => { | |||
| 33 | setCurrentLeaderboard(rankings.rankings_overall) | 37 | setCurrentLeaderboard(rankings.rankings_overall) |
| 34 | } | 38 | } |
| 35 | setLoad(true); | 39 | setLoad(true); |
| 40 | setLeaderboardLoad(true); | ||
| 36 | } | 41 | } |
| 37 | 42 | ||
| 38 | const __dev_fetch_unofficial_rankings = async () => { | 43 | const __dev_fetch_unofficial_rankings = async () => { |
| 39 | try { | 44 | try { |
| 45 | setLeaderboardLoad(false); | ||
| 40 | const rankings = await API.get_unofficial_rankings(); | 46 | const rankings = await API.get_unofficial_rankings(); |
| 41 | setLeaderboardData(rankings); | 47 | setLeaderboardData(rankings); |
| 42 | if (currentLeaderboardType == RankingCategories.rankings_singleplayer) { | 48 | if (currentLeaderboardType == RankingCategories.rankings_singleplayer) { |
| @@ -47,6 +53,7 @@ const Rankings: React.FC = () => { | |||
| 47 | } else { | 53 | } else { |
| 48 | setCurrentLeaderboard(rankings.rankings_overall) | 54 | setCurrentLeaderboard(rankings.rankings_overall) |
| 49 | } | 55 | } |
| 56 | setLeaderboardLoad(true); | ||
| 50 | } catch (e) { | 57 | } catch (e) { |
| 51 | console.log(e) | 58 | console.log(e) |
| 52 | } | 59 | } |
| @@ -83,23 +90,23 @@ const Rankings: React.FC = () => { | |||
| 83 | <main> | 90 | <main> |
| 84 | <section className="nav-container nav-1"> | 91 | <section className="nav-container nav-1"> |
| 85 | <div> | 92 | <div> |
| 86 | <button onClick={() => _fetch_rankings()} className="nav-1-btn"> | 93 | <button onClick={() => {_fetch_rankings(); setCurrentRankingType(LeaderboardTypes.official)}} className={`nav-1-btn ${currentRankingType == LeaderboardTypes.official ? "selected" : ""}`}> |
| 87 | <span>Official (LPHUB)</span> | 94 | <span>Official (LPHUB)</span> |
| 88 | </button> | 95 | </button> |
| 89 | <button onClick={() => __dev_fetch_unofficial_rankings()} className="nav-1-btn"> | 96 | <button onClick={() => {__dev_fetch_unofficial_rankings(); setCurrentRankingType(LeaderboardTypes.unofficial)}} className={`nav-1-btn ${currentRankingType == LeaderboardTypes.unofficial ? "selected" : ""}`}> |
| 90 | <span>Unofficial (Steam)</span> | 97 | <span>Unofficial (Steam)</span> |
| 91 | </button> | 98 | </button> |
| 92 | </div> | 99 | </div> |
| 93 | </section> | 100 | </section> |
| 94 | <section className="nav-container nav-2"> | 101 | <section className="nav-container nav-2"> |
| 95 | <div> | 102 | <div> |
| 96 | <button onClick={() => _set_current_leaderboard(RankingCategories.rankings_singleplayer)} className="nav-2-btn"> | 103 | <button onClick={() => _set_current_leaderboard(RankingCategories.rankings_singleplayer)} className={`nav-2-btn ${currentLeaderboardType == RankingCategories.rankings_singleplayer ? "selected" : ""}`}> |
| 97 | <span>Singleplayer</span> | 104 | <span>Singleplayer</span> |
| 98 | </button> | 105 | </button> |
| 99 | <button onClick={() => _set_current_leaderboard(RankingCategories.rankings_multiplayer)} className="nav-2-btn"> | 106 | <button onClick={() => _set_current_leaderboard(RankingCategories.rankings_multiplayer)} className={`nav-2-btn ${currentLeaderboardType == RankingCategories.rankings_multiplayer ? "selected" : ""}`}> |
| 100 | <span>Cooperative</span> | 107 | <span>Cooperative</span> |
| 101 | </button> | 108 | </button> |
| 102 | <button onClick={() => _set_current_leaderboard(RankingCategories.rankings_overall)} className="nav-2-btn"> | 109 | <button onClick={() => _set_current_leaderboard(RankingCategories.rankings_overall)} className={`nav-2-btn ${currentLeaderboardType == RankingCategories.rankings_overall ? "selected" : ""}`}> |
| 103 | <span>Overall</span> | 110 | <span>Overall</span> |
| 104 | </button> | 111 | </button> |
| 105 | </div> | 112 | </div> |
| @@ -116,10 +123,16 @@ const Rankings: React.FC = () => { | |||
| 116 | 123 | ||
| 117 | <div className="splitter"></div> | 124 | <div className="splitter"></div> |
| 118 | 125 | ||
| 119 | {currentLeaderboard?.map((curRankingData, i) => { | 126 | {leaderboardLoad && currentLeaderboard?.map((curRankingData, i) => { |
| 120 | return <RankingEntry currentLeaderboardType={currentLeaderboardType} curRankingData={curRankingData} key={i}></RankingEntry> | 127 | return <RankingEntry currentLeaderboardType={currentLeaderboardType} curRankingData={curRankingData} key={i}></RankingEntry> |
| 121 | }) | 128 | }) |
| 122 | } | 129 | } |
| 130 | |||
| 131 | {leaderboardLoad ? null : | ||
| 132 | <div style={{display: "flex", justifyContent: "center", margin: "30px 0px"}}> | ||
| 133 | <span className="loader"></span> | ||
| 134 | </div> | ||
| 135 | } | ||
| 123 | </div> | 136 | </div> |
| 124 | </section> | 137 | </section> |
| 125 | : null} | 138 | : null} |