Use generics to better type TabbedView (#10726)
This commit is contained in:
parent
fcf2fe2c1d
commit
a629ce3a53
12 changed files with 56 additions and 52 deletions
|
@ -38,7 +38,7 @@ import ExportDialog from "../dialogs/ExportDialog";
|
|||
import { useFeatureEnabled } from "../../../hooks/useSettings";
|
||||
import { usePinnedEvents } from "../right_panel/PinnedMessagesCard";
|
||||
import { RightPanelPhases } from "../../../stores/right-panel/RightPanelStorePhases";
|
||||
import { ROOM_NOTIFICATIONS_TAB } from "../dialogs/RoomSettingsDialog";
|
||||
import { RoomSettingsTab } from "../dialogs/RoomSettingsDialog";
|
||||
import { useEventEmitterState } from "../../../hooks/useEventEmitter";
|
||||
import RightPanelStore from "../../../stores/right-panel/RightPanelStore";
|
||||
import DMRoomMap from "../../../utils/DMRoomMap";
|
||||
|
@ -199,7 +199,7 @@ const RoomContextMenu: React.FC<IProps> = ({ room, onFinished, ...props }) => {
|
|||
dis.dispatch({
|
||||
action: "open_room_settings",
|
||||
room_id: room.roomId,
|
||||
initial_tab_id: ROOM_NOTIFICATIONS_TAB,
|
||||
initial_tab_id: RoomSettingsTab.Notifications,
|
||||
});
|
||||
onFinished();
|
||||
|
||||
|
|
|
@ -1494,7 +1494,7 @@ export default class InviteDialog extends React.PureComponent<Props, IInviteDial
|
|||
|
||||
let dialogContent;
|
||||
if (this.props.kind === InviteKind.CallTransfer) {
|
||||
const tabs: NonEmptyArray<Tab> = [
|
||||
const tabs: NonEmptyArray<Tab<TabId>> = [
|
||||
new Tab(TabId.UserDirectory, _td("User Directory"), "mx_InviteDialog_userDirectoryIcon", usersSection),
|
||||
];
|
||||
|
||||
|
|
|
@ -40,14 +40,16 @@ import { NonEmptyArray } from "../../../@types/common";
|
|||
import { PollHistoryTab } from "../settings/tabs/room/PollHistoryTab";
|
||||
import ErrorBoundary from "../elements/ErrorBoundary";
|
||||
|
||||
export const ROOM_GENERAL_TAB = "ROOM_GENERAL_TAB";
|
||||
export const ROOM_VOIP_TAB = "ROOM_VOIP_TAB";
|
||||
export const ROOM_SECURITY_TAB = "ROOM_SECURITY_TAB";
|
||||
export const ROOM_ROLES_TAB = "ROOM_ROLES_TAB";
|
||||
export const ROOM_NOTIFICATIONS_TAB = "ROOM_NOTIFICATIONS_TAB";
|
||||
export const ROOM_BRIDGES_TAB = "ROOM_BRIDGES_TAB";
|
||||
export const ROOM_ADVANCED_TAB = "ROOM_ADVANCED_TAB";
|
||||
export const ROOM_POLL_HISTORY_TAB = "ROOM_POLL_HISTORY_TAB";
|
||||
export const enum RoomSettingsTab {
|
||||
General = "ROOM_GENERAL_TAB",
|
||||
Voip = "ROOM_VOIP_TAB",
|
||||
Security = "ROOM_SECURITY_TAB",
|
||||
Roles = "ROOM_ROLES_TAB",
|
||||
Notifications = "ROOM_NOTIFICATIONS_TAB",
|
||||
Bridges = "ROOM_BRIDGES_TAB",
|
||||
Advanced = "ROOM_ADVANCED_TAB",
|
||||
PollHistory = "ROOM_POLL_HISTORY_TAB",
|
||||
}
|
||||
|
||||
interface IProps {
|
||||
roomId: string;
|
||||
|
@ -118,12 +120,12 @@ class RoomSettingsDialog extends React.Component<IProps, IState> {
|
|||
this.forceUpdate();
|
||||
};
|
||||
|
||||
private getTabs(): NonEmptyArray<Tab> {
|
||||
const tabs: Tab[] = [];
|
||||
private getTabs(): NonEmptyArray<Tab<RoomSettingsTab>> {
|
||||
const tabs: Tab<RoomSettingsTab>[] = [];
|
||||
|
||||
tabs.push(
|
||||
new Tab(
|
||||
ROOM_GENERAL_TAB,
|
||||
RoomSettingsTab.General,
|
||||
_td("General"),
|
||||
"mx_RoomSettingsDialog_settingsIcon",
|
||||
<GeneralRoomSettingsTab room={this.state.room} />,
|
||||
|
@ -133,7 +135,7 @@ class RoomSettingsDialog extends React.Component<IProps, IState> {
|
|||
if (SettingsStore.getValue("feature_group_calls")) {
|
||||
tabs.push(
|
||||
new Tab(
|
||||
ROOM_VOIP_TAB,
|
||||
RoomSettingsTab.Voip,
|
||||
_td("Voice & Video"),
|
||||
"mx_RoomSettingsDialog_voiceIcon",
|
||||
<VoipRoomSettingsTab room={this.state.room} />,
|
||||
|
@ -142,7 +144,7 @@ class RoomSettingsDialog extends React.Component<IProps, IState> {
|
|||
}
|
||||
tabs.push(
|
||||
new Tab(
|
||||
ROOM_SECURITY_TAB,
|
||||
RoomSettingsTab.Security,
|
||||
_td("Security & Privacy"),
|
||||
"mx_RoomSettingsDialog_securityIcon",
|
||||
<SecurityRoomSettingsTab room={this.state.room} closeSettingsFn={() => this.props.onFinished(true)} />,
|
||||
|
@ -151,7 +153,7 @@ class RoomSettingsDialog extends React.Component<IProps, IState> {
|
|||
);
|
||||
tabs.push(
|
||||
new Tab(
|
||||
ROOM_ROLES_TAB,
|
||||
RoomSettingsTab.Roles,
|
||||
_td("Roles & Permissions"),
|
||||
"mx_RoomSettingsDialog_rolesIcon",
|
||||
<RolesRoomSettingsTab room={this.state.room} />,
|
||||
|
@ -160,7 +162,7 @@ class RoomSettingsDialog extends React.Component<IProps, IState> {
|
|||
);
|
||||
tabs.push(
|
||||
new Tab(
|
||||
ROOM_NOTIFICATIONS_TAB,
|
||||
RoomSettingsTab.Notifications,
|
||||
_td("Notifications"),
|
||||
"mx_RoomSettingsDialog_notificationsIcon",
|
||||
(
|
||||
|
@ -176,7 +178,7 @@ class RoomSettingsDialog extends React.Component<IProps, IState> {
|
|||
if (SettingsStore.getValue("feature_bridge_state")) {
|
||||
tabs.push(
|
||||
new Tab(
|
||||
ROOM_BRIDGES_TAB,
|
||||
RoomSettingsTab.Bridges,
|
||||
_td("Bridges"),
|
||||
"mx_RoomSettingsDialog_bridgesIcon",
|
||||
<BridgeSettingsTab room={this.state.room} />,
|
||||
|
@ -187,7 +189,7 @@ class RoomSettingsDialog extends React.Component<IProps, IState> {
|
|||
|
||||
tabs.push(
|
||||
new Tab(
|
||||
ROOM_POLL_HISTORY_TAB,
|
||||
RoomSettingsTab.PollHistory,
|
||||
_td("Poll history"),
|
||||
"mx_RoomSettingsDialog_pollsIcon",
|
||||
<PollHistoryTab room={this.state.room} onFinished={() => this.props.onFinished(true)} />,
|
||||
|
@ -197,7 +199,7 @@ class RoomSettingsDialog extends React.Component<IProps, IState> {
|
|||
if (SettingsStore.getValue(UIFeature.AdvancedSettings)) {
|
||||
tabs.push(
|
||||
new Tab(
|
||||
ROOM_ADVANCED_TAB,
|
||||
RoomSettingsTab.Advanced,
|
||||
_td("Advanced"),
|
||||
"mx_RoomSettingsDialog_warningIcon",
|
||||
(
|
||||
|
@ -211,7 +213,7 @@ class RoomSettingsDialog extends React.Component<IProps, IState> {
|
|||
);
|
||||
}
|
||||
|
||||
return tabs as NonEmptyArray<Tab>;
|
||||
return tabs as NonEmptyArray<Tab<RoomSettingsTab>>;
|
||||
}
|
||||
|
||||
public render(): React.ReactNode {
|
||||
|
|
|
@ -70,7 +70,7 @@ const SpacePreferencesAppearanceTab: React.FC<Pick<IProps, "space">> = ({ space
|
|||
};
|
||||
|
||||
const SpacePreferencesDialog: React.FC<IProps> = ({ space, initialTabId, onFinished }) => {
|
||||
const tabs: NonEmptyArray<Tab> = [
|
||||
const tabs: NonEmptyArray<Tab<SpacePreferenceTab>> = [
|
||||
new Tab(
|
||||
SpacePreferenceTab.Appearance,
|
||||
_td("Appearance"),
|
||||
|
|
|
@ -80,7 +80,7 @@ const SpaceSettingsDialog: React.FC<IProps> = ({ matrixClient: cli, space, onFin
|
|||
<AdvancedRoomSettingsTab room={space} closeSettingsFn={onFinished} />,
|
||||
)
|
||||
: null,
|
||||
].filter(Boolean) as NonEmptyArray<Tab>;
|
||||
].filter(Boolean) as NonEmptyArray<Tab<SpaceSettingsTab>>;
|
||||
}, [cli, space, onFinished]);
|
||||
|
||||
return (
|
||||
|
|
|
@ -81,8 +81,8 @@ export default class UserSettingsDialog extends React.Component<IProps, IState>
|
|||
this.setState({ newSessionManagerEnabled: newValue });
|
||||
};
|
||||
|
||||
private getTabs(): NonEmptyArray<Tab> {
|
||||
const tabs: Tab[] = [];
|
||||
private getTabs(): NonEmptyArray<Tab<UserTab>> {
|
||||
const tabs: Tab<UserTab>[] = [];
|
||||
|
||||
tabs.push(
|
||||
new Tab(
|
||||
|
@ -208,7 +208,7 @@ export default class UserSettingsDialog extends React.Component<IProps, IState>
|
|||
),
|
||||
);
|
||||
|
||||
return tabs as NonEmptyArray<Tab>;
|
||||
return tabs as NonEmptyArray<Tab<UserTab>>;
|
||||
}
|
||||
|
||||
public render(): React.ReactNode {
|
||||
|
|
|
@ -85,6 +85,8 @@ export interface PickerIProps {
|
|||
onFinished(sourceId?: string): void;
|
||||
}
|
||||
|
||||
type TabId = "screen" | "window";
|
||||
|
||||
export default class DesktopCapturerSourcePicker extends React.Component<PickerIProps, PickerIState> {
|
||||
public interval: number;
|
||||
|
||||
|
@ -134,7 +136,7 @@ export default class DesktopCapturerSourcePicker extends React.Component<PickerI
|
|||
this.props.onFinished();
|
||||
};
|
||||
|
||||
private getTab(type: "screen" | "window", label: string): Tab {
|
||||
private getTab(type: TabId, label: string): Tab<TabId> {
|
||||
const sources = this.state.sources
|
||||
.filter((source) => source.id.startsWith(type))
|
||||
.map((source) => {
|
||||
|
@ -152,7 +154,7 @@ export default class DesktopCapturerSourcePicker extends React.Component<PickerI
|
|||
}
|
||||
|
||||
public render(): React.ReactNode {
|
||||
const tabs: NonEmptyArray<Tab> = [
|
||||
const tabs: NonEmptyArray<Tab<TabId>> = [
|
||||
this.getTab("screen", _t("Share entire screen")),
|
||||
this.getTab("window", _t("Application window")),
|
||||
];
|
||||
|
|
|
@ -33,7 +33,7 @@ import { Action } from "../../../dispatcher/actions";
|
|||
import SpaceStore from "../../../stores/spaces/SpaceStore";
|
||||
import { showSpaceInvite } from "../../../utils/space";
|
||||
import EventTileBubble from "../messages/EventTileBubble";
|
||||
import { ROOM_SECURITY_TAB } from "../dialogs/RoomSettingsDialog";
|
||||
import { RoomSettingsTab } from "../dialogs/RoomSettingsDialog";
|
||||
import { MatrixClientPeg } from "../../../MatrixClientPeg";
|
||||
import { shouldShowComponent } from "../../../customisations/helpers/UIComponents";
|
||||
import { UIComponent } from "../../../settings/UIFeature";
|
||||
|
@ -268,7 +268,7 @@ const NewRoomIntro: React.FC = () => {
|
|||
event.preventDefault();
|
||||
defaultDispatcher.dispatch({
|
||||
action: "open_room_settings",
|
||||
initial_tab_id: ROOM_SECURITY_TAB,
|
||||
initial_tab_id: RoomSettingsTab.Security,
|
||||
});
|
||||
}
|
||||
|
||||
|
|
|
@ -31,7 +31,7 @@ import { upgradeRoom } from "../../../utils/RoomUpgrade";
|
|||
import { arrayHasDiff } from "../../../utils/arrays";
|
||||
import { useLocalEcho } from "../../../hooks/useLocalEcho";
|
||||
import dis from "../../../dispatcher/dispatcher";
|
||||
import { ROOM_SECURITY_TAB } from "../dialogs/RoomSettingsDialog";
|
||||
import { RoomSettingsTab } from "../dialogs/RoomSettingsDialog";
|
||||
import { Action } from "../../../dispatcher/actions";
|
||||
import { ViewRoomPayload } from "../../../dispatcher/payloads/ViewRoomPayload";
|
||||
import { doesRoomVersionSupport, PreferredRoomVersions } from "../../../utils/PreferredRoomVersions";
|
||||
|
@ -320,7 +320,7 @@ const JoinRuleSettings: React.FC<IProps> = ({
|
|||
// open new settings on this tab
|
||||
dis.dispatch({
|
||||
action: "open_room_settings",
|
||||
initial_tab_id: ROOM_SECURITY_TAB,
|
||||
initial_tab_id: RoomSettingsTab.Security,
|
||||
});
|
||||
},
|
||||
});
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue