@@ -15,7 +15,7 @@ See the License for the specific language governing permissions and
1515limitations under the License.
1616*/
1717
18- import React from "react" ;
18+ import React , { useCallback } from "react" ;
1919import { MatrixEvent } from "matrix-js-sdk/src/models/event" ;
2020
2121import 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+ } ;
0 commit comments