-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Implement leave game menu option
Closes #16
- Loading branch information
Showing
3 changed files
with
67 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
import { useIntl } from "react-intl"; | ||
import { useLocation } from "wouter"; | ||
import { useSnackbar } from "notistack"; | ||
import useCharacter from "./useCharacter"; | ||
import useGameId from "./useGameId"; | ||
|
||
/** | ||
* A React hook to leave the game | ||
* | ||
* @returns A function to call in order to leave the game | ||
*/ | ||
const useLeaveGame = () => { | ||
const [, , deleteCharacter] = useCharacter(); | ||
const [, , deleteGameId] = useGameId(); | ||
const [, setLocation] = useLocation(); | ||
const { enqueueSnackbar } = useSnackbar(); | ||
const intl = useIntl(); | ||
|
||
return () => { | ||
deleteCharacter(); | ||
deleteGameId(); | ||
enqueueSnackbar( | ||
intl.formatMessage({ | ||
defaultMessage: "Spiel erfolgreich verlassen!", | ||
description: "success snackbar on leave game", | ||
}), | ||
{ variant: "success" } | ||
); | ||
setLocation("/"); | ||
}; | ||
}; | ||
|
||
export default useLeaveGame; |