2021-11-26 15:41:04 +00:00
|
|
|
/*
|
2025-03-20 15:35:54 +00:00
|
|
|
Copyright 2024,2025 New Vector Ltd.
|
2024-09-09 14:57:16 +01:00
|
|
|
Copyright 2021-2023 The Matrix.org Foundation C.I.C.
|
2021-11-26 15:41:04 +00:00
|
|
|
|
2025-01-06 11:18:54 +00:00
|
|
|
SPDX-License-Identifier: AGPL-3.0-only OR GPL-3.0-only OR LicenseRef-Element-Commercial
|
2024-09-09 14:57:16 +01:00
|
|
|
Please see LICENSE files in the repository root for full details.
|
2021-11-26 15:41:04 +00:00
|
|
|
*/
|
|
|
|
|
|
2025-03-27 10:43:58 +00:00
|
|
|
import React, { type JSX } from "react";
|
2021-12-09 09:10:23 +00:00
|
|
|
import classNames from "classnames";
|
2024-11-18 15:47:15 +00:00
|
|
|
import {
|
|
|
|
|
OverflowHorizontalIcon,
|
|
|
|
|
UserProfileSolidIcon,
|
|
|
|
|
FavouriteSolidIcon,
|
2025-03-20 15:35:54 +00:00
|
|
|
PinSolidIcon,
|
2025-11-27 16:03:19 +00:00
|
|
|
SettingsSolidIcon,
|
2024-11-18 15:47:15 +00:00
|
|
|
} from "@vector-im/compound-design-tokens/assets/web/icons";
|
2025-11-27 16:03:19 +00:00
|
|
|
import { IconButton, Text, Tooltip } from "@vector-im/compound-web";
|
2021-11-26 15:41:04 +00:00
|
|
|
|
|
|
|
|
import { _t } from "../../../languageHandler";
|
2021-11-29 17:42:53 +00:00
|
|
|
import ContextMenu, { alwaysAboveRightOf, ChevronFace, useContextMenu } from "../../structures/ContextMenu";
|
2021-11-26 15:41:04 +00:00
|
|
|
import AccessibleButton from "../elements/AccessibleButton";
|
|
|
|
|
import StyledCheckbox from "../elements/StyledCheckbox";
|
|
|
|
|
import { MetaSpace } from "../../../stores/spaces";
|
|
|
|
|
import { useSettingValue } from "../../../hooks/useSettings";
|
|
|
|
|
import { onMetaSpaceChangeFactory } from "../settings/tabs/user/SidebarUserSettingsTab";
|
|
|
|
|
import defaultDispatcher from "../../../dispatcher/dispatcher";
|
|
|
|
|
import { Action } from "../../../dispatcher/actions";
|
2022-03-24 16:42:53 -06:00
|
|
|
import { UserTab } from "../dialogs/UserTab";
|
2022-02-24 10:01:06 +01:00
|
|
|
import QuickThemeSwitcher from "./QuickThemeSwitcher";
|
2022-03-23 20:17:57 +00:00
|
|
|
import Modal from "../../../Modal";
|
|
|
|
|
import DevtoolsDialog from "../dialogs/DevtoolsDialog";
|
2022-10-19 13:07:03 +01:00
|
|
|
import { SdkContextClass } from "../../../contexts/SDKContext";
|
2021-11-26 15:41:04 +00:00
|
|
|
|
2023-01-12 13:25:14 +00:00
|
|
|
const QuickSettingsButton: React.FC<{
|
|
|
|
|
isPanelCollapsed: boolean;
|
|
|
|
|
}> = ({ isPanelCollapsed = false }) => {
|
2025-11-27 16:03:19 +00:00
|
|
|
const [menuDisplayed, handle, openMenu, closeMenu] = useContextMenu<HTMLButtonElement>();
|
2021-11-26 15:41:04 +00:00
|
|
|
|
|
|
|
|
const { [MetaSpace.Favourites]: favouritesEnabled, [MetaSpace.People]: peopleEnabled } =
|
2024-12-23 20:25:15 +00:00
|
|
|
useSettingValue("Spaces.enabledMetaSpaces");
|
2021-11-26 15:41:04 +00:00
|
|
|
|
2023-06-28 16:39:19 +02:00
|
|
|
const currentRoomId = SdkContextClass.instance.roomViewStore.getRoomId();
|
2024-12-23 20:25:15 +00:00
|
|
|
const developerModeEnabled = useSettingValue("developerMode");
|
2025-02-13 11:53:51 +01:00
|
|
|
// "Favourites" and "People" meta spaces are not available in the new room list
|
|
|
|
|
const newRoomListEnabled = useSettingValue("feature_new_room_list");
|
2023-06-28 16:39:19 +02:00
|
|
|
|
2023-02-16 09:38:44 +00:00
|
|
|
let contextMenu: JSX.Element | undefined;
|
|
|
|
|
if (menuDisplayed && handle.current) {
|
2021-11-26 15:41:04 +00:00
|
|
|
contextMenu = (
|
|
|
|
|
<ContextMenu
|
|
|
|
|
{...alwaysAboveRightOf(handle.current.getBoundingClientRect(), ChevronFace.None, 16)}
|
2025-02-13 11:53:51 +01:00
|
|
|
wrapperClassName={classNames("mx_QuickSettingsButton_ContextMenuWrapper", {
|
|
|
|
|
mx_QuickSettingsButton_ContextMenuWrapper_new_room_list: newRoomListEnabled,
|
|
|
|
|
})}
|
2025-03-10 09:12:38 +00:00
|
|
|
// Eventually replace with a properly aria-labelled menu
|
|
|
|
|
data-testid="quick-settings-menu"
|
2021-11-26 15:41:04 +00:00
|
|
|
onFinished={closeMenu}
|
|
|
|
|
managed={false}
|
|
|
|
|
focusLock={true}
|
2026-04-07 16:17:59 +01:00
|
|
|
role="region"
|
|
|
|
|
aria-label={_t("quick_settings|title")}
|
2021-11-26 15:41:04 +00:00
|
|
|
>
|
2023-09-25 18:12:41 +01:00
|
|
|
<h2>{_t("quick_settings|title")}</h2>
|
2021-11-26 15:41:04 +00:00
|
|
|
|
2022-03-23 20:17:57 +00:00
|
|
|
<AccessibleButton
|
|
|
|
|
onClick={() => {
|
|
|
|
|
closeMenu();
|
2022-10-19 13:07:03 +01:00
|
|
|
defaultDispatcher.dispatch({ action: Action.ViewUserSettings });
|
2022-03-23 20:17:57 +00:00
|
|
|
}}
|
|
|
|
|
kind="primary_outline"
|
|
|
|
|
>
|
2023-09-25 18:12:41 +01:00
|
|
|
{_t("quick_settings|all_settings")}
|
2022-03-23 20:17:57 +00:00
|
|
|
</AccessibleButton>
|
|
|
|
|
|
2023-06-28 16:39:19 +02:00
|
|
|
{currentRoomId && developerModeEnabled && (
|
2022-03-02 10:18:45 +01:00
|
|
|
<AccessibleButton
|
|
|
|
|
onClick={() => {
|
|
|
|
|
closeMenu();
|
2022-03-23 20:17:57 +00:00
|
|
|
Modal.createDialog(
|
|
|
|
|
DevtoolsDialog,
|
2022-12-12 12:24:14 +01:00
|
|
|
{
|
2023-06-28 16:39:19 +02:00
|
|
|
roomId: currentRoomId,
|
2022-12-12 12:24:14 +01:00
|
|
|
},
|
2022-03-02 10:18:45 +01:00
|
|
|
"mx_DevtoolsDialog_wrapper",
|
2022-12-12 12:24:14 +01:00
|
|
|
);
|
|
|
|
|
}}
|
2022-03-02 10:18:45 +01:00
|
|
|
kind="danger_outline"
|
|
|
|
|
>
|
2023-09-19 17:16:38 +01:00
|
|
|
{_t("devtools|title")}
|
2022-03-02 10:18:45 +01:00
|
|
|
</AccessibleButton>
|
2022-12-12 12:24:14 +01:00
|
|
|
)}
|
2021-11-26 15:41:04 +00:00
|
|
|
|
2025-02-13 11:53:51 +01:00
|
|
|
{!newRoomListEnabled && (
|
|
|
|
|
<>
|
2025-03-20 15:35:54 +00:00
|
|
|
<h4>
|
|
|
|
|
<PinSolidIcon className="mx_QuickSettingsButton_icon" />
|
2025-02-13 11:53:51 +01:00
|
|
|
{_t("quick_settings|metaspace_section")}
|
|
|
|
|
</h4>
|
|
|
|
|
<StyledCheckbox
|
2025-03-20 15:35:54 +00:00
|
|
|
className="mx_QuickSettingsButton_option"
|
2025-02-13 11:53:51 +01:00
|
|
|
checked={!!favouritesEnabled}
|
|
|
|
|
onChange={onMetaSpaceChangeFactory(
|
|
|
|
|
MetaSpace.Favourites,
|
|
|
|
|
"WebQuickSettingsPinToSidebarCheckbox",
|
|
|
|
|
)}
|
|
|
|
|
>
|
|
|
|
|
<FavouriteSolidIcon className="mx_QuickSettingsButton_icon" />
|
|
|
|
|
{_t("common|favourites")}
|
|
|
|
|
</StyledCheckbox>
|
|
|
|
|
<StyledCheckbox
|
2025-03-20 15:35:54 +00:00
|
|
|
className="mx_QuickSettingsButton_option"
|
2025-02-13 11:53:51 +01:00
|
|
|
checked={!!peopleEnabled}
|
|
|
|
|
onChange={onMetaSpaceChangeFactory(
|
|
|
|
|
MetaSpace.People,
|
|
|
|
|
"WebQuickSettingsPinToSidebarCheckbox",
|
|
|
|
|
)}
|
|
|
|
|
>
|
|
|
|
|
<UserProfileSolidIcon className="mx_QuickSettingsButton_icon" />
|
|
|
|
|
{_t("common|people")}
|
|
|
|
|
</StyledCheckbox>
|
|
|
|
|
<AccessibleButton
|
2025-03-20 15:35:54 +00:00
|
|
|
className="mx_QuickSettingsButton_moreOptionsButton mx_QuickSettingsButton_option"
|
2025-02-13 11:53:51 +01:00
|
|
|
onClick={() => {
|
|
|
|
|
closeMenu();
|
|
|
|
|
defaultDispatcher.dispatch({
|
|
|
|
|
action: Action.ViewUserSettings,
|
|
|
|
|
initialTabId: UserTab.Sidebar,
|
|
|
|
|
});
|
|
|
|
|
}}
|
|
|
|
|
>
|
|
|
|
|
<OverflowHorizontalIcon className="mx_QuickSettingsButton_icon" />
|
|
|
|
|
{_t("quick_settings|sidebar_settings")}
|
|
|
|
|
</AccessibleButton>
|
|
|
|
|
</>
|
|
|
|
|
)}
|
2022-02-24 10:01:06 +01:00
|
|
|
<QuickThemeSwitcher requestClose={closeMenu} />
|
2021-11-26 15:41:04 +00:00
|
|
|
</ContextMenu>
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
2025-11-27 16:03:19 +00:00
|
|
|
let button = (
|
|
|
|
|
<IconButton
|
|
|
|
|
aria-label={_t("quick_settings|title")}
|
|
|
|
|
className={classNames("mx_QuickSettingsButton", { expanded: !isPanelCollapsed })}
|
|
|
|
|
onClick={openMenu}
|
|
|
|
|
ref={handle}
|
|
|
|
|
aria-expanded={!isPanelCollapsed}
|
|
|
|
|
>
|
|
|
|
|
<>
|
|
|
|
|
<SettingsSolidIcon />
|
|
|
|
|
{/* This is dirty, but we need to add the label to the indicator icon */}
|
|
|
|
|
{!isPanelCollapsed && (
|
|
|
|
|
<Text className="mx_QuickSettingsButton_label" as="span" size="md" title={_t("common|settings")}>
|
|
|
|
|
{_t("common|settings")}
|
|
|
|
|
</Text>
|
|
|
|
|
)}
|
|
|
|
|
</>
|
|
|
|
|
</IconButton>
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
if (isPanelCollapsed) {
|
|
|
|
|
button = (
|
|
|
|
|
<Tooltip label={_t("quick_settings|title")} placement="right">
|
|
|
|
|
{button}
|
|
|
|
|
</Tooltip>
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
2021-11-26 15:41:04 +00:00
|
|
|
return (
|
|
|
|
|
<>
|
2025-12-19 14:40:44 +00:00
|
|
|
{button}
|
2021-11-26 15:41:04 +00:00
|
|
|
{contextMenu}
|
|
|
|
|
</>
|
|
|
|
|
);
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
export default QuickSettingsButton;
|