Skip to content
This repository was archived by the owner on Sep 11, 2024. It is now read-only.

Commit 5b8d440

Browse files
author
Kerry
authored
type Actions (#7862)
* type ViewHomPage action Signed-off-by: Kerry Archibald <[email protected]> * type spacestore actions Signed-off-by: Kerry Archibald <[email protected]> * lint Signed-off-by: Kerry Archibald <[email protected]> * add action types Signed-off-by: Kerry Archibald <[email protected]> * use new action types in stores Signed-off-by: Kerry Archibald <[email protected]> * remove debug change Signed-off-by: Kerry Archibald <[email protected]> * stricter keyboard shortcut types Signed-off-by: Kerry Archibald <[email protected]> * action comments Signed-off-by: Kerry Archibald <[email protected]>
1 parent 57595bc commit 5b8d440

33 files changed

+304
-73
lines changed

src/Registration.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ import dis from './dispatcher/dispatcher';
2626
import Modal from './Modal';
2727
import { _t } from './languageHandler';
2828
import QuestionDialog from "./components/views/dialogs/QuestionDialog";
29+
import { Action } from "./dispatcher/actions";
2930

3031
// Regex for what a "safe" or "Matrix-looking" localpart would be.
3132
// TODO: Update as needed for https://github.com/matrix-org/matrix-doc/issues/1514
@@ -69,7 +70,7 @@ export async function startAnyRegistrationFlow(
6970
if (proceed) {
7071
dis.dispatch({ action: 'start_registration', screenAfterLogin: options.screen_after });
7172
} else if (options.go_home_on_cancel) {
72-
dis.dispatch({ action: 'view_home_page' });
73+
dis.dispatch({ action: Action.ViewHomePage });
7374
} else if (options.go_welcome_on_cancel) {
7475
dis.dispatch({ action: 'view_welcome_page' });
7576
}

src/accessibility/KeyboardShortcuts.ts

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ limitations under the License.
1717

1818
import { _td } from "../languageHandler";
1919
import { isMac, Key } from "../Keyboard";
20-
import { ISetting } from "../settings/Settings";
20+
import { IBaseSetting } from "../settings/Settings";
2121
import SettingsStore from "../settings/SettingsStore";
2222
import IncompatibleController from "../settings/controllers/IncompatibleController";
2323

@@ -119,9 +119,20 @@ export enum KeyBindingAction {
119119
ToggleHiddenEventVisibility = 'KeyBinding.toggleHiddenEventVisibility',
120120
}
121121

122+
export type KeyBindingConfig = {
123+
key: string;
124+
ctrlOrCmdKey?: boolean;
125+
ctrlKey?: boolean;
126+
altKey?: boolean;
127+
shiftKey?: boolean;
128+
metaKey?: boolean;
129+
};
130+
131+
type KeyboardShortcutSetting = IBaseSetting<KeyBindingConfig>;
132+
122133
type IKeyboardShortcuts = {
123134
// TODO: We should figure out what to do with the keyboard shortcuts that are not handled by KeybindingManager
124-
[k in (KeyBindingAction | string)]: ISetting;
135+
[k in (KeyBindingAction | string)]: KeyboardShortcutSetting;
125136
};
126137

127138
export interface ICategory {
@@ -614,7 +625,11 @@ export const getKeyboardShortcuts = (): IKeyboardShortcuts => {
614625
}, {});
615626
};
616627

617-
export const registerShortcut = (shortcutName: string, categoryName: CategoryName, shortcut: ISetting): void => {
628+
export const registerShortcut = (
629+
shortcutName: string,
630+
categoryName: CategoryName,
631+
shortcut: KeyboardShortcutSetting,
632+
): void => {
618633
KEYBOARD_SHORTCUTS[shortcutName] = shortcut;
619634
CATEGORIES[categoryName].settingNames.push(shortcutName);
620635
};

src/components/structures/GroupView.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -342,7 +342,7 @@ class FeaturedUser extends React.Component {
342342
e.stopPropagation();
343343

344344
dis.dispatch({
345-
action: 'view_start_chat_or_reuse',
345+
action: Action.ViewStartChatOrReuse,
346346
user_id: this.props.summaryInfo.user_id,
347347
});
348348
};
@@ -491,7 +491,7 @@ export default class GroupView extends React.Component {
491491
if (this._unmounted || groupId !== errorGroupId) return;
492492
if (err.errcode === 'M_GUEST_ACCESS_FORBIDDEN' && !willDoOnboarding) {
493493
dis.dispatch({
494-
action: 'do_after_sync_prepared',
494+
action: Action.DoAfterSyncPrepared,
495495
deferred_action: {
496496
action: 'view_group',
497497
group_id: groupId,

src/components/structures/LoggedInView.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -490,7 +490,7 @@ class LoggedInView extends React.Component<IProps, IState> {
490490
break;
491491
case KeyBindingAction.GoToHome:
492492
dis.dispatch({
493-
action: 'view_home_page',
493+
action: Action.ViewHomePage,
494494
});
495495
Modal.closeCurrentModal("homeKeyboardShortcut");
496496
handled = true;

src/components/structures/MatrixChat.tsx

Lines changed: 20 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,10 @@ import { SummarizedNotificationState } from "../../stores/notifications/Summariz
119119
import GenericToast from '../views/toasts/GenericToast';
120120
import Views from '../../Views';
121121
import { ViewRoomPayload } from "../../dispatcher/payloads/ViewRoomPayload";
122+
import { ViewHomePagePayload } from '../../dispatcher/payloads/ViewHomePagePayload';
123+
import { AfterLeaveRoomPayload } from '../../dispatcher/payloads/AfterLeaveRoomPayload';
124+
import { DoAfterSyncPreparedPayload } from '../../dispatcher/payloads/DoAfterSyncPreparedPayload';
125+
import { ViewStartChatOrReusePayload } from '../../dispatcher/payloads/ViewStartChatOrReusePayload';
122126

123127
// legacy export
124128
export { default as Views } from "../../Views";
@@ -541,7 +545,7 @@ export default class MatrixChat extends React.PureComponent<IProps, IState> {
541545
// will cause a full login and sync and finally the deferred
542546
// action will be dispatched.
543547
dis.dispatch({
544-
action: 'do_after_sync_prepared',
548+
action: Action.DoAfterSyncPrepared,
545549
deferred_action: payload,
546550
});
547551
dis.dispatch({ action: 'require_registration' });
@@ -632,7 +636,7 @@ export default class MatrixChat extends React.PureComponent<IProps, IState> {
632636
MatrixClientPeg.get().leave(payload.room_id).then(() => {
633637
modal.close();
634638
if (this.state.currentRoomId === payload.room_id) {
635-
dis.dispatch({ action: 'view_home_page' });
639+
dis.dispatch({ action: Action.ViewHomePage });
636640
}
637641
}, (err) => {
638642
modal.close();
@@ -705,10 +709,10 @@ export default class MatrixChat extends React.PureComponent<IProps, IState> {
705709
case 'view_welcome_page':
706710
this.viewWelcome();
707711
break;
708-
case 'view_home_page':
712+
case Action.ViewHomePage:
709713
this.viewHome(payload.justRegistered);
710714
break;
711-
case 'view_start_chat_or_reuse':
715+
case Action.ViewStartChatOrReuse:
712716
this.chatCreateOrReuse(payload.user_id);
713717
break;
714718
case 'view_create_chat':
@@ -1057,10 +1061,10 @@ export default class MatrixChat extends React.PureComponent<IProps, IState> {
10571061
// No point in making 2 DMs with welcome bot. This assumes view_set_mxid will
10581062
// result in a new DM with the welcome user.
10591063
if (userId !== this.props.config.welcomeUserId) {
1060-
dis.dispatch({
1061-
action: 'do_after_sync_prepared',
1064+
dis.dispatch<DoAfterSyncPreparedPayload<ViewStartChatOrReusePayload>>({
1065+
action: Action.DoAfterSyncPrepared,
10621066
deferred_action: {
1063-
action: 'view_start_chat_or_reuse',
1067+
action: Action.ViewStartChatOrReuse,
10641068
user_id: userId,
10651069
},
10661070
});
@@ -1162,8 +1166,8 @@ export default class MatrixChat extends React.PureComponent<IProps, IState> {
11621166
if (shouldLeave) {
11631167
leaveRoomBehaviour(roomId);
11641168

1165-
dis.dispatch({
1166-
action: "after_leave_room",
1169+
dis.dispatch<AfterLeaveRoomPayload>({
1170+
action: Action.AfterLeaveRoom,
11671171
room_id: roomId,
11681172
});
11691173
}
@@ -1176,7 +1180,7 @@ export default class MatrixChat extends React.PureComponent<IProps, IState> {
11761180
MatrixClientPeg.get().forget(roomId).then(() => {
11771181
// Switch to home page if we're currently viewing the forgotten room
11781182
if (this.state.currentRoomId === roomId) {
1179-
dis.dispatch({ action: "view_home_page" });
1183+
dis.dispatch({ action: Action.ViewHomePage });
11801184
}
11811185

11821186
// We have to manually update the room list because the forgotten room will not
@@ -1275,7 +1279,7 @@ export default class MatrixChat extends React.PureComponent<IProps, IState> {
12751279
if (welcomeUserRoom === null) {
12761280
// We didn't redirect to the welcome user room, so show
12771281
// the homepage.
1278-
dis.dispatch({ action: 'view_home_page', justRegistered: true });
1282+
dis.dispatch<ViewHomePagePayload>({ action: Action.ViewHomePage, justRegistered: true });
12791283
}
12801284
} else if (ThreepidInviteStore.instance.pickBestInvite()) {
12811285
// The user has a 3pid invite pending - show them that
@@ -1288,7 +1292,7 @@ export default class MatrixChat extends React.PureComponent<IProps, IState> {
12881292
} else {
12891293
// The user has just logged in after registering,
12901294
// so show the homepage.
1291-
dis.dispatch({ action: 'view_home_page', justRegistered: true });
1295+
dis.dispatch<ViewHomePagePayload>({ action: Action.ViewHomePage, justRegistered: true });
12921296
}
12931297
} else {
12941298
this.showScreenAfterLogin();
@@ -1353,7 +1357,7 @@ export default class MatrixChat extends React.PureComponent<IProps, IState> {
13531357
if (MatrixClientPeg.get().isGuest()) {
13541358
dis.dispatch({ action: 'view_welcome_page' });
13551359
} else {
1356-
dis.dispatch({ action: 'view_home_page' });
1360+
dis.dispatch({ action: Action.ViewHomePage });
13571361
}
13581362
}
13591363
}
@@ -1666,7 +1670,7 @@ export default class MatrixChat extends React.PureComponent<IProps, IState> {
16661670
const isLoggedOutOrGuest = !cli || cli.isGuest();
16671671
if (!isLoggedOutOrGuest && AUTH_SCREENS.includes(screen)) {
16681672
// user is logged in and landing on an auth page which will uproot their session, redirect them home instead
1669-
dis.dispatch({ action: "view_home_page" });
1673+
dis.dispatch({ action: Action.ViewHomePage });
16701674
return;
16711675
}
16721676

@@ -1714,7 +1718,7 @@ export default class MatrixChat extends React.PureComponent<IProps, IState> {
17141718
});
17151719
} else if (screen === 'home') {
17161720
dis.dispatch({
1717-
action: 'view_home_page',
1721+
action: Action.ViewHomePage,
17181722
});
17191723
} else if (screen === 'start') {
17201724
this.showScreen('home');
@@ -1737,7 +1741,7 @@ export default class MatrixChat extends React.PureComponent<IProps, IState> {
17371741
PlatformPeg.get().startSingleSignOn(cli, type, this.getFragmentAfterLogin());
17381742
} else if (screen === 'groups') {
17391743
if (SpaceStore.spacesEnabled) {
1740-
dis.dispatch({ action: "view_home_page" });
1744+
dis.dispatch({ action: Action.ViewHomePage });
17411745
return;
17421746
}
17431747
dis.dispatch({

src/components/structures/RightPanel.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ import { E2EStatus } from '../../utils/ShieldUtils';
4747
import TimelineCard from '../views/right_panel/TimelineCard';
4848
import { UPDATE_EVENT } from '../../stores/AsyncStore';
4949
import { IRightPanelCard, IRightPanelCardState } from '../../stores/right-panel/RightPanelStoreIPanelState';
50+
import { Action } from '../../dispatcher/actions';
5051

5152
interface IProps {
5253
room?: Room; // if showing panels for a given room, this is set
@@ -134,7 +135,7 @@ export default class RightPanel extends React.Component<IProps, IState> {
134135
// to the home page which is not obviously the correct thing to do, but I'm not sure
135136
// anything else is - we could hide the close button altogether?)
136137
dis.dispatch({
137-
action: "view_home_page",
138+
action: Action.ViewHomePage,
138139
});
139140
} else if (
140141
this.state.phase === RightPanelPhases.EncryptionPanel &&

src/components/structures/RoomView.tsx

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,7 @@ import { ActionPayload } from "../../dispatcher/payloads";
103103
import { KeyBindingAction } from "../../accessibility/KeyboardShortcuts";
104104
import { ViewRoomPayload } from "../../dispatcher/payloads/ViewRoomPayload";
105105
import { JoinRoomPayload } from "../../dispatcher/payloads/JoinRoomPayload";
106+
import { DoAfterSyncPreparedPayload } from '../../dispatcher/payloads/DoAfterSyncPreparedPayload';
106107

107108
const DEBUG = false;
108109
let debuglog = function(msg: string) {};
@@ -1273,11 +1274,12 @@ export class RoomView extends React.Component<IRoomProps, IRoomState> {
12731274
if (this.context && this.context.isGuest()) {
12741275
// Join this room once the user has registered and logged in
12751276
// (If we failed to peek, we may not have a valid room object.)
1276-
dis.dispatch({
1277-
action: 'do_after_sync_prepared',
1277+
dis.dispatch<DoAfterSyncPreparedPayload<ViewRoomPayload>>({
1278+
action: Action.DoAfterSyncPrepared,
12781279
deferred_action: {
12791280
action: Action.ViewRoom,
12801281
room_id: this.getRoomId(),
1282+
metricsTrigger: undefined,
12811283
},
12821284
});
12831285
dis.dispatch({ action: 'require_registration' });
@@ -1568,7 +1570,7 @@ export class RoomView extends React.Component<IRoomProps, IRoomState> {
15681570
rejecting: true,
15691571
});
15701572
this.context.leave(this.state.roomId).then(() => {
1571-
dis.dispatch({ action: 'view_home_page' });
1573+
dis.dispatch({ action: Action.ViewHomePage });
15721574
this.setState({
15731575
rejecting: false,
15741576
});
@@ -1601,7 +1603,7 @@ export class RoomView extends React.Component<IRoomProps, IRoomState> {
16011603
await this.context.setIgnoredUsers(ignoredUsers);
16021604

16031605
await this.context.leave(this.state.roomId);
1604-
dis.dispatch({ action: 'view_home_page' });
1606+
dis.dispatch({ action: Action.ViewHomePage });
16051607
this.setState({
16061608
rejecting: false,
16071609
});

src/components/structures/UserMenu.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ import MatrixClientContext from "../../contexts/MatrixClientContext";
6161
import { SettingUpdatedPayload } from "../../dispatcher/payloads/SettingUpdatedPayload";
6262
import UserIdentifierCustomisations from "../../customisations/UserIdentifier";
6363
import PosthogTrackers from "../../PosthogTrackers";
64+
import { ViewHomePagePayload } from "../../dispatcher/payloads/ViewHomePagePayload";
6465

6566
const CustomStatusSection = () => {
6667
const cli = useContext(MatrixClientContext);
@@ -360,7 +361,7 @@ export default class UserMenu extends React.Component<IProps, IState> {
360361
ev.preventDefault();
361362
ev.stopPropagation();
362363

363-
defaultDispatcher.dispatch({ action: 'view_home_page' });
364+
defaultDispatcher.dispatch<ViewHomePagePayload>({ action: Action.ViewHomePage });
364365
this.setState({ contextMenuPosition: null }); // also close the menu
365366
};
366367

src/components/views/dialogs/RoomSettingsDialog.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ import SettingsStore from "../../../settings/SettingsStore";
3131
import { UIFeature } from "../../../settings/UIFeature";
3232
import { replaceableComponent } from "../../../utils/replaceableComponent";
3333
import BaseDialog from "./BaseDialog";
34+
import { Action } from '../../../dispatcher/actions';
3435

3536
export const ROOM_GENERAL_TAB = "ROOM_GENERAL_TAB";
3637
export const ROOM_SECURITY_TAB = "ROOM_SECURITY_TAB";
@@ -75,7 +76,7 @@ export default class RoomSettingsDialog extends React.Component<IProps, IState>
7576
private onAction = (payload): void => {
7677
// When view changes below us, close the room settings
7778
// whilst the modal is open this can only be triggered when someone hits Leave Room
78-
if (payload.action === 'view_home_page') {
79+
if (payload.action === Action.ViewHomePage) {
7980
this.props.onFinished(true);
8081
}
8182
};

src/components/views/dialogs/SpaceSettingsDialog.tsx

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ import SettingsStore from "../../../settings/SettingsStore";
3030
import { UIFeature } from "../../../settings/UIFeature";
3131
import AdvancedRoomSettingsTab from "../settings/tabs/room/AdvancedRoomSettingsTab";
3232
import RolesRoomSettingsTab from "../settings/tabs/room/RolesRoomSettingsTab";
33+
import { Action } from '../../../dispatcher/actions';
3334

3435
export enum SpaceSettingsTab {
3536
General = "SPACE_GENERAL_TAB",
@@ -44,8 +45,8 @@ interface IProps extends IDialogProps {
4445
}
4546

4647
const SpaceSettingsDialog: React.FC<IProps> = ({ matrixClient: cli, space, onFinished }) => {
47-
useDispatcher(defaultDispatcher, ({ action, ...params }) => {
48-
if (action === "after_leave_room" && params.room_id === space.roomId) {
48+
useDispatcher(defaultDispatcher, (payload) => {
49+
if (payload.action === Action.AfterLeaveRoom && payload.room_id === space.roomId) {
4950
onFinished(false);
5051
}
5152
});

0 commit comments

Comments
 (0)