Skip to content

Commit

Permalink
web: use helper instead of subscribing to event manually
Browse files Browse the repository at this point in the history
  • Loading branch information
tulir committed Oct 6, 2024
1 parent 758e3e9 commit 3a68ec7
Showing 1 changed file with 4 additions and 9 deletions.
13 changes: 4 additions & 9 deletions web/src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,32 +13,27 @@
//
// 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/>.
import { useEffect, useMemo, useState } from "react"
import { useEffect, useMemo } from "react"
import { ScaleLoader } from "react-spinners"
import { useEventAsState } from "./util/eventdispatcher.ts"
import Client from "./api/client.ts"
import WSClient from "./api/wsclient.ts"
import { ClientState } from "./api/types/hievents.ts"
import { ConnectionEvent } from "./api/rpc.ts"
import { LoginScreen, VerificationScreen } from "./ui/login"
import MainScreen from "./ui/MainScreen.tsx"

function App() {
const [connState, setConnState] = useState<ConnectionEvent>()
const [clientState, setClientState] = useState<ClientState>()
const client = useMemo(() => new Client(new WSClient("/_gomuks/websocket")), [])
const connState = useEventAsState(client.rpc.connect)
const clientState = useEventAsState(client.state)
useEffect(() => {
((window as unknown) as { client: Client }).client = client

// TODO remove this debug log
const unlistenDebug = client.rpc.event.listen(ev => {
console.debug("Received event:", ev)
})
const unlistenConnect = client.rpc.connect.listen(setConnState)
const unlistenState = client.state.listen(setClientState)
client.rpc.start()
return () => {
unlistenConnect()
unlistenState()
unlistenDebug()
client.rpc.stop()
}
Expand Down

0 comments on commit 3a68ec7

Please sign in to comment.