From 5768b2202b58587500eca301c263b50287df3ed0 Mon Sep 17 00:00:00 2001 From: Tulir Asokan Date: Fri, 25 Oct 2024 19:02:02 +0300 Subject: [PATCH] web/main: set switchRoom in effect --- web/src/ui/MainScreen.tsx | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/web/src/ui/MainScreen.tsx b/web/src/ui/MainScreen.tsx index d5743d3..50ce52f 100644 --- a/web/src/ui/MainScreen.tsx +++ b/web/src/ui/MainScreen.tsx @@ -13,7 +13,7 @@ // // You should have received a copy of the GNU Affero General Public License // along with this program. If not, see . -import { use, useCallback, useState } from "react" +import { use, useCallback, useLayoutEffect, useState } from "react" import type { RoomID } from "@/api/types" import { ClientContext } from "./ClientContext.ts" import RoomView from "./RoomView.tsx" @@ -25,13 +25,16 @@ const MainScreen = () => { const client = use(ClientContext)! const activeRoom = activeRoomID && client.store.rooms.get(activeRoomID) const setActiveRoom = useCallback((roomID: RoomID) => { + console.log("Switching to room", roomID) setActiveRoomID(roomID) if (client.store.rooms.get(roomID)?.stateLoaded === false) { client.loadRoomState(roomID) .catch(err => console.error("Failed to load room state", err)) } }, [client]) - client.store.switchRoom = setActiveRoom + useLayoutEffect(() => { + client.store.switchRoom = setActiveRoom + }, [client, setActiveRoom]) const clearActiveRoom = useCallback(() => setActiveRoomID(null), []) return