generated from yandeu/phaser-project-template
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: implement chatting in multiplayer, add hooks which autodisconne…
…cts on connection lost, add error modal; refactor: App hooks
- Loading branch information
Showing
29 changed files
with
199 additions
and
145 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
{ | ||
"exportall.config.relExclusion": ["/src/ui/components/ErrorModal"] | ||
} |
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,38 @@ | ||
import React, { useEffect } from "react"; | ||
import { Modal, Space, Title } from "@mantine/core"; | ||
import { useDisclosure } from "@mantine/hooks"; | ||
|
||
import { Errors } from "./components"; | ||
|
||
export const ErrorModal = ({ errors, clearErrors }) => { | ||
const [opened, { close, open }] = useDisclosure(false); | ||
|
||
useEffect(() => { | ||
if (errors.length) { | ||
open(); | ||
} | ||
}, [errors]); | ||
|
||
const handleClose = () => { | ||
close(); | ||
clearErrors(); | ||
}; | ||
|
||
return ( | ||
<Modal.Root opened={opened} onClose={handleClose} centered size="auto"> | ||
<Modal.Overlay /> | ||
<Modal.Content> | ||
<Modal.Header py={0}> | ||
<Title c="red" order={2}> | ||
Error | ||
</Title> | ||
<Modal.CloseButton /> | ||
</Modal.Header> | ||
<Modal.Body> | ||
<Space h="md" /> | ||
<Errors errors={errors} /> | ||
</Modal.Body> | ||
</Modal.Content> | ||
</Modal.Root> | ||
); | ||
}; |
2 changes: 1 addition & 1 deletion
2
...rofileModal/components/NonFieldErrors.tsx → ...mponents/ErrorModal/components/Errors.tsx
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 @@ | ||
export * from "./Errors"; |
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,2 @@ | ||
export * from "./components"; | ||
export * from "./ErrorModal"; |
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 |
---|---|---|
@@ -1 +1,2 @@ | ||
export * from "./ToggleButton"; | ||
export * from "./ErrorModal"; |
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,2 @@ | ||
export * from "./useGame"; | ||
export * from "./useMultiplayerDisconnect"; |
File renamed without changes.
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 @@ | ||
export * from "./useMultiplayerDisconnect"; |
31 changes: 31 additions & 0 deletions
31
client/src/ui/hooks/useGame/useMultiplayerDisconnect/useMultiplayerDisconnect.ts
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,31 @@ | ||
import { useDidUpdate } from "@mantine/hooks"; | ||
|
||
import { useGame } from "../"; | ||
import { useState } from "react"; | ||
|
||
export const useMultiplayerDisconnect = () => { | ||
const [connectionError, setConnectionError] = useState<string | null>(null); | ||
const { | ||
gameManager, | ||
loadMainMenu, | ||
computed: { isLoaded }, | ||
} = useGame(); | ||
|
||
useDidUpdate(() => { | ||
if (isLoaded) { | ||
console.log("LOADED CHANGED"); | ||
const { channel } = gameManager.game; | ||
channel.onDisconnect(() => { | ||
loadMainMenu(); | ||
console.log("SET ERROR"); | ||
setConnectionError("Connection to server lost"); | ||
}); | ||
} | ||
}, [isLoaded]); | ||
|
||
const clearConnectionError = () => { | ||
setConnectionError(null); | ||
}; | ||
|
||
return { connectionError, clearConnectionError }; | ||
}; |
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 @@ | ||
export * from "./useSyncSettingsToSession"; |
20 changes: 20 additions & 0 deletions
20
client/src/ui/hooks/useSettings/hooks/useSyncSettingsToSession.ts
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 @@ | ||
import { useEffect } from "react"; | ||
|
||
import { useSettings, settingsStorageKey } from "../"; | ||
import { setSessionStorage } from "../services/localStorage"; | ||
|
||
const syncSettingsToSession = () => { | ||
const unsub = useSettings.subscribe( | ||
(state) => state.settings, | ||
(state) => setSessionStorage(settingsStorageKey, state) | ||
); | ||
|
||
return unsub; | ||
}; | ||
|
||
export const useSyncSettingsToSession = () => { | ||
return useEffect(() => { | ||
const unsub = syncSettingsToSession(); | ||
return unsub; | ||
}, []); | ||
}; |
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,3 @@ | ||
export * from "./hooks"; | ||
export * from "./services"; | ||
export * from "./useSettings"; |
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 @@ | ||
export * from "./localStorage"; |
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,23 @@ | ||
export const setSessionStorage = (key, value) => { | ||
sessionStorage.setItem(key, serializeJSON(value)); | ||
}; | ||
|
||
export const getSessionStorage = (key) => { | ||
return deserializeJSON(sessionStorage.getItem(key) ?? "{}"); | ||
}; | ||
|
||
export const serializeJSON = (value: any) => { | ||
try { | ||
return JSON.stringify(value); | ||
} catch (error) { | ||
throw new Error("Failed to serialize the value"); | ||
} | ||
}; | ||
|
||
export const deserializeJSON = (value: string) => { | ||
try { | ||
return JSON.parse(value); | ||
} catch { | ||
return value; | ||
} | ||
}; |
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
1 change: 0 additions & 1 deletion
1
client/src/ui/scenes/BottomRight/scenes/ProfileModal/components/index.ts
This file was deleted.
Oops, something went wrong.
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 |
---|---|---|
|
@@ -3,8 +3,7 @@ import { useDidUpdate } from "@mantine/hooks"; | |
import { useForm } from "@mantine/form"; | ||
import { TextInput, PasswordInput, Space, Stack, Anchor } from "@mantine/core"; | ||
|
||
import { Button } from "~/ui/components"; | ||
import { NonFieldErrors } from "../../components"; | ||
import { Button, Errors } from "~/ui/components"; | ||
import { useLoginMutation } from "./hooks"; | ||
|
||
export const Login = ({ setShowLogIn, initEmailPass = {}, setInitEmailPass }) => { | ||
|
@@ -32,7 +31,7 @@ export const Login = ({ setShowLogIn, initEmailPass = {}, setInitEmailPass }) => | |
return ( | ||
<form onSubmit={form.onSubmit(handleLogin)}> | ||
<Stack> | ||
<NonFieldErrors errors={nonFieldErrors} /> | ||
<Errors errors={nonFieldErrors} /> | ||
<TextInput | ||
placeholder="[email protected]" | ||
label="Email" | ||
|
Oops, something went wrong.