From 27f77ec9b5b9511df680948b460f5119431b84eb Mon Sep 17 00:00:00 2001 From: Paulsenik Date: Sat, 28 Dec 2024 17:08:10 +0100 Subject: [PATCH] remove anonymous in user-leaderboards --- .../Components/StatisticsTab/Leaderboard.tsx | 316 +++++++++--------- 1 file changed, 161 insertions(+), 155 deletions(-) diff --git a/frontend/src/Components/StatisticsTab/Leaderboard.tsx b/frontend/src/Components/StatisticsTab/Leaderboard.tsx index 83826aa..98f39c1 100644 --- a/frontend/src/Components/StatisticsTab/Leaderboard.tsx +++ b/frontend/src/Components/StatisticsTab/Leaderboard.tsx @@ -1,19 +1,24 @@ -import { Link } from "react-router-dom"; +import {Link} from "react-router-dom"; import { - UserMetricType, - UserMetricEntry, - TimeSpan, - ItemMetricType, - ItemMetricEntry, + CompositeMetricEntry, + CompositeMetricType, convertUsersBalance, convertUsersSpent, - CompositeMetricType, - CompositeMetricEntry, + ItemMetricEntry, + ItemMetricType, + TimeSpan, + UserMetricEntry, + UserMetricType, } from "../../Types/Statistics"; -import { useEffect, useState } from "react"; -import { getAllUsers, getCompositeMetric, getItemMetric, getUserMetric } from "../../Queries"; -import { ScrollArea, ScrollAreaScrollbar, ScrollAreaThumb, ScrollAreaViewport } from "@radix-ui/react-scroll-area"; -import { formatMoney } from "../../Format"; +import {useEffect, useState} from "react"; +import {getAllUsers, getCompositeMetric, getItemMetric, getUserMetric} from "../../Queries"; +import { + ScrollArea, + ScrollAreaScrollbar, + ScrollAreaThumb, + ScrollAreaViewport +} from "@radix-ui/react-scroll-area"; +import {formatMoney} from "../../Format"; export function CompositeLeaderboard(props: { type: CompositeMetricType; @@ -22,7 +27,7 @@ export function CompositeLeaderboard(props: { desc: string; isMoney: boolean; }) { - const { type, timeSpan, title, desc, isMoney } = props; + const {type, timeSpan, title, desc, isMoney} = props; const [stats, setStats] = useState([]); const [options, setOptions] = useState<[string, string][]>([]); const [selected, setSelected] = useState<[string, string]>(); @@ -45,66 +50,66 @@ export function CompositeLeaderboard(props: { useEffect(() => { const uniqueKeys = Array.from( - new Set(stats.map((entry) => JSON.stringify([entry.key1, entry.key1DisplayName]))) + new Set(stats.map((entry) => JSON.stringify([entry.key1, entry.key1DisplayName]))) ).map((key) => JSON.parse(key)); setOptions(uniqueKeys.sort((a: string, b: string) => a[0].localeCompare(b[0]))); setSelected(uniqueKeys[0]); }, [stats]); return ( - -
-

{title}

- -

{desc}

-
+

{title}

+ +

{desc}

+ - - - + +
+ {stats - .filter((a) => { - return selected && a.key1 == selected[0]; - }) - .map((entry, index) => { - return ( + .filter((a) => { + return selected && a.key1 == selected[0]; + }) + .map((entry, index) => { + return ( - ); - })} - -
-
- - - - - - -
+ ); + })} + + + + + + + + + + ); } @@ -115,59 +120,59 @@ export function ItemLeaderboard(props: { desc: string; isMoney: boolean; }) { - const { type, timeSpan, title, desc, isMoney } = props; + const {type, timeSpan, title, desc, isMoney} = props; const [stats, setStats] = useState([]); useEffect(() => { getItemMetric(type, timeSpan) - .then((l) => { - if (l) { - setStats(l); - } - }) - .catch(() => { - setStats([]); - }); + .then((l) => { + if (l) { + setStats(l); + } + }) + .catch(() => { + setStats([]); + }); }, [timeSpan]); return ( - -
-

{title}

-

{desc}

-
- - - + +
+

{title}

+

{desc}

+
+ +
+ {stats.map((entry, index) => { return ( - + ); })} - -
-
- - - - - - -
+ + + + + + + + + + ); } @@ -178,7 +183,7 @@ export function UserLeaderboard(props: { desc: string; isMoney: boolean; }) { - const { type, timeSpan, title, desc, isMoney } = props; + const {type, timeSpan, title, desc, isMoney} = props; const [stats, setStats] = useState([]); useEffect(() => { @@ -204,43 +209,43 @@ export function UserLeaderboard(props: { }, [timeSpan]); return ( - -
-

{title}

-

{desc}

-
- - - - {stats.map((entry, index) => { + +
+

{title}

+

{desc}

+
+ +
+ + {stats.filter((e) => (!e.entity.hidden)).map((entry, index) => { return ( - + ); })} - -
-
- - - - - - -
+ + + + + + + + + + ); } @@ -253,23 +258,24 @@ export function LeaderboardEntry(props: { isMoney: boolean; anonymize: boolean; }) { - const { entryDisplayName, entryId, entryValue, position, isUser, isMoney, anonymize } = props; + const {entryDisplayName, entryId, entryValue, position, isUser, isMoney, anonymize} = props; return ( - - {position} - - {isUser && anonymize ? ( - <>Anonyme 🍍 - ) : isUser ? ( - - {entryDisplayName} - - ) : ( - <>{entryDisplayName} - )} - - {isMoney ? {formatMoney(entryValue)} : {entryValue}} - + + {position} + + {isUser && anonymize ? ( + <>Anonyme 🍍 + ) : isUser ? ( + + {entryDisplayName} + + ) : ( + <>{entryDisplayName} + )} + + {isMoney ? {formatMoney(entryValue)} : + {entryValue}} + ); }