mirror of
https://github.com/Sendouc/sendou.ink.git
synced 2026-08-28 14:18:04 -05:00
replace leaderboard mutation
This commit is contained in:
6
frontend-react/package-lock.json
generated
6
frontend-react/package-lock.json
generated
@@ -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": "*"
|
||||
|
||||
@@ -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",
|
||||
|
||||
@@ -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<DetailedMapCardProps> = ({
|
||||
{player.main_abilities.map(abilityMap)}
|
||||
<Flex gridArea="6 / 1 / 7 / 4" alignItems="center">
|
||||
{player.sub_abilities.flat().map((ability, index) => (
|
||||
<>
|
||||
<React.Fragment key={index}>
|
||||
{(index === 3 || index === 6) && <Box w="5px" />}
|
||||
<AbilityIcon
|
||||
key={index}
|
||||
ability={ability}
|
||||
size="SUBTINY"
|
||||
/>
|
||||
</>
|
||||
<AbilityIcon ability={ability} size="SUBTINY" />
|
||||
</React.Fragment>
|
||||
))}
|
||||
</Flex>
|
||||
<Flex gridArea="7 / 1 / 8 / 2" justifyContent="center">
|
||||
@@ -240,6 +237,7 @@ const DetailedMapCard: React.FC<DetailedMapCardProps> = ({
|
||||
const CollapsedMapCard: React.FC<CollapsedMapCardProps> = ({
|
||||
expand,
|
||||
mapDetails,
|
||||
loading,
|
||||
}) => {
|
||||
const { grayWithShade } = useContext(MyThemeContext)
|
||||
const winnerTeamName = mapDetails[0].winners.team_name
|
||||
@@ -288,7 +286,9 @@ const CollapsedMapCard: React.FC<CollapsedMapCardProps> = ({
|
||||
</Box>
|
||||
</React.Fragment>
|
||||
))}
|
||||
<Button onClick={() => expand()}>Expand</Button>
|
||||
<Button onClick={() => expand()} loading={loading}>
|
||||
Expand
|
||||
</Button>
|
||||
</Flex>
|
||||
)
|
||||
}
|
||||
@@ -303,6 +303,12 @@ const DraftCupDetails: React.FC<RouteComponentProps & DraftCupDetailsProps> = ({
|
||||
SearchForDraftCupVars
|
||||
>(SEARCH_FOR_DRAFT_CUP, { variables: { name: "+2 Draft Cup March 2020" } })
|
||||
const [expanded, setExpanded] = useState<number | null>(null)
|
||||
const [loadingSet, setLoadingSet] = useState<number | null>(null)
|
||||
|
||||
useEffect(() => {
|
||||
if (!loadingSet) return
|
||||
setExpanded(loadingSet)
|
||||
}, [loadingSet])
|
||||
|
||||
if (loading) return <Loading />
|
||||
if (error) return <Error errorMessage={error.message} />
|
||||
@@ -354,7 +360,8 @@ const DraftCupDetails: React.FC<RouteComponentProps & DraftCupDetailsProps> = ({
|
||||
))
|
||||
) : (
|
||||
<CollapsedMapCard
|
||||
expand={() => setExpanded(match.round_number)}
|
||||
expand={() => setLoadingSet(match.round_number)}
|
||||
loading={loadingSet === match.round_number}
|
||||
mapDetails={match.map_details}
|
||||
/>
|
||||
)}
|
||||
|
||||
@@ -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
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user