From d7b253c74bc6973e6cf3050fdb727b53aeca3177 Mon Sep 17 00:00:00 2001 From: Grant Date: Tue, 4 Jun 2024 15:09:46 -0600 Subject: [PATCH] ClientConfig is not always available anymore --- .../src/components/Chat/OpenChatButton.tsx | 8 +++-- .../src/components/Profile/UserCard.tsx | 34 ++++++++++--------- packages/client/src/contexts/ChatContext.tsx | 15 ++++++++ packages/lib/src/net.ts | 2 +- 4 files changed, 39 insertions(+), 20 deletions(-) diff --git a/packages/client/src/components/Chat/OpenChatButton.tsx b/packages/client/src/components/Chat/OpenChatButton.tsx index 057d060..fda27e1 100644 --- a/packages/client/src/components/Chat/OpenChatButton.tsx +++ b/packages/client/src/components/Chat/OpenChatButton.tsx @@ -13,9 +13,11 @@ const OpenChatButton = () => { color="danger" size="sm" > - + {config?.chat?.element_host && ( + + )} ); }; diff --git a/packages/client/src/components/Profile/UserCard.tsx b/packages/client/src/components/Profile/UserCard.tsx index 51a525d..d580f9e 100644 --- a/packages/client/src/components/Profile/UserCard.tsx +++ b/packages/client/src/components/Profile/UserCard.tsx @@ -81,22 +81,24 @@ export const UserCard = ({ user }: { user: IUser }) => { {user?.sub}
- + {config && ( + + )}
diff --git a/packages/client/src/contexts/ChatContext.tsx b/packages/client/src/contexts/ChatContext.tsx index e7302a0..c2619a3 100644 --- a/packages/client/src/contexts/ChatContext.tsx +++ b/packages/client/src/contexts/ChatContext.tsx @@ -33,6 +33,11 @@ export const ChatContext = ({ children }: PropsWithChildren) => { const [notifs, setNotifs] = useState(0); const doLogin = () => { + if (!config) { + console.warn("[ChatContext#doLogin] has no config instance"); + return; + } + const redirectUrl = window.location.protocol + "//" + window.location.host + "/chat_callback"; @@ -46,6 +51,11 @@ export const ChatContext = ({ children }: PropsWithChildren) => { }; const doLogout = async () => { + if (!config) { + console.warn("[ChatContext#doLogout] has no config instance"); + return; + } + await fetch( `https://${config.chat.matrix_homeserver}/_matrix/client/v3/logout`, { @@ -97,6 +107,11 @@ export const ChatContext = ({ children }: PropsWithChildren) => { }; const checkForNotifs = async () => { + if (!config) { + console.warn("[ChatContext#checkForNotifs] no config instance"); + return; + } + const accessToken = localStorage.getItem("matrix.access_token"); if (!accessToken) return; diff --git a/packages/lib/src/net.ts b/packages/lib/src/net.ts index fbf50b2..0774b63 100644 --- a/packages/lib/src/net.ts +++ b/packages/lib/src/net.ts @@ -30,7 +30,7 @@ export interface ClientToServerEvents { // TODO: move to client/{...}/AppContext.tsx export interface IAppContext { - config: ClientConfig; + config?: ClientConfig; user?: AuthSession; canvasPosition?: ICanvasPosition; setCanvasPosition: (v: ICanvasPosition) => void;