diff options
| author | Arda Serdar Pektezol <1669855+pektezol@users.noreply.github.com> | 2024-09-05 12:59:42 +0300 |
|---|---|---|
| committer | Arda Serdar Pektezol <1669855+pektezol@users.noreply.github.com> | 2024-09-05 12:59:42 +0300 |
| commit | da5be7e26336f9e02978ebe239e7ae8309bc7a3b (patch) | |
| tree | 40a11785c77fa4af6486b3b3e898258dcd0538c3 /frontend/src/components/Summary.tsx | |
| parent | refactor: beta homepage text (diff) | |
| download | lphub-da5be7e26336f9e02978ebe239e7ae8309bc7a3b.tar.gz lphub-da5be7e26336f9e02978ebe239e7ae8309bc7a3b.tar.bz2 lphub-da5be7e26336f9e02978ebe239e7ae8309bc7a3b.zip | |
refactor: fix summary cat change logic
Diffstat (limited to 'frontend/src/components/Summary.tsx')
| -rw-r--r-- | frontend/src/components/Summary.tsx | 21 |
1 files changed, 11 insertions, 10 deletions
diff --git a/frontend/src/components/Summary.tsx b/frontend/src/components/Summary.tsx index b8f0087..23da82c 100644 --- a/frontend/src/components/Summary.tsx +++ b/frontend/src/components/Summary.tsx | |||
| @@ -15,17 +15,17 @@ const Summary: React.FC<SummaryProps> = ({ selectedRun, setSelectedRun, data }) | |||
| 15 | const [selectedCategory, setSelectedCategory] = React.useState<number>(1); | 15 | const [selectedCategory, setSelectedCategory] = React.useState<number>(1); |
| 16 | const [historySelected, setHistorySelected] = React.useState<boolean>(false); | 16 | const [historySelected, setHistorySelected] = React.useState<boolean>(false); |
| 17 | 17 | ||
| 18 | function _select_run(x: number, y: number) { | 18 | function _select_run(idx: number, category_id: number) { |
| 19 | let r = document.querySelectorAll("button.record"); | 19 | let r = document.querySelectorAll("button.record"); |
| 20 | r.forEach(e => (e as HTMLElement).style.backgroundColor = "#2b2e46"); | 20 | r.forEach(e => (e as HTMLElement).style.backgroundColor = "#2b2e46"); |
| 21 | (r[x] as HTMLElement).style.backgroundColor = "#161723" | 21 | (r[idx] as HTMLElement).style.backgroundColor = "#161723" |
| 22 | 22 | ||
| 23 | 23 | ||
| 24 | if (data && data.summary.routes.length !== 0 && data.summary.routes.length !== 0) { | 24 | if (data && data.summary.routes.length !== 0 && data.summary.routes.length !== 0) { |
| 25 | if (y === 2) { x += data.summary.routes.filter(e => e.category.id < 2).length } | 25 | if (category_id === 2) { idx += data.summary.routes.filter(e => e.category.id < 2).length } |
| 26 | if (y === 3) { x += data.summary.routes.filter(e => e.category.id < 3).length } | 26 | if (category_id === 3) { idx += data.summary.routes.filter(e => e.category.id < 3).length } |
| 27 | if (y === 4) { x += data.summary.routes.filter(e => e.category.id < 4).length } | 27 | if (category_id === 4) { idx += data.summary.routes.filter(e => e.category.id < 4).length } |
| 28 | setSelectedRun(x); | 28 | setSelectedRun(idx); |
| 29 | } | 29 | } |
| 30 | } | 30 | } |
| 31 | 31 | ||
| @@ -52,6 +52,7 @@ const Summary: React.FC<SummaryProps> = ({ selectedRun, setSelectedRun, data }) | |||
| 52 | 52 | ||
| 53 | React.useEffect(() => { | 53 | React.useEffect(() => { |
| 54 | _category_change(); | 54 | _category_change(); |
| 55 | _select_run(0, selectedCategory); | ||
| 55 | }, [selectedCategory]); | 56 | }, [selectedCategory]); |
| 56 | 57 | ||
| 57 | React.useEffect(() => { | 58 | React.useEffect(() => { |
| @@ -84,7 +85,7 @@ const Summary: React.FC<SummaryProps> = ({ selectedRun, setSelectedRun, data }) | |||
| 84 | <div className='record-top'> | 85 | <div className='record-top'> |
| 85 | <span>Date</span> | 86 | <span>Date</span> |
| 86 | <span>Record</span> | 87 | <span>Record</span> |
| 87 | <span>First completion</span> | 88 | <span>First Completion</span> |
| 88 | </div> | 89 | </div> |
| 89 | <hr /> | 90 | <hr /> |
| 90 | <div id='records'> | 91 | <div id='records'> |
| @@ -143,8 +144,8 @@ const Summary: React.FC<SummaryProps> = ({ selectedRun, setSelectedRun, data }) | |||
| 143 | </div> | 144 | </div> |
| 144 | </div> | 145 | </div> |
| 145 | <div id='count'> | 146 | <div id='count'> |
| 146 | <span>Completion count</span> | 147 | <span>Completion Count</span> |
| 147 | <div>{selectedCategory === 1 ? data.summary.routes[selectedRun].completion_count : "N/A"}</div> | 148 | <div>{data.summary.routes[selectedRun].completion_count}</div> |
| 148 | </div> | 149 | </div> |
| 149 | </section> | 150 | </section> |
| 150 | 151 | ||
| @@ -153,7 +154,7 @@ const Summary: React.FC<SummaryProps> = ({ selectedRun, setSelectedRun, data }) | |||
| 153 | {data.summary.routes.sort((a, b) => a.category.id - b.category.id)[selectedRun].showcase !== "" ? | 154 | {data.summary.routes.sort((a, b) => a.category.id - b.category.id)[selectedRun].showcase !== "" ? |
| 154 | <iframe title='Showcase video' src={"https://www.youtube.com/embed/" + _get_youtube_id(data.summary.routes[selectedRun].showcase)}> </iframe> | 155 | <iframe title='Showcase video' src={"https://www.youtube.com/embed/" + _get_youtube_id(data.summary.routes[selectedRun].showcase)}> </iframe> |
| 155 | : ""} | 156 | : ""} |
| 156 | <h3>Route description</h3> | 157 | <h3>Route Description</h3> |
| 157 | <span id='description-text'> | 158 | <span id='description-text'> |
| 158 | <ReactMarkdown> | 159 | <ReactMarkdown> |
| 159 | {data.summary.routes.sort((a, b) => a.category.id - b.category.id)[selectedRun].description} | 160 | {data.summary.routes.sort((a, b) => a.category.id - b.category.id)[selectedRun].description} |