/* * Copyright (C) 2024 Aleksander WilczyƄski (aleks@alekswilc.dev) * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Affero General Public License as published * by the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Affero General Public License for more details. * * See LICENSE for more. */ import { useState } from "react"; import { TProfileData } from "../../../types/profile.ts"; import { useTranslation } from "react-i18next"; import { ArrowIcon } from "../../mini/icons/ArrowIcon.tsx"; import { formatTime } from "../../../util/time.ts"; import { FaCheck } from "react-icons/fa6"; export const ProfileCard = ({ data }: { data: TProfileData }) => { const [ showTrains, setShowTrains ] = useState(false); const [ showStations, setShowStations ] = useState(false); const [ sortTrainsBy, setSortTrainsBy ] = useState<"time" | "score" | "distance">("score"); const { t } = useTranslation(); return
profile

{ data.steam.personname } { data.player.verified && }

{ Math.floor(data.player.trainDistance / 1000) }km { t("profile.stats.distance") }
{ formatTime(data.player.dispatcherTime) } { t("profile.stats.time") }
{ Object.keys(data.player.trainStats || {}).length > 0 &&
setShowTrains(val => !val) }>

{ t("profile.trains.header") }

{ showTrains &&
{ t("profile.trains.train") }
setSortTrainsBy("distance") }>
{ t("profile.trains.distance") }
setSortTrainsBy("score") }>
{ t("profile.trains.points") }
setSortTrainsBy("time") }>
{ t("profile.trains.time") }
{ Object.keys(data.player.trainStats).sort((a, b) => data.player.trainStats[ b ][ sortTrainsBy ] - data.player.trainStats[ a ][ sortTrainsBy ]).map(trainName => { const train = data.player.trainStats[ trainName ]; return

{ trainName }

{ Math.floor(train.distance / 1000) }km

{ train.score }

{ formatTime(train.time) }

; }) }
}
} { Object.keys(data.player.dispatcherStats || {}).length > 0 &&
setShowStations(val => !val) }>

{ t("profile.stations.header") }

{ showStations &&
{ t("profile.stations.station") }
{ t("profile.stations.time") }
{ Object.keys(data.player.dispatcherStats).sort((a, b) => data.player.dispatcherStats[ b ].time - data.player.dispatcherStats[ a ].time).map(stationName => { const station = data.player.dispatcherStats[ stationName ]; return

{ stationName }

{ formatTime(station.time) }

; }) }
}
}
; };