-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #284 from moonstream-to/updates
Updates
- Loading branch information
Showing
18 changed files
with
335 additions
and
128 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
.container { | ||
display: flex; | ||
width: 141.518px; | ||
min-height: 30px; | ||
padding: 5px 20px; | ||
justify-content: center; | ||
align-items: center; | ||
gap: 10px; | ||
|
||
border: 1px solid #262019; | ||
background: linear-gradient(0deg, #884F43 0%, #884F43 100%), #328449; | ||
color: #FFF; | ||
text-align: center; | ||
font-family: Bangers, cursive; | ||
font-size: 18px; | ||
font-style: normal; | ||
font-weight: 400; | ||
line-height: 100%; /* 18px */ | ||
letter-spacing: 0.9px; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
import { useMutation, useQuery } from "react-query"; | ||
import { Spinner } from "@chakra-ui/react"; | ||
|
||
import styles from "./RematchButton.module.css"; | ||
import { AtBatStatus, Token } from "../../types"; | ||
import { getCharacterSessions, isCampaignToken } from "../campaign/teams"; | ||
import { JoinSessionParams } from "../../hooks/useJoinSession"; | ||
import { playSound } from "../../utils/notifications"; | ||
import { sendReport } from "../../utils/humbug"; | ||
import { joinSessionFullcountPlayer } from "../../tokenInterfaces/FullcountPlayerAPI"; | ||
import { mutationOptions } from "../../hooks/FCPlayerAPIOptions"; | ||
import useMoonToast from "../../hooks/useMoonToast"; | ||
|
||
const RematchButton = ({ | ||
atBat, | ||
selectedToken, | ||
onSuccess, | ||
}: { | ||
atBat: AtBatStatus; | ||
selectedToken: Token; | ||
onSuccess: (sessionID: number) => void; | ||
}) => { | ||
const toast = useMoonToast(); | ||
const joinSession = useMutation( | ||
async ({ sessionID, token, inviteCode }: JoinSessionParams): Promise<unknown> => { | ||
return joinSessionFullcountPlayer({ token, sessionID, inviteCode }); | ||
}, | ||
{ | ||
...mutationOptions, | ||
onSuccess: (_, variables) => { | ||
onSuccess(variables.sessionID); | ||
}, | ||
onError: (e: Error) => { | ||
toast("Rematch request failed" + e?.message, "error"); | ||
sendReport("Error toast", { error: e }, ["type:error_toast"]); | ||
}, | ||
}, | ||
); | ||
|
||
const availableBots = useQuery( | ||
["availableBots", atBat.pitcher, atBat.batter], | ||
() => { | ||
if (atBat.batter && isCampaignToken(atBat.batter?.address, atBat.batter.id)) { | ||
return getCharacterSessions(atBat.batter); | ||
} | ||
if (atBat.pitcher && isCampaignToken(atBat.pitcher.address, atBat.pitcher.id)) { | ||
return getCharacterSessions(atBat.pitcher); | ||
} | ||
return undefined; | ||
}, | ||
{ | ||
refetchInterval: 3000, | ||
}, | ||
); | ||
|
||
const handleClick = () => { | ||
playSound("click"); | ||
sendReport("Rematch", {}, ["type:click", "click:rematch"]); | ||
if (availableBots.data && availableBots.data[0]) { | ||
joinSession.mutate({ | ||
token: selectedToken, | ||
sessionID: availableBots.data[0], | ||
inviteCode: "", | ||
}); | ||
} | ||
}; | ||
|
||
return ( | ||
<> | ||
{availableBots.data && availableBots.data.length > 0 && ( | ||
<button className={styles.container} onClick={handleClick} disabled={joinSession.isLoading}> | ||
{joinSession.isLoading ? <Spinner h={4} w={4} /> : "REMATCH"} | ||
</button> | ||
)} | ||
</> | ||
); | ||
}; | ||
|
||
export default RematchButton; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.