2021-11-26 15:41:04 +00:00
|
|
|
/*
|
2024-09-09 14:57:16 +01:00
|
|
|
Copyright 2024 New Vector Ltd.
|
|
|
|
|
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
|
|
|
*/
|
|
|
|
|
|
2022-02-24 10:01:06 +01:00
|
|
|
import React 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,
|
|
|
|
|
} from "@vector-im/compound-design-tokens/assets/web/icons";
|
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-02 10:18:45 +01:00
|
|
|
import { Icon as PinUprightIcon } from "../../../../res/img/element-icons/room/pin-upright.svg";
|
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 }) => {
|
2021-11-26 15:41:04 +00:00
|
|
|
const [menuDisplayed, handle, openMenu, closeMenu] = useContextMenu<HTMLDivElement>();
|
|
|
|
|
|
|
|
|
|
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,
|
|
|
|
|
})}
|
2021-11-26 15:41:04 +00:00
|
|
|
onFinished={closeMenu}
|
|
|
|
|
managed={false}
|
|
|
|
|
focusLock={true}
|
|
|
|
|
>
|
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 && (
|
|
|
|
|
<>
|
|
|
|
|
<h4 className="mx_QuickSettingsButton_pinToSidebarHeading">
|
|
|
|
|
<PinUprightIcon className="mx_QuickSettingsButton_icon" />
|
|
|
|
|
{_t("quick_settings|metaspace_section")}
|
|
|
|
|
</h4>
|
2021-11-26 15:41:04 +00:00
|
|
|
|
2025-02-13 11:53:51 +01:00
|
|
|
<StyledCheckbox
|
|
|
|
|
className="mx_QuickSettingsButton_favouritesCheckbox"
|
|
|
|
|
checked={!!favouritesEnabled}
|
|
|
|
|
onChange={onMetaSpaceChangeFactory(
|
|
|
|
|
MetaSpace.Favourites,
|
|
|
|
|
"WebQuickSettingsPinToSidebarCheckbox",
|
|
|
|
|
)}
|
|
|
|
|
>
|
|
|
|
|
<FavouriteSolidIcon className="mx_QuickSettingsButton_icon" />
|
|
|
|
|
{_t("common|favourites")}
|
|
|
|
|
</StyledCheckbox>
|
|
|
|
|
<StyledCheckbox
|
|
|
|
|
className="mx_QuickSettingsButton_peopleCheckbox"
|
|
|
|
|
checked={!!peopleEnabled}
|
|
|
|
|
onChange={onMetaSpaceChangeFactory(
|
|
|
|
|
MetaSpace.People,
|
|
|
|
|
"WebQuickSettingsPinToSidebarCheckbox",
|
|
|
|
|
)}
|
|
|
|
|
>
|
|
|
|
|
<UserProfileSolidIcon className="mx_QuickSettingsButton_icon" />
|
|
|
|
|
{_t("common|people")}
|
|
|
|
|
</StyledCheckbox>
|
|
|
|
|
<AccessibleButton
|
|
|
|
|
className="mx_QuickSettingsButton_moreOptionsButton"
|
|
|
|
|
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>
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return (
|
|
|
|
|
<>
|
2024-05-03 16:07:11 +02:00
|
|
|
<AccessibleButton
|
2021-11-29 20:10:34 +00:00
|
|
|
className={classNames("mx_QuickSettingsButton", { expanded: !isPanelCollapsed })}
|
2021-11-26 15:41:04 +00:00
|
|
|
onClick={openMenu}
|
2024-05-03 16:07:11 +02:00
|
|
|
aria-label={_t("quick_settings|title")}
|
|
|
|
|
title={isPanelCollapsed ? _t("quick_settings|title") : undefined}
|
2023-12-21 08:50:42 +00:00
|
|
|
ref={handle}
|
2023-04-20 18:13:30 +01:00
|
|
|
aria-expanded={!isPanelCollapsed}
|
2021-11-29 20:10:34 +00:00
|
|
|
>
|
2023-08-22 18:47:33 +01:00
|
|
|
{!isPanelCollapsed ? _t("common|settings") : null}
|
2024-05-03 16:07:11 +02:00
|
|
|
</AccessibleButton>
|
2021-11-26 15:41:04 +00:00
|
|
|
|
|
|
|
|
{contextMenu}
|
|
|
|
|
</>
|
|
|
|
|
);
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
export default QuickSettingsButton;
|