Write the mute button once instead of twice per kind

- Both arms of the switch were the same eleven lines of click, disabled, busy
  and enabled wiring; only the component and the test id differed.
- Two copies that had to be kept in sync by hand, for nothing.
- `toggles` becomes an expression rather than a `let` mutated in a switch,
  which makes the optional chaining downstream dead.
- The labels switch stays: i18n extraction needs literal `t("…")` keys, and it
  gives exhaustiveness checking on the union.
This commit is contained in:
fkwp
2026-09-17 11:56:31 +02:00
parent a6e00895a0
commit d7e0444117
+18 -31
View File
@@ -256,12 +256,11 @@ export const MediaMuteAndSwitchButton: FC<MediaMuteAndSwitchButtonProps> = ({
if (menuOpen) devices.requestDeviceNames(); // No-op after the first call if (menuOpen) devices.requestDeviceNames(); // No-op after the first call
}, [menuOpen, devices]); }, [menuOpen, devices]);
let button; // The mute control differs between the two only in which button it is and
let toggles: { label: string; enabled: boolean; id: string }[] = []; // what it is called; how it behaves is the same, and was worth saying once.
switch (iconsAndLabels) { const MuteButton = iconsAndLabels === "audio" ? MicButton : VideoButton;
case "video": const button = (
button = ( <MuteButton
<VideoButton
enabled={enabled ?? false} enabled={enabled ?? false}
busy={isBusy} busy={isBusy}
onClick={(e) => { onClick={(e) => {
@@ -270,35 +269,23 @@ export const MediaMuteAndSwitchButton: FC<MediaMuteAndSwitchButtonProps> = ({
e.stopPropagation(); e.stopPropagation();
}} }}
disabled={isBusy || onMuteClick === undefined} disabled={isBusy || onMuteClick === undefined}
data-testid="incall_videomute" data-testid={
iconsAndLabels === "audio" ? "incall_mute" : "incall_videomute"
}
/> />
); );
if (videoBlurToggleClick !== undefined) {
toggles = [ // Only the camera menu carries a toggle, and only when the caller offers one.
const toggles =
iconsAndLabels === "video" && videoBlurToggleClick !== undefined
? [
{ {
label: t("action.blur_background"), label: t("action.blur_background"),
enabled: videoBlurEnabled ?? false, enabled: videoBlurEnabled ?? false,
id: BLUR_ID, id: BLUR_ID,
}, },
]; ]
} : [];
break;
case "audio":
button = (
<MicButton
enabled={enabled ?? false}
busy={isBusy}
onClick={(e) => {
onMuteClick?.();
e.preventDefault();
e.stopPropagation();
}}
disabled={isBusy || onMuteClick === undefined}
data-testid="incall_mute"
/>
);
break;
}
let optionsButtonLabel: string; let optionsButtonLabel: string;
let defaultMenuTitle: string; let defaultMenuTitle: string;
@@ -518,15 +505,15 @@ export const MediaMuteAndSwitchButton: FC<MediaMuteAndSwitchButtonProps> = ({
</div> </div>
</div> </div>
</div> </div>
{(toggles?.length ?? 0) > 0 && <hr />} {toggles.length > 0 && <hr />}
{toggles?.map((toggle) => ( {toggles.map((toggle) => (
<ToggleMenuItem <ToggleMenuItem
label={toggle.label} label={toggle.label}
onSelect={(e) => { onSelect={(e) => {
videoBlurToggleClick?.(); videoBlurToggleClick?.();
e.preventDefault(); e.preventDefault();
}} }}
checked={toggle.enabled ?? false} checked={toggle.enabled}
key={toggle.id} key={toggle.id}
/> />
))} ))}