import React, { useState, useContext } from "react" import { useQuery } from "@apollo/react-hooks" import Loading from "../common/Loading" import Error from "../common/Error" import { RouteComponentProps } from "@reach/router" import { Flex, Heading, Avatar, Box, Icon } from "@chakra-ui/core" import PageHeader from "../common/PageHeader" import { Helmet } from "react-helmet-async" import { PLUS_MAPLISTS, PlusMaplistsData, } from "../../graphql/queries/plusMaplists" import MyThemeContext from "../../themeContext" import { Stage } from "../../types" import { mapIcons } from "../../assets/imageImports" import { FaArrowLeft, FaArrowRight } from "react-icons/fa" import IconButton from "../elements/IconButton" interface MaplistCardProps { maplist: Stage[] voteCounts: { name: Stage sz: number[] tc: number[] rm: number[] cb: number[] }[] modeShort: "sz" | "tc" | "rm" | "cb" } const MaplistCard: React.FC = ({ maplist, voteCounts, modeShort, }) => { const { grayWithShade, themeColorHex, colorMode, themeColorWithShade, } = useContext(MyThemeContext) const votedMaps = voteCounts.reduce((acc, cur) => { const maxScore = (cur[modeShort][0] + cur[modeShort][1] + cur[modeShort][2]) * 2 const score = +( ((cur[modeShort][1] * 1 + cur[modeShort][2] * 2) / maxScore) * 100 ).toFixed(2) const mapObject = { name: cur.name, score, votes: cur[modeShort] } return [...acc, mapObject] }, [] as { name: string; score: number; votes: number[] }[]) votedMaps.sort((a, b) => b.score - a.score) const shade = colorMode === "light" ? "600" : "400" return ( <> {votedMaps.map(stage => { return ( {stage.name} {stage.score}% {stage.votes[0]} {" "} {stage.votes[1]}{" "} {stage.votes[2]} ) })} ) } const MapVotingHistoryPage: React.FC = () => { const { data, error, loading } = useQuery(PLUS_MAPLISTS) const [index, setIndex] = useState(0) if (error) return if (loading || !data) return const maplistObject = data.plusMaplists[index] return ( <> Plus Server Map Voting History | sendou.ink setIndex(index - 1)} /> {maplistObject.name} setIndex(index + 1)} /> ) } export default MapVotingHistoryPage