From b5c0c0a991de459a6744d2475c735b0327a10f4d Mon Sep 17 00:00:00 2001 From: Pinapelz Date: Sun, 6 Jul 2025 14:53:55 -0700 Subject: add menu to allow score to be filtered by sortKey --- frontend/src/pages/Score.tsx | 54 +++++++++++++++++++++++++++++++++++++++----- 1 file changed, 48 insertions(+), 6 deletions(-) (limited to 'frontend/src/pages/Score.tsx') diff --git a/frontend/src/pages/Score.tsx b/frontend/src/pages/Score.tsx index 8e16a86..2bf1a2b 100644 --- a/frontend/src/pages/Score.tsx +++ b/frontend/src/pages/Score.tsx @@ -20,6 +20,7 @@ const Score = () => { const [viewMode, setViewMode] = useState<"cards" | "table">("cards"); const [sortField, setSortField] = useState(""); const [sortDirection, setSortDirection] = useState("asc"); + const [requestOrder, setRequestOrder] = useState("timestamp"); const gameName = new URLSearchParams(window.location.search).get("game") || "dancerush"; @@ -33,6 +34,37 @@ const Score = () => { alert("Network error during logout. Please try again."); } }; + + const renderRequestFilterMenu = () => { + if (gameName === "dancerush") { + const filterOptions = [ + { value: "timestamp", label: "Recent" }, + { value: "score", label: "Score" }, + { value: "lamp", label: "Rank" }, + { value: "lamo_diff", label: "Difficulty" }, + ]; + + return ( +
+ {filterOptions.map((option) => ( + + ))} +
+ ); + } + return null; + }; + // eslint-disable-next-line @typescript-eslint/no-explicit-any const flattenScoreData = (score: any) => { const flat = { ...score, ...score.data }; @@ -51,7 +83,7 @@ const Score = () => { url.searchParams.append("userId", user.id); url.searchParams.append("internalGameName", gameName); url.searchParams.append("pageNum", pageNum.toString()); - url.searchParams.append("sortKey", 'timestamp'); + url.searchParams.append("sortKey", requestOrder); url.searchParams.append("direction", "asc"); const response = await fetch(url.toString()); @@ -68,7 +100,7 @@ const Score = () => { setLoading(false); } }, - [user], + [user, gameName, requestOrder], ); useEffect(() => { @@ -101,7 +133,7 @@ const Score = () => { return (
- +
@@ -131,9 +163,16 @@ const Score = () => {
-

- Displaying {scores.length} scores • Page {currentPage} of {numPages} -

+ + {/* Filter Menu */} +
+
+ + Sort by: + + {renderRequestFilterMenu()} +
+
{(() => { @@ -180,6 +219,9 @@ const Score = () => { )} +

+ Displaying {scores.length} scores • Page {currentPage} of {numPages} +

); -- cgit v1.2.3