diff options
Diffstat (limited to 'frontend/src/components/Summary.tsx')
| -rw-r--r-- | frontend/src/components/Summary.tsx | 39 |
1 files changed, 21 insertions, 18 deletions
diff --git a/frontend/src/components/Summary.tsx b/frontend/src/components/Summary.tsx index 1ba166a..9f39506 100644 --- a/frontend/src/components/Summary.tsx +++ b/frontend/src/components/Summary.tsx | |||
| @@ -18,18 +18,21 @@ const Summary: React.FC<SummaryProps> = ({ | |||
| 18 | const [selectedCategory, setSelectedCategory] = React.useState<number>(1); | 18 | const [selectedCategory, setSelectedCategory] = React.useState<number>(1); |
| 19 | const [historySelected, setHistorySelected] = React.useState<boolean>(false); | 19 | const [historySelected, setHistorySelected] = React.useState<boolean>(false); |
| 20 | 20 | ||
| 21 | function _select_run(idx: number, category_id: number) { | 21 | const _select_run = React.useCallback( |
| 22 | let r = document.querySelectorAll('button.record'); | 22 | (idx: number, category_id: number) => { |
| 23 | r.forEach(e => ((e as HTMLElement).style.backgroundColor = '#2b2e46')); | 23 | let r = document.querySelectorAll('button.record'); |
| 24 | (r[idx] as HTMLElement).style.backgroundColor = '#161723'; | 24 | r.forEach(e => ((e as HTMLElement).style.backgroundColor = '#2b2e46')); |
| 25 | (r[idx] as HTMLElement).style.backgroundColor = '#161723'; | ||
| 25 | 26 | ||
| 26 | if (data && data.summary.routes.length !== 0) { | 27 | if (data && data.summary.routes.length !== 0) { |
| 27 | idx += data.summary.routes.filter( | 28 | idx += data.summary.routes.filter( |
| 28 | e => e.category.id < category_id | 29 | e => e.category.id < category_id |
| 29 | ).length; // lethimcook | 30 | ).length; // lethimcook |
| 30 | setSelectedRun(idx); | 31 | setSelectedRun(idx); |
| 31 | } | 32 | } |
| 32 | } | 33 | }, |
| 34 | [data, setSelectedRun] | ||
| 35 | ); | ||
| 33 | 36 | ||
| 34 | function _get_youtube_id(url: string): string { | 37 | function _get_youtube_id(url: string): string { |
| 35 | const urlArray = url.split(/(vi\/|v=|\/v\/|youtu\.be\/|\/embed\/)/); | 38 | const urlArray = url.split(/(vi\/|v=|\/v\/|youtu\.be\/|\/embed\/)/); |
| @@ -38,7 +41,7 @@ const Summary: React.FC<SummaryProps> = ({ | |||
| 38 | : urlArray[0]; | 41 | : urlArray[0]; |
| 39 | } | 42 | } |
| 40 | 43 | ||
| 41 | function _category_change() { | 44 | const _category_change = React.useCallback(() => { |
| 42 | const btn = document.querySelectorAll('#section3 #category span button'); | 45 | const btn = document.querySelectorAll('#section3 #category span button'); |
| 43 | btn.forEach(e => { | 46 | btn.forEach(e => { |
| 44 | (e as HTMLElement).style.backgroundColor = '#2b2e46'; | 47 | (e as HTMLElement).style.backgroundColor = '#2b2e46'; |
| @@ -51,9 +54,9 @@ const Summary: React.FC<SummaryProps> = ({ | |||
| 51 | ? selectedCategory - 3 | 54 | ? selectedCategory - 3 |
| 52 | : selectedCategory - 1; | 55 | : selectedCategory - 1; |
| 53 | (btn[idx] as HTMLElement).style.backgroundColor = '#202232'; | 56 | (btn[idx] as HTMLElement).style.backgroundColor = '#202232'; |
| 54 | } | 57 | }, [selectedCategory, data.map.is_coop]); |
| 55 | 58 | ||
| 56 | function _history_change() { | 59 | const _history_change = React.useCallback(() => { |
| 57 | const btn = document.querySelectorAll('#section3 #history span button'); | 60 | const btn = document.querySelectorAll('#section3 #history span button'); |
| 58 | btn.forEach(e => { | 61 | btn.forEach(e => { |
| 59 | (e as HTMLElement).style.backgroundColor = '#2b2e46'; | 62 | (e as HTMLElement).style.backgroundColor = '#2b2e46'; |
| @@ -62,20 +65,20 @@ const Summary: React.FC<SummaryProps> = ({ | |||
| 62 | ? (btn[1] as HTMLElement) | 65 | ? (btn[1] as HTMLElement) |
| 63 | : (btn[0] as HTMLElement) | 66 | : (btn[0] as HTMLElement) |
| 64 | ).style.backgroundColor = '#202232'; | 67 | ).style.backgroundColor = '#202232'; |
| 65 | } | 68 | }, [historySelected]); |
| 66 | 69 | ||
| 67 | React.useEffect(() => { | 70 | React.useEffect(() => { |
| 68 | _history_change(); | 71 | _history_change(); |
| 69 | }, [historySelected]); | 72 | }, [historySelected, _history_change]); |
| 70 | 73 | ||
| 71 | React.useEffect(() => { | 74 | React.useEffect(() => { |
| 72 | _category_change(); | 75 | _category_change(); |
| 73 | _select_run(0, selectedCategory); | 76 | _select_run(0, selectedCategory); |
| 74 | }, [selectedCategory]); | 77 | }, [selectedCategory, _category_change, _select_run]); |
| 75 | 78 | ||
| 76 | React.useEffect(() => { | 79 | React.useEffect(() => { |
| 77 | _select_run(0, selectedCategory); | 80 | _select_run(0, selectedCategory); |
| 78 | }, []); | 81 | }, [_select_run, selectedCategory]); |
| 79 | 82 | ||
| 80 | return ( | 83 | return ( |
| 81 | <> | 84 | <> |