diff --git a/frontend-react/package-lock.json b/frontend-react/package-lock.json index 7da7c2043..7f8b1dddd 100644 --- a/frontend-react/package-lock.json +++ b/frontend-react/package-lock.json @@ -2383,9 +2383,9 @@ "integrity": "sha512-ce5d3q03Ex0sy4R14722Rmt6MT07Ua+k4FwDfdcToYJcMKNtRVQvJ6JCAPdAmAnbRb6CsX6aYb9m96NGod9uTw==" }, "@types/reach__router": { - "version": "1.3.2", - "resolved": "https://registry.npmjs.org/@types/reach__router/-/reach__router-1.3.2.tgz", - "integrity": "sha512-OTPBURw7aF3q+ejjcBQKjEFsiv4hr0oEFfIgUfdaSQfvnNSSu3I/Cfy1JvoDaTnbt6ZByiFWC5Y9AMhf4x0WOA==", + "version": "1.3.3", + "resolved": "https://registry.npmjs.org/@types/reach__router/-/reach__router-1.3.3.tgz", + "integrity": "sha512-HTHMGJLdH3czgPP1nHF82y+TYLV1KSh1qYeezqHNDNuESBy55ij1LCn8jDYFeKCuAxm0gd9J25zyYy7mhOcgOw==", "requires": { "@types/history": "*", "@types/react": "*" diff --git a/frontend-react/package.json b/frontend-react/package.json index 1e9615a7e..dd70bcda3 100644 --- a/frontend-react/package.json +++ b/frontend-react/package.json @@ -14,7 +14,7 @@ "@testing-library/react": "^10.0.2", "@testing-library/user-event": "^10.0.1", "@types/jest": "^25.1.4", - "@types/reach__router": "^1.3.2", + "@types/reach__router": "^1.3.3", "@types/react": "^16.9.31", "@types/react-color": "^3.0.1", "@types/react-datepicker": "^2.11.0", diff --git a/frontend-react/src/components/plusdraftcup/DraftCupDetails.tsx b/frontend-react/src/components/plusdraftcup/DraftCupDetails.tsx index 7cb1476ac..8529e3ae7 100644 --- a/frontend-react/src/components/plusdraftcup/DraftCupDetails.tsx +++ b/frontend-react/src/components/plusdraftcup/DraftCupDetails.tsx @@ -1,4 +1,4 @@ -import React, { useContext, useState } from "react" +import React, { useContext, useState, useEffect } from "react" import { RouteComponentProps, Link } from "@reach/router" import { SEARCH_FOR_DRAFT_CUP, @@ -51,6 +51,7 @@ interface CollapsedMapCardProps { losers: DetailedTeamInfo }[] expand: () => void + loading: boolean } const abilityMap = (ability: Ability, index: number) => { @@ -176,14 +177,10 @@ const DetailedMapCard: React.FC = ({ {player.main_abilities.map(abilityMap)} {player.sub_abilities.flat().map((ability, index) => ( - <> + {(index === 3 || index === 6) && } - - + + ))} @@ -240,6 +237,7 @@ const DetailedMapCard: React.FC = ({ const CollapsedMapCard: React.FC = ({ expand, mapDetails, + loading, }) => { const { grayWithShade } = useContext(MyThemeContext) const winnerTeamName = mapDetails[0].winners.team_name @@ -288,7 +286,9 @@ const CollapsedMapCard: React.FC = ({ ))} - + ) } @@ -303,6 +303,12 @@ const DraftCupDetails: React.FC = ({ SearchForDraftCupVars >(SEARCH_FOR_DRAFT_CUP, { variables: { name: "+2 Draft Cup March 2020" } }) const [expanded, setExpanded] = useState(null) + const [loadingSet, setLoadingSet] = useState(null) + + useEffect(() => { + if (!loadingSet) return + setExpanded(loadingSet) + }, [loadingSet]) if (loading) return if (error) return @@ -354,7 +360,8 @@ const DraftCupDetails: React.FC = ({ )) ) : ( setExpanded(match.round_number)} + expand={() => setLoadingSet(match.round_number)} + loading={loadingSet === match.round_number} mapDetails={match.map_details} /> )} diff --git a/graphql-schemas/detailedtournament.js b/graphql-schemas/detailedtournament.js index afeef7372..6b11c1bb0 100644 --- a/graphql-schemas/detailedtournament.js +++ b/graphql-schemas/detailedtournament.js @@ -25,6 +25,10 @@ const typeDef = gql` matches: [DetailedMatchInput!]! lanistaToken: String! ): Boolean! + replaceDraftLeaderboard( + plus_server: PlusServer! + players: [TournamentPlayerInput!]! + ): Boolean! } type DraftCupCollection { @@ -142,6 +146,13 @@ const typeDef = gql` score: Int! } + input TournamentPlayerInput { + discord_id: String! + first: Int! + second: Int! + third: Int! + } + type PlayerStat { discord_id: String! "Weapon of the stat. ALL if stat is all weapon stats summed up" @@ -340,6 +351,24 @@ const resolvers = { await generateStats(eventType) return true }, + replaceDraftLeaderboard: async (root, args, ctx) => { + if (!ctx.user) throw new AuthenticationError("Not logged in.") + if (ctx.user.discord_id !== process.env.ADMIN_ID) + throw new AuthenticationError("not admin") + + const players = args.players.sort( + (a, b) => + b.first * 4 + + b.second * 2 + + b.third - + (a.first * 4 + a.second * 2 + a.third) + ) + + const type = `DRAFT${args.plus_server}` + await Leaderboard.updateOne({ type }, { type, players }, { upsert: true }) + + return true + }, }, }