From abf9022fd9ac54e0555fd890853fce356df1b2c1 Mon Sep 17 00:00:00 2001 From: Timo K Date: Tue, 9 Jun 2026 17:17:25 +0200 Subject: [PATCH] Add primary button icon configuration and set it left arrow in lobby --- src/AppBar.tsx | 41 ++++++++++++++++++++++++++++++++++------- src/room/LobbyView.tsx | 3 +++ 2 files changed, 37 insertions(+), 7 deletions(-) diff --git a/src/AppBar.tsx b/src/AppBar.tsx index 9939f9505..aac28d551 100644 --- a/src/AppBar.tsx +++ b/src/AppBar.tsx @@ -6,15 +6,16 @@ Please see LICENSE in the repository root for full details. */ import { - createContext, - type FC, - type MouseEvent, - type ReactNode, use, useCallback, useEffect, useMemo, useState, + createContext, + type ComponentType, + type FC, + type MouseEvent, + type ReactNode, } from "react"; import { Heading, IconButton, Tooltip } from "@vector-im/compound-web"; import { CollapseIcon } from "@vector-im/compound-design-tokens/assets/web/icons"; @@ -28,6 +29,9 @@ import styles from "./AppBar.module.css"; interface AppBarContext { setTitle: (value: string) => void; setSecondaryButton: (value: ReactNode) => void; + setPrimaryButtonIcon: ( + value: ComponentType> | null, + ) => void; setHidden: (value: boolean) => void; } @@ -53,9 +57,18 @@ export const AppBar: FC = ({ children }) => { const [secondaryButton, setSecondaryButton] = useState( null, ); + const [PrimaryButtonIcon, setPrimaryButtonIcon] = useState + > | null>(null); + const context = useMemo( - () => ({ setTitle, setSecondaryButton, setHidden }), - [setTitle, setHidden, setSecondaryButton], + () => ({ + setTitle, + setSecondaryButton, + setHidden, + setPrimaryButtonIcon, + }), + [setTitle, setHidden, setSecondaryButton, setPrimaryButtonIcon], ); return ( @@ -72,7 +85,7 @@ export const AppBar: FC = ({ children }) => { - + {PrimaryButtonIcon ? : } @@ -107,6 +120,20 @@ export function useAppBarTitle(title: string): void { }, [title, setTitle]); } +/** + * React hook which sets the title to be shown in the app bar, if present. It is + * an error to call this hook from multiple sites in the same component tree. + */ +export function useAppBarPrimaryButtonIcon(icon: typeof CollapseIcon): void { + const setIcon = use(AppBarContext)?.setPrimaryButtonIcon; + useEffect(() => { + if (setIcon !== undefined) { + setIcon(icon); + return (): void => setIcon(null); + } + }, [setIcon, icon]); +} + /** * React hook which sets the title to be shown in the app bar, if present. It is * an error to call this hook from multiple sites in the same component tree. diff --git a/src/room/LobbyView.tsx b/src/room/LobbyView.tsx index cec9f6acd..d1f1a1346 100644 --- a/src/room/LobbyView.tsx +++ b/src/room/LobbyView.tsx @@ -26,6 +26,7 @@ import { } from "livekit-client"; import { useObservableEagerState } from "observable-hooks"; import { useNavigate } from "react-router-dom"; +import { ArrowLeftIcon } from "@vector-im/compound-design-tokens/assets/web/icons"; import inCallStyles from "./InCallView.module.css"; import styles from "./LobbyView.module.css"; @@ -51,6 +52,7 @@ import { CallFooter, type FooterSnapshot } from "../components/CallFooter"; import { useCallViewKeyboardShortcuts } from "../useCallViewKeyboardShortcuts"; import { createLobbyFooterViewModel } from "../components/CallFooterViewModel"; import { type ViewModel } from "../state/ViewModel"; +import { useAppBarPrimaryButtonIcon } from "../AppBar"; interface Props { client: MatrixClient; @@ -87,6 +89,7 @@ export const LobbyView: FC = ({ const { t } = useTranslation(); usePageTitle(matrixInfo.roomName); + useAppBarPrimaryButtonIcon(ArrowLeftIcon); const audioEnabled = useBehavior(muteStates.audio.enabled$); const videoEnabled = useBehavior(muteStates.video.enabled$); const toggleAudio = useBehavior(muteStates.audio.toggle$);