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

Commit 97d0599

Browse files
committed
Convert RoomCreate to a functional component
1 parent 9c7c5a4 commit 97d0599

File tree

3 files changed

+41
-41
lines changed

3 files changed

+41
-41
lines changed

src/components/views/messages/RoomCreate.tsx

Lines changed: 39 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ See the License for the specific language governing permissions and
1515
limitations under the License.
1616
*/
1717

18-
import React from "react";
18+
import React, { useCallback } from "react";
1919
import { MatrixEvent } from "matrix-js-sdk/src/models/event";
2020

2121
import dis from "../../../dispatcher/dispatcher";
@@ -36,44 +36,44 @@ interface IProps {
3636
* A message tile showing that this room was created as an upgrade of a previous
3737
* room.
3838
*/
39-
export default class RoomCreate extends React.Component<IProps> {
40-
private onLinkClicked = (e: React.MouseEvent): void => {
41-
e.preventDefault();
39+
export const RoomCreate: React.FC<IProps> = ({ mxEvent, timestamp }) => {
40+
const onLinkClicked = useCallback(
41+
(e: React.MouseEvent): void => {
42+
e.preventDefault();
4243

43-
const predecessor = this.props.mxEvent.getContent()["predecessor"];
44+
const predecessor = mxEvent.getContent()["predecessor"];
4445

45-
dis.dispatch<ViewRoomPayload>({
46-
action: Action.ViewRoom,
47-
event_id: predecessor["event_id"],
48-
highlighted: true,
49-
room_id: predecessor["room_id"],
50-
metricsTrigger: "Predecessor",
51-
metricsViaKeyboard: e.type !== "click",
52-
});
53-
};
54-
55-
public render(): JSX.Element {
56-
const predecessor = this.props.mxEvent.getContent()["predecessor"];
57-
if (predecessor === undefined) {
58-
return <div />; // We should never have been instantiated in this case
59-
}
60-
const prevRoom = MatrixClientPeg.get().getRoom(predecessor["room_id"]);
61-
const permalinkCreator = new RoomPermalinkCreator(prevRoom, predecessor["room_id"]);
62-
permalinkCreator.load();
63-
const predecessorPermalink = permalinkCreator.forEvent(predecessor["event_id"]);
64-
const link = (
65-
<a href={predecessorPermalink} onClick={this.onLinkClicked}>
66-
{_t("Click here to see older messages.")}
67-
</a>
68-
);
69-
70-
return (
71-
<EventTileBubble
72-
className="mx_CreateEvent"
73-
title={_t("This room is a continuation of another conversation.")}
74-
subtitle={link}
75-
timestamp={this.props.timestamp}
76-
/>
77-
);
46+
dis.dispatch<ViewRoomPayload>({
47+
action: Action.ViewRoom,
48+
event_id: predecessor["event_id"],
49+
highlighted: true,
50+
room_id: predecessor["room_id"],
51+
metricsTrigger: "Predecessor",
52+
metricsViaKeyboard: e.type !== "click",
53+
});
54+
},
55+
[mxEvent],
56+
);
57+
const predecessor = mxEvent.getContent()["predecessor"];
58+
if (predecessor === undefined) {
59+
return <div />; // We should never have been instantiated in this case
7860
}
79-
}
61+
const prevRoom = MatrixClientPeg.get().getRoom(predecessor["room_id"]);
62+
const permalinkCreator = new RoomPermalinkCreator(prevRoom, predecessor["room_id"]);
63+
permalinkCreator.load();
64+
const predecessorPermalink = permalinkCreator.forEvent(predecessor["event_id"]);
65+
const link = (
66+
<a href={predecessorPermalink} onClick={onLinkClicked}>
67+
{_t("Click here to see older messages.")}
68+
</a>
69+
);
70+
71+
return (
72+
<EventTileBubble
73+
className="mx_CreateEvent"
74+
title={_t("This room is a continuation of another conversation.")}
75+
subtitle={link}
76+
timestamp={timestamp}
77+
/>
78+
);
79+
};

src/events/EventTileFactory.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ import LegacyCallEvent from "../components/views/messages/LegacyCallEvent";
3333
import { CallEvent } from "../components/views/messages/CallEvent";
3434
import TextualEvent from "../components/views/messages/TextualEvent";
3535
import EncryptionEvent from "../components/views/messages/EncryptionEvent";
36-
import RoomCreate from "../components/views/messages/RoomCreate";
36+
import { RoomCreate } from "../components/views/messages/RoomCreate";
3737
import RoomAvatarEvent from "../components/views/messages/RoomAvatarEvent";
3838
import { WIDGET_LAYOUT_EVENT_TYPE } from "../stores/widgets/WidgetLayoutStore";
3939
import { ALL_RULE_TYPES } from "../mjolnir/BanList";

test/components/views/messages/RoomCreate-test.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ import { EventType, MatrixEvent } from "matrix-js-sdk/src/matrix";
2121

2222
import dis from "../../../../src/dispatcher/dispatcher";
2323
import SettingsStore from "../../../../src/settings/SettingsStore";
24-
import RoomCreate from "../../../../src/components/views/messages/RoomCreate";
24+
import { RoomCreate } from "../../../../src/components/views/messages/RoomCreate";
2525
import { stubClient } from "../../../test-utils/test-utils";
2626
import { Action } from "../../../../src/dispatcher/actions";
2727

0 commit comments

Comments
 (0)