From a65d6d9127c3fa7f6a8ecaec5d1ffd1f47c2bc98 Mon Sep 17 00:00:00 2001 From: Arda Serdar Pektezol <1669855+pektezol@users.noreply.github.com> Date: Tue, 3 Sep 2024 00:08:53 +0300 Subject: refactor: port to typescript --- frontend/src/components/Summary.tsx | 169 ++++++++++++++++++++++++++++++++++++ 1 file changed, 169 insertions(+) create mode 100644 frontend/src/components/Summary.tsx (limited to 'frontend/src/components/Summary.tsx') diff --git a/frontend/src/components/Summary.tsx b/frontend/src/components/Summary.tsx new file mode 100644 index 0000000..b8f0087 --- /dev/null +++ b/frontend/src/components/Summary.tsx @@ -0,0 +1,169 @@ +import React from 'react'; +import ReactMarkdown from 'react-markdown'; + +import { MapSummary } from '../types/Map'; +import "../css/Maps.css" + +interface SummaryProps { + selectedRun: number + setSelectedRun: (x: number) => void; + data: MapSummary; +} + +const Summary: React.FC = ({ selectedRun, setSelectedRun, data }) => { + + const [selectedCategory, setSelectedCategory] = React.useState(1); + const [historySelected, setHistorySelected] = React.useState(false); + + function _select_run(x: number, y: number) { + let r = document.querySelectorAll("button.record"); + r.forEach(e => (e as HTMLElement).style.backgroundColor = "#2b2e46"); + (r[x] as HTMLElement).style.backgroundColor = "#161723" + + + if (data && data.summary.routes.length !== 0 && data.summary.routes.length !== 0) { + if (y === 2) { x += data.summary.routes.filter(e => e.category.id < 2).length } + if (y === 3) { x += data.summary.routes.filter(e => e.category.id < 3).length } + if (y === 4) { x += data.summary.routes.filter(e => e.category.id < 4).length } + setSelectedRun(x); + } + } + + function _get_youtube_id(url: string): string { + const urlArray = url.split(/(vi\/|v=|\/v\/|youtu\.be\/|\/embed\/)/); + return (urlArray[2] !== undefined) ? urlArray[2].split(/[^0-9a-z_]/i)[0] : urlArray[0]; + }; + + function _category_change() { + const btn = document.querySelectorAll("#section3 #category span button"); + btn.forEach((e) => { (e as HTMLElement).style.backgroundColor = "#2b2e46" }); + (btn[selectedCategory - 1] as HTMLElement).style.backgroundColor = "#202232"; + }; + + function _history_change() { + const btn = document.querySelectorAll("#section3 #history span button"); + btn.forEach((e) => { (e as HTMLElement).style.backgroundColor = "#2b2e46" }); + (historySelected ? btn[1] as HTMLElement : btn[0] as HTMLElement).style.backgroundColor = "#202232"; + }; + + React.useEffect(() => { + _history_change(); + }, [historySelected]); + + React.useEffect(() => { + _category_change(); + }, [selectedCategory]); + + React.useEffect(() => { + _select_run(0, selectedCategory); + }, []); + + return ( + <> +
+
+ +

{data.summary.routes.sort((a, b) => a.category.id - b.category.id)[selectedRun].history.score_count} + {data.summary.routes.sort((a, b) => a.category.id - b.category.id)[selectedRun].history.score_count === 1 ? ` portal` : ` portals`}

+ + + + {data.map.is_coop ? + : } + + + +
+ +
+ +
+ {data.summary.routes.filter(e => e.category.id === selectedCategory).length === 0 ?
There are no records for this map.
: + <> +
+ Date + Record + First completion +
+
+
+ + {data.summary.routes + .sort((a, b) => a.history.score_count - b.history.score_count) + .filter(e => e.category.id === selectedCategory) + .map((r, index) => ( + + ))} +
+ + } +
+ +
+ {data.summary.routes.filter(e => e.category.id === selectedCategory).length === 0 ?
There are no records for this map.
: +
+ {/*
{graph(1)}
+
{graph(2)}
+
{graph(3)}
*/} +
+ } +
+ + + + +
+ + +
+
+
+ Difficulty + {data.summary.routes.sort((a, b) => a.category.id - b.category.id)[selectedRun].rating === 0 ? (N/A) : null} + {data.summary.routes.sort((a, b) => a.category.id - b.category.id)[selectedRun].rating === 1 ? (Very easy) : null} + {data.summary.routes.sort((a, b) => a.category.id - b.category.id)[selectedRun].rating === 2 ? (Easy) : null} + {data.summary.routes.sort((a, b) => a.category.id - b.category.id)[selectedRun].rating === 3 ? (Medium) : null} + {data.summary.routes.sort((a, b) => a.category.id - b.category.id)[selectedRun].rating === 4 ? (Hard) : null} + {data.summary.routes.sort((a, b) => a.category.id - b.category.id)[selectedRun].rating === 5 ? (Very hard) : null} +
+ {data.summary.routes.sort((a, b) => a.category.id - b.category.id)[selectedRun].rating === 1 ? (
) : (
)} + {data.summary.routes.sort((a, b) => a.category.id - b.category.id)[selectedRun].rating === 2 ? (
) : (
)} + {data.summary.routes.sort((a, b) => a.category.id - b.category.id)[selectedRun].rating === 3 ? (
) : (
)} + {data.summary.routes.sort((a, b) => a.category.id - b.category.id)[selectedRun].rating === 4 ? (
) : (
)} + {data.summary.routes.sort((a, b) => a.category.id - b.category.id)[selectedRun].rating === 5 ? (
) : (
)} +
+
+
+ Completion count +
{selectedCategory === 1 ? data.summary.routes[selectedRun].completion_count : "N/A"}
+
+
+ +
+
+ {data.summary.routes.sort((a, b) => a.category.id - b.category.id)[selectedRun].showcase !== "" ? + + : ""} +

Route description

+ + + {data.summary.routes.sort((a, b) => a.category.id - b.category.id)[selectedRun].description} + + +
+
+ + + ); +}; + +export default Summary; -- cgit v1.2.3