diff options
| author | Arda Serdar Pektezol <1669855+pektezol@users.noreply.github.com> | 2024-09-03 00:08:53 +0300 |
|---|---|---|
| committer | Arda Serdar Pektezol <1669855+pektezol@users.noreply.github.com> | 2024-09-03 00:08:53 +0300 |
| commit | a65d6d9127c3fa7f6a8ecaec5d1ffd1f47c2bc98 (patch) | |
| tree | edf8630e9d6426124dd49854af0cb703ebc5b710 /frontend/src/components/Leaderboards.tsx | |
| parent | fix: revert to static homepage (#195) (diff) | |
| download | lphub-a65d6d9127c3fa7f6a8ecaec5d1ffd1f47c2bc98.tar.gz lphub-a65d6d9127c3fa7f6a8ecaec5d1ffd1f47c2bc98.tar.bz2 lphub-a65d6d9127c3fa7f6a8ecaec5d1ffd1f47c2bc98.zip | |
refactor: port to typescript
Diffstat (limited to 'frontend/src/components/Leaderboards.tsx')
| -rw-r--r-- | frontend/src/components/Leaderboards.tsx | 105 |
1 files changed, 105 insertions, 0 deletions
diff --git a/frontend/src/components/Leaderboards.tsx b/frontend/src/components/Leaderboards.tsx new file mode 100644 index 0000000..badff37 --- /dev/null +++ b/frontend/src/components/Leaderboards.tsx | |||
| @@ -0,0 +1,105 @@ | |||
| 1 | import React from 'react'; | ||
| 2 | |||
| 3 | import { DownloadIcon, ThreedotIcon } from '../images/Images'; | ||
| 4 | import { MapLeaderboard } from '../types/Map'; | ||
| 5 | import { ticks_to_time, time_ago } from '../utils/Time'; | ||
| 6 | import "../css/Maps.css" | ||
| 7 | |||
| 8 | interface LeaderboardsProps { | ||
| 9 | data?: MapLeaderboard; | ||
| 10 | } | ||
| 11 | |||
| 12 | const Leaderboards: React.FC<LeaderboardsProps> = ({ data }) => { | ||
| 13 | |||
| 14 | const [pageNumber, setPageNumber] = React.useState<number>(1); | ||
| 15 | |||
| 16 | if (!data) { | ||
| 17 | return ( | ||
| 18 | <section id='section6' className='summary2'> | ||
| 19 | <h1 style={{ textAlign: "center" }}>Map is not available for competitive boards.</h1> | ||
| 20 | </section> | ||
| 21 | ); | ||
| 22 | }; | ||
| 23 | |||
| 24 | if (data.records.length === 0) { | ||
| 25 | return ( | ||
| 26 | <section id='section6' className='summary2'> | ||
| 27 | <h1 style={{ textAlign: "center" }}>No records found.</h1> | ||
| 28 | </section> | ||
| 29 | ); | ||
| 30 | }; | ||
| 31 | |||
| 32 | return ( | ||
| 33 | <section id='section6' className='summary2'> | ||
| 34 | |||
| 35 | <div id='leaderboard-top' | ||
| 36 | style={data.map.is_coop ? { gridTemplateColumns: "7.5% 40% 7.5% 15% 15% 15%" } : { gridTemplateColumns: "7.5% 30% 10% 20% 17.5% 15%" }} | ||
| 37 | > | ||
| 38 | <span>Place</span> | ||
| 39 | |||
| 40 | {data.map.is_coop ? ( | ||
| 41 | <div id='runner'> | ||
| 42 | <span>Host</span> | ||
| 43 | <span>Partner</span> | ||
| 44 | </div> | ||
| 45 | ) : ( | ||
| 46 | <span>Runner</span> | ||
| 47 | )} | ||
| 48 | |||
| 49 | <span>Portals</span> | ||
| 50 | <span>Time</span> | ||
| 51 | <span>Date</span> | ||
| 52 | <div id='page-number'> | ||
| 53 | <div> | ||
| 54 | |||
| 55 | <button onClick={() => pageNumber === 1 ? null : setPageNumber(prevPageNumber => prevPageNumber - 1)} | ||
| 56 | ><i className='triangle' style={{ position: 'relative', left: '-5px', }}></i> </button> | ||
| 57 | <span>{data.pagination.current_page}/{data.pagination.total_pages}</span> | ||
| 58 | <button onClick={() => pageNumber === data.pagination.total_pages ? null : setPageNumber(prevPageNumber => prevPageNumber + 1)} | ||
| 59 | ><i className='triangle' style={{ position: 'relative', left: '5px', transform: 'rotate(180deg)' }}></i> </button> | ||
| 60 | </div> | ||
| 61 | </div> | ||
| 62 | </div> | ||
| 63 | <hr /> | ||
| 64 | <div id='leaderboard-records'> | ||
| 65 | {data.records.map((r, index) => ( | ||
| 66 | <span className='leaderboard-record' key={index} | ||
| 67 | style={data.map.is_coop ? { gridTemplateColumns: "3% 4.5% 40% 4% 3.5% 15% 15% 14.5%" } : { gridTemplateColumns: "3% 4.5% 30% 4% 6% 20% 17% 15%" }} | ||
| 68 | > | ||
| 69 | <span>{r.placement}</span> | ||
| 70 | <span> </span> | ||
| 71 | {r.kind === "multiplayer" ? ( | ||
| 72 | <div> | ||
| 73 | <span><img src={r.host.avatar_link} alt='' /> {r.host.user_name}</span> | ||
| 74 | <span><img src={r.partner.avatar_link} alt='' /> {r.partner.user_name}</span> | ||
| 75 | </div> | ||
| 76 | ) : ( | ||
| 77 | <div><span><img src={r.user.avatar_link} alt='' /> {r.user.user_name}</span></div> | ||
| 78 | )} | ||
| 79 | |||
| 80 | <span>{r.score_count}</span> | ||
| 81 | <span> </span> | ||
| 82 | <span className='hover-popup' popup-text={(r.score_time) + " ticks"}>{ticks_to_time(r.score_time)}</span> | ||
| 83 | <span className='hover-popup' popup-text={r.record_date.replace("T", ' ').split(".")[0]}>{time_ago(new Date(r.record_date.replace("T", " ").replace("Z", "")))}</span> | ||
| 84 | |||
| 85 | {r.kind === "multiplayer" ? ( | ||
| 86 | <span> | ||
| 87 | <button onClick={() => { window.alert(`Host demo ID: ${r.host_demo_id} \nParnter demo ID: ${r.partner_demo_id}`) }}><img src={ThreedotIcon} alt="demo_id" /></button> | ||
| 88 | <button onClick={() => window.location.href = `https://lp.ardapektezol.com/api/v1/demos?uuid=${r.partner_demo_id}`}><img src={DownloadIcon} alt="download" style={{ filter: "hue-rotate(160deg) contrast(60%) saturate(1000%)" }} /></button> | ||
| 89 | <button onClick={() => window.location.href = `https://lp.ardapektezol.com/api/v1/demos?uuid=${r.host_demo_id}`}><img src={DownloadIcon} alt="download" style={{ filter: "hue-rotate(300deg) contrast(60%) saturate(1000%)" }} /></button> | ||
| 90 | </span> | ||
| 91 | ) : ( | ||
| 92 | |||
| 93 | <span> | ||
| 94 | <button onClick={() => { window.alert(`Demo ID: ${r.demo_id}`) }}><img src={ThreedotIcon} alt="demo_id" /></button> | ||
| 95 | <button onClick={() => window.location.href = `https://lp.ardapektezol.com/api/v1/demos?uuid=${r.demo_id}`}><img src={DownloadIcon} alt="download" /></button> | ||
| 96 | </span> | ||
| 97 | )} | ||
| 98 | </span> | ||
| 99 | ))} | ||
| 100 | </div> | ||
| 101 | </section> | ||
| 102 | ); | ||
| 103 | }; | ||
| 104 | |||
| 105 | export default Leaderboards; | ||