mirror of
https://github.com/tulir/gomuks.git
synced 2025-04-20 10:33:41 -05:00
Revert "web/app: initialize RPC client outside React"
This reverts commit 704ca2ca42
.
It doesn't play nicely with vite's hot reloads
This commit is contained in:
parent
9b73e755e8
commit
cffae7a3c8
1 changed files with 4 additions and 5 deletions
|
@ -13,7 +13,7 @@
|
||||||
//
|
//
|
||||||
// You should have received a copy of the GNU Affero General Public License
|
// You should have received a copy of the GNU Affero General Public License
|
||||||
// along with this program. If not, see <https://www.gnu.org/licenses/>.
|
// along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
import { useEffect } from "react"
|
import { useEffect, useMemo } from "react"
|
||||||
import { ScaleLoader } from "react-spinners"
|
import { ScaleLoader } from "react-spinners"
|
||||||
import Client from "./api/client.ts"
|
import Client from "./api/client.ts"
|
||||||
import WSClient from "./api/wsclient.ts"
|
import WSClient from "./api/wsclient.ts"
|
||||||
|
@ -24,10 +24,9 @@ import { LightboxWrapper } from "./ui/modal/Lightbox.tsx"
|
||||||
import { ModalWrapper } from "./ui/modal/Modal.tsx"
|
import { ModalWrapper } from "./ui/modal/Modal.tsx"
|
||||||
import { useEventAsState } from "./util/eventdispatcher.ts"
|
import { useEventAsState } from "./util/eventdispatcher.ts"
|
||||||
|
|
||||||
const client = new Client(new WSClient("_gomuks/websocket"))
|
|
||||||
window.client = client
|
|
||||||
|
|
||||||
function App() {
|
function App() {
|
||||||
|
const client = useMemo(() => new Client(new WSClient("_gomuks/websocket")), [])
|
||||||
|
window.client = client
|
||||||
const connState = useEventAsState(client.rpc.connect)
|
const connState = useEventAsState(client.rpc.connect)
|
||||||
const clientState = useEventAsState(client.state)
|
const clientState = useEventAsState(client.state)
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
|
@ -35,7 +34,7 @@ function App() {
|
||||||
.then(permission => console.log("Notification permission:", permission))
|
.then(permission => console.log("Notification permission:", permission))
|
||||||
client.rpc.start()
|
client.rpc.start()
|
||||||
return () => client.rpc.stop()
|
return () => client.rpc.stop()
|
||||||
}, [])
|
}, [client])
|
||||||
|
|
||||||
if (connState?.error) {
|
if (connState?.error) {
|
||||||
return <div>
|
return <div>
|
||||||
|
|
Loading…
Add table
Reference in a new issue