From da3de75af75f144a17f045a933bda14fe677b86c Mon Sep 17 00:00:00 2001 From: Sendou <38327916+Sendouc@users.noreply.github.com> Date: Sat, 6 Jun 2020 20:57:09 +0300 Subject: [PATCH] plus maplist new/gone notifs --- .../src/components/plus/Maplist.tsx | 73 ++++++++++++++++--- .../src/components/plus/PlusPage.tsx | 6 +- 2 files changed, 69 insertions(+), 10 deletions(-) diff --git a/frontend-react/src/components/plus/Maplist.tsx b/frontend-react/src/components/plus/Maplist.tsx index 62a1fd47b..08b6cf615 100644 --- a/frontend-react/src/components/plus/Maplist.tsx +++ b/frontend-react/src/components/plus/Maplist.tsx @@ -1,5 +1,5 @@ import React, { useContext } from "react" -import { Heading, Flex, Box, Avatar, Icon } from "@chakra-ui/core" +import { Heading, Flex, Box, Avatar, Icon, AvatarBadge } from "@chakra-ui/core" import { mapIcons } from "../../assets/imageImports" import MyThemeContext from "../../themeContext" import { Stage } from "../../types" @@ -7,9 +7,14 @@ import { Stage } from "../../types" interface MaplistCardProps { modeShort: string stages: Stage[] + newMaps: Stage[] } -const MaplistCard: React.FC = ({ modeShort, stages }) => { +const MaplistCard: React.FC = ({ + modeShort, + stages, + newMaps, +}) => { const { themeColorHex, themeColorWithShade } = useContext(MyThemeContext) return ( = ({ modeShort, stages }) => { - {stages.map(stage => { + {stages.map((stage) => { return ( = ({ modeShort, stages }) => { mx="0.2em" title={stage} textAlign="center" - /> + > + {newMaps.includes(stage) && ( + + )} + ) })} @@ -47,30 +56,76 @@ const MaplistCard: React.FC = ({ modeShort, stages }) => { interface MaplistProps { name: string sz: string[] + pastSz: string[] tc: string[] + pastTc: string[] rm: string[] + pastRm: string[] cb: string[] + pastCb: string[] voterCount: number } const Maplist: React.FC = ({ name, sz, + pastSz, tc, + pastTc, rm, + pastRm, cb, + pastCb, voterCount, }) => { + const { grayWithShade, themeColorWithShade } = useContext(MyThemeContext) + + const lastMonth = [pastSz, pastTc, pastRm, pastCb] + const thisMonth = [sz, tc, rm, cb] + const toAdd = ["SZ", "TC", "RM", "CB"] + + let goneMaps: Stage[] = [] + + lastMonth.forEach((arr, index) => { + const append = toAdd[index] + const newOfTheMode = arr + .filter((map) => !thisMonth[index].includes(map)) + .map((map) => `${map} (${append})`) + + goneMaps = [...goneMaps, ...newOfTheMode] + }) + + const newMaps: Stage[][] = [] + + thisMonth.forEach((arr, index) => { + const newOfTheMode = arr.filter((map) => !lastMonth[index].includes(map)) + + newMaps.push(newOfTheMode) + }) + return ( <> {name} maps - Based on {voterCount} votes + Based on {voterCount} votes - - - - + + + + + {goneMaps.length > 0 && ( + + Maps gone since last month: {goneMaps.join(", ")}. New maps marked + with{" "} + + + )} ) } diff --git a/frontend-react/src/components/plus/PlusPage.tsx b/frontend-react/src/components/plus/PlusPage.tsx index 259098f61..c6b18ef92 100644 --- a/frontend-react/src/components/plus/PlusPage.tsx +++ b/frontend-react/src/components/plus/PlusPage.tsx @@ -6,7 +6,6 @@ import Loading from "../common/Loading" import Error from "../common/Error" import { PLUS_INFO, PlusInfoData } from "../../graphql/queries/plusInfo" import { USER } from "../../graphql/queries/user" -//import Voting from "./Voting" import { Redirect, RouteComponentProps, Link } from "@reach/router" import PageHeader from "../common/PageHeader" import { FaHistory, FaVoteYea, FaMapMarkedAlt } from "react-icons/fa" @@ -42,6 +41,7 @@ const PlusPage: React.FC = () => { if (!data.plusInfo) return const maplist = maplistData.plusMaplists[0] + const lastMonthsMaplist = maplistData.plusMaplists[1] const plusInfo = data.plusInfo return ( @@ -85,9 +85,13 @@ const PlusPage: React.FC = () => {