ClientConfig is not always available anymore

This commit is contained in:
Grant 2024-06-04 15:09:46 -06:00
parent 771ddd4d39
commit d7b253c74b
4 changed files with 39 additions and 20 deletions

View File

@ -13,9 +13,11 @@ const OpenChatButton = () => {
color="danger"
size="sm"
>
<Button as={Link} href={config.chat.element_host} target="_blank">
Chat
</Button>
{config?.chat?.element_host && (
<Button as={Link} href={config.chat.element_host} target="_blank">
Chat
</Button>
)}
</Badge>
);
};

View File

@ -81,22 +81,24 @@ export const UserCard = ({ user }: { user: IUser }) => {
<span className="text-sm">{user?.sub}</span>
</div>
<div>
<Button
isIconOnly
as={Link}
href={getMatrixLink(user, config)}
target="_blank"
onClick={handleMatrixClick}
>
{messageStatus === "loading" ? (
<Spinner />
) : (
<FontAwesomeIcon
icon={messageStatus === "error" ? faWarning : faMessage}
color="inherit"
/>
)}
</Button>
{config && (
<Button
isIconOnly
as={Link}
href={getMatrixLink(user, config)}
target="_blank"
onClick={handleMatrixClick}
>
{messageStatus === "loading" ? (
<Spinner />
) : (
<FontAwesomeIcon
icon={messageStatus === "error" ? faWarning : faMessage}
color="inherit"
/>
)}
</Button>
)}
</div>
</div>
<Button size="sm">View Profile</Button>

View File

@ -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;

View File

@ -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;