type Actions (#7862)

* type ViewHomPage action

Signed-off-by: Kerry Archibald <kerrya@element.io>

* type spacestore actions

Signed-off-by: Kerry Archibald <kerrya@element.io>

* lint

Signed-off-by: Kerry Archibald <kerrya@element.io>

* add action types

Signed-off-by: Kerry Archibald <kerrya@element.io>

* use new action types in stores

Signed-off-by: Kerry Archibald <kerrya@element.io>

* remove debug change

Signed-off-by: Kerry Archibald <kerrya@element.io>

* stricter keyboard shortcut types

Signed-off-by: Kerry Archibald <kerrya@element.io>

* action comments

Signed-off-by: Kerry Archibald <kerrya@element.io>
This commit is contained in:
Kerry 2022-02-22 11:04:27 +01:00 committed by GitHub
parent 57595bc593
commit 5b8d440406
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
33 changed files with 304 additions and 73 deletions

View file

@ -342,7 +342,7 @@ class FeaturedUser extends React.Component {
e.stopPropagation();
dis.dispatch({
action: 'view_start_chat_or_reuse',
action: Action.ViewStartChatOrReuse,
user_id: this.props.summaryInfo.user_id,
});
};
@ -491,7 +491,7 @@ export default class GroupView extends React.Component {
if (this._unmounted || groupId !== errorGroupId) return;
if (err.errcode === 'M_GUEST_ACCESS_FORBIDDEN' && !willDoOnboarding) {
dis.dispatch({
action: 'do_after_sync_prepared',
action: Action.DoAfterSyncPrepared,
deferred_action: {
action: 'view_group',
group_id: groupId,

View file

@ -490,7 +490,7 @@ class LoggedInView extends React.Component<IProps, IState> {
break;
case KeyBindingAction.GoToHome:
dis.dispatch({
action: 'view_home_page',
action: Action.ViewHomePage,
});
Modal.closeCurrentModal("homeKeyboardShortcut");
handled = true;

View file

@ -119,6 +119,10 @@ import { SummarizedNotificationState } from "../../stores/notifications/Summariz
import GenericToast from '../views/toasts/GenericToast';
import Views from '../../Views';
import { ViewRoomPayload } from "../../dispatcher/payloads/ViewRoomPayload";
import { ViewHomePagePayload } from '../../dispatcher/payloads/ViewHomePagePayload';
import { AfterLeaveRoomPayload } from '../../dispatcher/payloads/AfterLeaveRoomPayload';
import { DoAfterSyncPreparedPayload } from '../../dispatcher/payloads/DoAfterSyncPreparedPayload';
import { ViewStartChatOrReusePayload } from '../../dispatcher/payloads/ViewStartChatOrReusePayload';
// legacy export
export { default as Views } from "../../Views";
@ -541,7 +545,7 @@ export default class MatrixChat extends React.PureComponent<IProps, IState> {
// will cause a full login and sync and finally the deferred
// action will be dispatched.
dis.dispatch({
action: 'do_after_sync_prepared',
action: Action.DoAfterSyncPrepared,
deferred_action: payload,
});
dis.dispatch({ action: 'require_registration' });
@ -632,7 +636,7 @@ export default class MatrixChat extends React.PureComponent<IProps, IState> {
MatrixClientPeg.get().leave(payload.room_id).then(() => {
modal.close();
if (this.state.currentRoomId === payload.room_id) {
dis.dispatch({ action: 'view_home_page' });
dis.dispatch({ action: Action.ViewHomePage });
}
}, (err) => {
modal.close();
@ -705,10 +709,10 @@ export default class MatrixChat extends React.PureComponent<IProps, IState> {
case 'view_welcome_page':
this.viewWelcome();
break;
case 'view_home_page':
case Action.ViewHomePage:
this.viewHome(payload.justRegistered);
break;
case 'view_start_chat_or_reuse':
case Action.ViewStartChatOrReuse:
this.chatCreateOrReuse(payload.user_id);
break;
case 'view_create_chat':
@ -1057,10 +1061,10 @@ export default class MatrixChat extends React.PureComponent<IProps, IState> {
// No point in making 2 DMs with welcome bot. This assumes view_set_mxid will
// result in a new DM with the welcome user.
if (userId !== this.props.config.welcomeUserId) {
dis.dispatch({
action: 'do_after_sync_prepared',
dis.dispatch<DoAfterSyncPreparedPayload<ViewStartChatOrReusePayload>>({
action: Action.DoAfterSyncPrepared,
deferred_action: {
action: 'view_start_chat_or_reuse',
action: Action.ViewStartChatOrReuse,
user_id: userId,
},
});
@ -1162,8 +1166,8 @@ export default class MatrixChat extends React.PureComponent<IProps, IState> {
if (shouldLeave) {
leaveRoomBehaviour(roomId);
dis.dispatch({
action: "after_leave_room",
dis.dispatch<AfterLeaveRoomPayload>({
action: Action.AfterLeaveRoom,
room_id: roomId,
});
}
@ -1176,7 +1180,7 @@ export default class MatrixChat extends React.PureComponent<IProps, IState> {
MatrixClientPeg.get().forget(roomId).then(() => {
// Switch to home page if we're currently viewing the forgotten room
if (this.state.currentRoomId === roomId) {
dis.dispatch({ action: "view_home_page" });
dis.dispatch({ action: Action.ViewHomePage });
}
// 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> {
if (welcomeUserRoom === null) {
// We didn't redirect to the welcome user room, so show
// the homepage.
dis.dispatch({ action: 'view_home_page', justRegistered: true });
dis.dispatch<ViewHomePagePayload>({ action: Action.ViewHomePage, justRegistered: true });
}
} else if (ThreepidInviteStore.instance.pickBestInvite()) {
// The user has a 3pid invite pending - show them that
@ -1288,7 +1292,7 @@ export default class MatrixChat extends React.PureComponent<IProps, IState> {
} else {
// The user has just logged in after registering,
// so show the homepage.
dis.dispatch({ action: 'view_home_page', justRegistered: true });
dis.dispatch<ViewHomePagePayload>({ action: Action.ViewHomePage, justRegistered: true });
}
} else {
this.showScreenAfterLogin();
@ -1353,7 +1357,7 @@ export default class MatrixChat extends React.PureComponent<IProps, IState> {
if (MatrixClientPeg.get().isGuest()) {
dis.dispatch({ action: 'view_welcome_page' });
} else {
dis.dispatch({ action: 'view_home_page' });
dis.dispatch({ action: Action.ViewHomePage });
}
}
}
@ -1666,7 +1670,7 @@ export default class MatrixChat extends React.PureComponent<IProps, IState> {
const isLoggedOutOrGuest = !cli || cli.isGuest();
if (!isLoggedOutOrGuest && AUTH_SCREENS.includes(screen)) {
// user is logged in and landing on an auth page which will uproot their session, redirect them home instead
dis.dispatch({ action: "view_home_page" });
dis.dispatch({ action: Action.ViewHomePage });
return;
}
@ -1714,7 +1718,7 @@ export default class MatrixChat extends React.PureComponent<IProps, IState> {
});
} else if (screen === 'home') {
dis.dispatch({
action: 'view_home_page',
action: Action.ViewHomePage,
});
} else if (screen === 'start') {
this.showScreen('home');
@ -1737,7 +1741,7 @@ export default class MatrixChat extends React.PureComponent<IProps, IState> {
PlatformPeg.get().startSingleSignOn(cli, type, this.getFragmentAfterLogin());
} else if (screen === 'groups') {
if (SpaceStore.spacesEnabled) {
dis.dispatch({ action: "view_home_page" });
dis.dispatch({ action: Action.ViewHomePage });
return;
}
dis.dispatch({

View file

@ -47,6 +47,7 @@ import { E2EStatus } from '../../utils/ShieldUtils';
import TimelineCard from '../views/right_panel/TimelineCard';
import { UPDATE_EVENT } from '../../stores/AsyncStore';
import { IRightPanelCard, IRightPanelCardState } from '../../stores/right-panel/RightPanelStoreIPanelState';
import { Action } from '../../dispatcher/actions';
interface IProps {
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> {
// to the home page which is not obviously the correct thing to do, but I'm not sure
// anything else is - we could hide the close button altogether?)
dis.dispatch({
action: "view_home_page",
action: Action.ViewHomePage,
});
} else if (
this.state.phase === RightPanelPhases.EncryptionPanel &&

View file

@ -103,6 +103,7 @@ import { ActionPayload } from "../../dispatcher/payloads";
import { KeyBindingAction } from "../../accessibility/KeyboardShortcuts";
import { ViewRoomPayload } from "../../dispatcher/payloads/ViewRoomPayload";
import { JoinRoomPayload } from "../../dispatcher/payloads/JoinRoomPayload";
import { DoAfterSyncPreparedPayload } from '../../dispatcher/payloads/DoAfterSyncPreparedPayload';
const DEBUG = false;
let debuglog = function(msg: string) {};
@ -1273,11 +1274,12 @@ export class RoomView extends React.Component<IRoomProps, IRoomState> {
if (this.context && this.context.isGuest()) {
// Join this room once the user has registered and logged in
// (If we failed to peek, we may not have a valid room object.)
dis.dispatch({
action: 'do_after_sync_prepared',
dis.dispatch<DoAfterSyncPreparedPayload<ViewRoomPayload>>({
action: Action.DoAfterSyncPrepared,
deferred_action: {
action: Action.ViewRoom,
room_id: this.getRoomId(),
metricsTrigger: undefined,
},
});
dis.dispatch({ action: 'require_registration' });
@ -1568,7 +1570,7 @@ export class RoomView extends React.Component<IRoomProps, IRoomState> {
rejecting: true,
});
this.context.leave(this.state.roomId).then(() => {
dis.dispatch({ action: 'view_home_page' });
dis.dispatch({ action: Action.ViewHomePage });
this.setState({
rejecting: false,
});
@ -1601,7 +1603,7 @@ export class RoomView extends React.Component<IRoomProps, IRoomState> {
await this.context.setIgnoredUsers(ignoredUsers);
await this.context.leave(this.state.roomId);
dis.dispatch({ action: 'view_home_page' });
dis.dispatch({ action: Action.ViewHomePage });
this.setState({
rejecting: false,
});

View file

@ -61,6 +61,7 @@ import MatrixClientContext from "../../contexts/MatrixClientContext";
import { SettingUpdatedPayload } from "../../dispatcher/payloads/SettingUpdatedPayload";
import UserIdentifierCustomisations from "../../customisations/UserIdentifier";
import PosthogTrackers from "../../PosthogTrackers";
import { ViewHomePagePayload } from "../../dispatcher/payloads/ViewHomePagePayload";
const CustomStatusSection = () => {
const cli = useContext(MatrixClientContext);
@ -360,7 +361,7 @@ export default class UserMenu extends React.Component<IProps, IState> {
ev.preventDefault();
ev.stopPropagation();
defaultDispatcher.dispatch({ action: 'view_home_page' });
defaultDispatcher.dispatch<ViewHomePagePayload>({ action: Action.ViewHomePage });
this.setState({ contextMenuPosition: null }); // also close the menu
};

View file

@ -31,6 +31,7 @@ import SettingsStore from "../../../settings/SettingsStore";
import { UIFeature } from "../../../settings/UIFeature";
import { replaceableComponent } from "../../../utils/replaceableComponent";
import BaseDialog from "./BaseDialog";
import { Action } from '../../../dispatcher/actions';
export const ROOM_GENERAL_TAB = "ROOM_GENERAL_TAB";
export const ROOM_SECURITY_TAB = "ROOM_SECURITY_TAB";
@ -75,7 +76,7 @@ export default class RoomSettingsDialog extends React.Component<IProps, IState>
private onAction = (payload): void => {
// When view changes below us, close the room settings
// whilst the modal is open this can only be triggered when someone hits Leave Room
if (payload.action === 'view_home_page') {
if (payload.action === Action.ViewHomePage) {
this.props.onFinished(true);
}
};

View file

@ -30,6 +30,7 @@ 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';
export enum SpaceSettingsTab {
General = "SPACE_GENERAL_TAB",
@ -44,8 +45,8 @@ interface IProps extends IDialogProps {
}
const SpaceSettingsDialog: React.FC<IProps> = ({ matrixClient: cli, space, onFinished }) => {
useDispatcher(defaultDispatcher, ({ action, ...params }) => {
if (action === "after_leave_room" && params.room_id === space.roomId) {
useDispatcher(defaultDispatcher, (payload) => {
if (payload.action === Action.AfterLeaveRoom && payload.room_id === space.roomId) {
onFinished(false);
}
});

View file

@ -49,6 +49,7 @@ import RoomViewStore from '../../../stores/RoomViewStore';
import WidgetUtils from '../../../utils/WidgetUtils';
import MatrixClientContext from "../../../contexts/MatrixClientContext";
import { ActionPayload } from "../../../dispatcher/payloads";
import { Action } from '../../../dispatcher/actions';
interface IProps {
app: IApp;
@ -447,7 +448,7 @@ export default class AppTile extends React.Component<IProps, IState> {
}
break;
case "after_leave_room":
case Action.AfterLeaveRoom:
if (payload.room_id === this.props.room?.roomId) {
// call this before we get it echoed down /sync, so it doesn't hang around as long and look jarring
this.onUserLeftRoom();

View file

@ -24,13 +24,14 @@ import {
ICategory,
CATEGORIES,
CategoryName,
KeyBindingConfig,
} from "../../../../../accessibility/KeyboardShortcuts";
import SdkConfig from "../../../../../SdkConfig";
import { isMac, Key } from "../../../../../Keyboard";
import { _t } from "../../../../../languageHandler";
// TODO: This should return KeyCombo but it has ctrlOrCmd instead of ctrlOrCmdKey
const getKeyboardShortcutValue = (name: string) => {
const getKeyboardShortcutValue = (name: string): KeyBindingConfig => {
return getKeyboardShortcuts()[name]?.default;
};