reuse exisng mute buttons (fixes most playwright issues)

This commit is contained in:
Timo K
2026-05-13 13:16:24 +02:00
parent 07e7090cc7
commit 0082ade234
2 changed files with 72 additions and 66 deletions
-1
View File
@@ -180,7 +180,6 @@ export const CallFooter: FC<FooterProps> = ({ ref, children, vm }) => {
iconsAndLabels="video" iconsAndLabels="video"
enabled={videoEnabled ?? false} enabled={videoEnabled ?? false}
onMuteClick={toggleVideo} onMuteClick={toggleVideo}
data-testid="incall_videomute"
options={videoOptions} options={videoOptions}
toggles={videoToggles} toggles={videoToggles}
selectedOption={selectedVideo} selectedOption={selectedVideo}
+72 -65
View File
@@ -17,18 +17,14 @@ import {
CheckIcon, CheckIcon,
ChevronUpIcon, ChevronUpIcon,
ChevronDownIcon, ChevronDownIcon,
MicOffSolidIcon,
MicOnIcon, MicOnIcon,
MicOnSolidIcon,
SpinnerIcon, SpinnerIcon,
VideoCallIcon, VideoCallIcon,
VideoCallOffSolidIcon,
VideoCallSolidIcon,
} from "@vector-im/compound-design-tokens/assets/web/icons"; } from "@vector-im/compound-design-tokens/assets/web/icons";
import classNames from "classnames"; import classNames from "classnames";
import { logger } from "matrix-js-sdk/lib/logger";
import styles from "./MediaMuteAndSwitchButton.module.css"; import styles from "./MediaMuteAndSwitchButton.module.css";
import { MicButton, VideoButton } from "../button";
export interface MenuOptions { export interface MenuOptions {
label: string; label: string;
@@ -81,7 +77,7 @@ export const MediaMuteAndSwitchButton: FC<MediaMuteAndSwitchButtonProps> = ({
title, title,
enabled, enabled,
onMuteClick, onMuteClick,
iconsAndLabels: iconsAndLabelsWithDefaultCases, iconsAndLabels,
options, options,
selectedOption, selectedOption,
toggles, toggles,
@@ -89,58 +85,82 @@ export const MediaMuteAndSwitchButton: FC<MediaMuteAndSwitchButtonProps> = ({
}) => { }) => {
const [plannedSelection, setPlannedSelection] = useState<string | null>(null); const [plannedSelection, setPlannedSelection] = useState<string | null>(null);
const [menuOpen, setMenuOpen] = useState(false); const [menuOpen, setMenuOpen] = useState(false);
let iconsAndLabels: IconsAndLabels | undefined;
switch (iconsAndLabelsWithDefaultCases) { let button;
switch (iconsAndLabels) {
case "video": case "video":
iconsAndLabels = { button = (
IconEnabled: VideoCallSolidIcon, <VideoButton
IconDisabled: VideoCallOffSolidIcon, enabled={enabled ?? false}
IconOptions: VideoCallIcon, onClick={(e) => {
disabledLabel: t("stop_video_button_label"), onMuteClick?.();
enabledLabel: t("start_video_button_label"), e.preventDefault();
optionsButtonLabel: t("settings.devices.camera"), e.stopPropagation();
}; }}
disabled={onMuteClick === undefined}
data-testid="incall_videomute"
/>
);
break; break;
case "audio": case "audio":
iconsAndLabels = { button = (
IconEnabled: MicOnSolidIcon, <MicButton
IconDisabled: MicOffSolidIcon, enabled={enabled ?? false}
IconOptions: MicOnIcon, onClick={(e) => {
disabledLabel: t("mute_microphone_button_label"), onMuteClick?.();
enabledLabel: t("unmute_microphone_button_label"), e.preventDefault();
optionsButtonLabel: t("settings.devices.microphone"), e.stopPropagation();
}; }}
disabled={onMuteClick === undefined}
data-testid="incall_mute"
/>
);
break; break;
default: default:
iconsAndLabels = iconsAndLabelsWithDefaultCases; button = (
<Button
iconOnly
role="switch"
Icon={
enabled ? iconsAndLabels?.IconEnabled : iconsAndLabels?.IconDisabled
}
onClick={(e) => {
onMuteClick?.();
e.preventDefault();
e.stopPropagation();
}}
kind={enabled ? "secondary" : "primary"}
size="lg"
className={styles.button}
aria-label={
enabled
? iconsAndLabels?.disabledLabel
: iconsAndLabels?.enabledLabel
}
/>
);
break; break;
} }
const {
IconEnabled, let IconOptions: ComponentType<React.SVGAttributes<SVGElement>> | undefined;
IconDisabled, let optionsButtonLabel: string;
IconOptions, switch (iconsAndLabels) {
disabledLabel, case "video":
enabledLabel, IconOptions = VideoCallIcon;
optionsButtonLabel, optionsButtonLabel = t("settings.devices.camera");
} = iconsAndLabels ?? { break;
IconEnabled: undefined, case "audio":
IconDisabled: undefined, IconOptions = MicOnIcon;
IconOptions: undefined, optionsButtonLabel = t("settings.devices.microphone");
disabledLabel: undefined, break;
enabledLabel: undefined, case undefined:
optionsButtonLabel: undefined, IconOptions = undefined;
}; optionsButtonLabel = "undefined";
{ break;
logger.info( default:
"RENDER WITH: selectedOption !== option.id && plannedSelection === option.id", IconOptions = iconsAndLabels.IconOptions;
selectedOption, optionsButtonLabel = iconsAndLabels.optionsButtonLabel;
" !==", break;
"option.id",
" && ",
plannedSelection,
" === ",
"option.id",
);
} }
return ( return (
<div <div
@@ -150,20 +170,7 @@ export const MediaMuteAndSwitchButton: FC<MediaMuteAndSwitchButtonProps> = ({
})} })}
> >
{/* The mute button lives inside */} {/* The mute button lives inside */}
<Button {button}
iconOnly
role="switch"
Icon={enabled ? IconEnabled : IconDisabled}
onClick={(e) => {
onMuteClick?.();
e.preventDefault();
e.stopPropagation();
}}
kind={enabled ? "secondary" : "primary"}
size="lg"
className={styles.button}
aria-label={enabled ? disabledLabel : enabledLabel}
/>
<Menu <Menu
title={title} title={title}
showTitle={true} showTitle={true}