* Convert tabbedview to functional component The 'Tab' is still a class, so now it's a functional component that has a supporting class, which is maybe a bit... jarring, but I think is actually perfectly logical. * put comment back * Fix bad tab ID behaviour * Make TabbedView a controlled component This does mean the logic of keeping what tab is active is now in each container component, but for a functional component, this is a single line. It makes TabbedView simpler and the container components always know exactly what tab is being displayed rather than having to effectively keep the state separately themselves if they wanted it. Based on https://github.com/matrix-org/matrix-react-sdk/pull/12478 * Fix some types & unused prop * Remove weird behaviour of using first tab is active isn't valid * Don't pass initialTabID here now it no longer has the prop * Fix test * bleh... id, not icon * Change to sub-components and use contitional call syntax * Comments * Fix element IDs * Fix merge * Test DesktopCapturerSourcePicker to make sonarcloud the right colour * Use custom hook for the fllback tab behaviour
103 lines
4.0 KiB
TypeScript
103 lines
4.0 KiB
TypeScript
/*
|
|
Copyright 2021 The Matrix.org Foundation C.I.C.
|
|
|
|
Licensed under the Apache License, Version 2.0 (the "License");
|
|
you may not use this file except in compliance with the License.
|
|
You may obtain a copy of the License at
|
|
|
|
http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
Unless required by applicable law or agreed to in writing, software
|
|
distributed under the License is distributed on an "AS IS" BASIS,
|
|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
See the License for the specific language governing permissions and
|
|
limitations under the License.
|
|
*/
|
|
|
|
import React, { useMemo } from "react";
|
|
import { Room, MatrixClient } from "matrix-js-sdk/src/matrix";
|
|
|
|
import { _t, _td } from "../../../languageHandler";
|
|
import BaseDialog from "./BaseDialog";
|
|
import defaultDispatcher from "../../../dispatcher/dispatcher";
|
|
import { useDispatcher } from "../../../hooks/useDispatcher";
|
|
import TabbedView, { Tab } from "../../structures/TabbedView";
|
|
import SpaceSettingsGeneralTab from "../spaces/SpaceSettingsGeneralTab";
|
|
import SpaceSettingsVisibilityTab from "../spaces/SpaceSettingsVisibilityTab";
|
|
import SettingsStore from "../../../settings/SettingsStore";
|
|
import { UIFeature } from "../../../settings/UIFeature";
|
|
import AdvancedRoomSettingsTab from "../settings/tabs/room/AdvancedRoomSettingsTab";
|
|
import RolesRoomSettingsTab from "../settings/tabs/room/RolesRoomSettingsTab";
|
|
import { Action } from "../../../dispatcher/actions";
|
|
import { NonEmptyArray } from "../../../@types/common";
|
|
|
|
export enum SpaceSettingsTab {
|
|
General = "SPACE_GENERAL_TAB",
|
|
Visibility = "SPACE_VISIBILITY_TAB",
|
|
Roles = "SPACE_ROLES_TAB",
|
|
Advanced = "SPACE_ADVANCED_TAB",
|
|
}
|
|
|
|
interface IProps {
|
|
matrixClient: MatrixClient;
|
|
space: Room;
|
|
onFinished(): void;
|
|
}
|
|
|
|
const SpaceSettingsDialog: React.FC<IProps> = ({ matrixClient: cli, space, onFinished }) => {
|
|
useDispatcher(defaultDispatcher, (payload) => {
|
|
if (payload.action === Action.AfterLeaveRoom && payload.room_id === space.roomId) {
|
|
onFinished();
|
|
}
|
|
});
|
|
|
|
const tabs = useMemo(() => {
|
|
return [
|
|
new Tab(
|
|
SpaceSettingsTab.General,
|
|
_td("common|general"),
|
|
"mx_SpaceSettingsDialog_generalIcon",
|
|
<SpaceSettingsGeneralTab matrixClient={cli} space={space} />,
|
|
),
|
|
new Tab(
|
|
SpaceSettingsTab.Visibility,
|
|
_td("room_settings|visibility|title"),
|
|
"mx_SpaceSettingsDialog_visibilityIcon",
|
|
<SpaceSettingsVisibilityTab matrixClient={cli} space={space} closeSettingsFn={onFinished} />,
|
|
),
|
|
new Tab(
|
|
SpaceSettingsTab.Roles,
|
|
_td("room_settings|permissions|title"),
|
|
"mx_RoomSettingsDialog_rolesIcon",
|
|
<RolesRoomSettingsTab room={space} />,
|
|
),
|
|
SettingsStore.getValue(UIFeature.AdvancedSettings)
|
|
? new Tab(
|
|
SpaceSettingsTab.Advanced,
|
|
_td("common|advanced"),
|
|
"mx_RoomSettingsDialog_warningIcon",
|
|
<AdvancedRoomSettingsTab room={space} closeSettingsFn={onFinished} />,
|
|
)
|
|
: null,
|
|
].filter(Boolean) as NonEmptyArray<Tab<SpaceSettingsTab>>;
|
|
}, [cli, space, onFinished]);
|
|
|
|
const [activeTabId, setActiveTabId] = React.useState(SpaceSettingsTab.General);
|
|
|
|
return (
|
|
<BaseDialog
|
|
title={_t("space_settings|title", { spaceName: space.name || _t("common|unnamed_space") })}
|
|
className="mx_SpaceSettingsDialog"
|
|
contentId="mx_SpaceSettingsDialog"
|
|
onFinished={onFinished}
|
|
fixedWidth={false}
|
|
>
|
|
<div className="mx_SpaceSettingsDialog_content" id="mx_SpaceSettingsDialog">
|
|
<TabbedView tabs={tabs} activeTabId={activeTabId} onChange={setActiveTabId} />
|
|
</div>
|
|
</BaseDialog>
|
|
);
|
|
};
|
|
|
|
export default SpaceSettingsDialog;
|