When showing thread, always auto-focus its composer (#8115)

This commit is contained in:
Michael Telatynski
2022-03-23 10:54:40 +00:00
committed by GitHub
parent a8d65ab5c5
commit d9276426fa
3 changed files with 26 additions and 34 deletions
@@ -24,7 +24,6 @@ import { MsgType, RelationType } from 'matrix-js-sdk/src/@types/event';
import type { Relations } from 'matrix-js-sdk/src/models/relations'; import type { Relations } from 'matrix-js-sdk/src/models/relations';
import { _t } from '../../../languageHandler'; import { _t } from '../../../languageHandler';
import dis from '../../../dispatcher/dispatcher'; import dis from '../../../dispatcher/dispatcher';
import { Action } from '../../../dispatcher/actions';
import ContextMenu, { aboveLeftOf, ContextMenuTooltipButton, useContextMenu } from '../../structures/ContextMenu'; import ContextMenu, { aboveLeftOf, ContextMenuTooltipButton, useContextMenu } from '../../structures/ContextMenu';
import { isContentActionable, canEditContent, editEvent } from '../../../utils/EventUtils'; import { isContentActionable, canEditContent, editEvent } from '../../../utils/EventUtils';
import RoomContext, { TimelineRenderingType } from "../../../contexts/RoomContext"; import RoomContext, { TimelineRenderingType } from "../../../contexts/RoomContext";
@@ -225,10 +224,6 @@ export default class MessageActionBar extends React.PureComponent<IMessageAction
private onThreadClick = (isCard: boolean): void => { private onThreadClick = (isCard: boolean): void => {
showThread({ rootEvent: this.props.mxEvent, push: isCard }); showThread({ rootEvent: this.props.mxEvent, push: isCard });
dis.dispatch({
action: Action.FocusSendMessageComposer,
context: TimelineRenderingType.Thread,
});
}; };
private onEditClick = (): void => { private onEditClick = (): void => {
@@ -202,16 +202,7 @@ class EditMessageComposer extends React.Component<IEditMessageComposerProps, ISt
timelineRenderingType: this.context.timelineRenderingType, timelineRenderingType: this.context.timelineRenderingType,
}); });
} else { } else {
this.clearStoredEditorState(); this.cancelEdit();
dis.dispatch({
action: Action.EditEvent,
event: null,
timelineRenderingType: this.context.timelineRenderingType,
});
dis.dispatch({
action: Action.FocusSendMessageComposer,
context: this.context.timelineRenderingType,
});
} }
event.preventDefault(); event.preventDefault();
break; break;
@@ -219,6 +210,19 @@ class EditMessageComposer extends React.Component<IEditMessageComposerProps, ISt
} }
}; };
private endEdit(): void {
// close the event editing and focus composer
dis.dispatch({
action: Action.EditEvent,
event: null,
timelineRenderingType: this.context.timelineRenderingType,
});
dis.dispatch({
action: Action.FocusSendMessageComposer,
context: this.context.timelineRenderingType,
});
}
private get editorRoomKey(): string { private get editorRoomKey(): string {
return `mx_edit_room_${this.getRoom().roomId}_${this.context.timelineRenderingType}`; return `mx_edit_room_${this.getRoom().roomId}_${this.context.timelineRenderingType}`;
} }
@@ -236,15 +240,7 @@ class EditMessageComposer extends React.Component<IEditMessageComposerProps, ISt
private cancelEdit = (): void => { private cancelEdit = (): void => {
this.clearStoredEditorState(); this.clearStoredEditorState();
dis.dispatch({ this.endEdit();
action: Action.EditEvent,
event: null,
timelineRenderingType: this.context.timelineRenderingType,
});
dis.dispatch({
action: Action.FocusSendMessageComposer,
context: this.context.timelineRenderingType,
});
}; };
private get shouldSaveStoredEditorState(): boolean { private get shouldSaveStoredEditorState(): boolean {
@@ -357,16 +353,7 @@ class EditMessageComposer extends React.Component<IEditMessageComposerProps, ISt
} }
} }
// close the event editing and focus composer this.endEdit();
dis.dispatch({
action: Action.EditEvent,
event: null,
timelineRenderingType: this.context.timelineRenderingType,
});
dis.dispatch({
action: Action.FocusSendMessageComposer,
context: this.context.timelineRenderingType,
});
}; };
private cancelPreviousPendingEdit(): void { private cancelPreviousPendingEdit(): void {
@@ -13,10 +13,14 @@ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and See the License for the specific language governing permissions and
limitations under the License. limitations under the License.
*/ */
import { MatrixEvent } from "matrix-js-sdk/src/models/event"; import { MatrixEvent } from "matrix-js-sdk/src/models/event";
import RightPanelStore from "../../stores/right-panel/RightPanelStore"; import RightPanelStore from "../../stores/right-panel/RightPanelStore";
import { RightPanelPhases } from "../../stores/right-panel/RightPanelStorePhases"; import { RightPanelPhases } from "../../stores/right-panel/RightPanelStorePhases";
import dis from "../dispatcher";
import { Action } from "../actions";
import { TimelineRenderingType } from "../../contexts/RoomContext";
export const showThread = (props: { export const showThread = (props: {
rootEvent: MatrixEvent; rootEvent: MatrixEvent;
@@ -41,6 +45,12 @@ export const showThread = (props: {
threadViewCard, threadViewCard,
]); ]);
} }
// Focus the composer
dis.dispatch({
action: Action.FocusSendMessageComposer,
context: TimelineRenderingType.Thread,
});
}; };
export const showThreadPanel = () => { export const showThreadPanel = () => {