Convert TextualEvent and SearchResultTile to TypeScript

Signed-off-by: Robin Townsend <robin@robin.town>
pull/21833/head
Robin Townsend 2021-06-24 18:45:23 -04:00
parent f9fe28a6ad
commit e35e836052
2 changed files with 41 additions and 44 deletions

View File

@ -15,26 +15,24 @@ See the License for the specific language governing permissions and
limitations under the License. limitations under the License.
*/ */
import React from 'react'; import React from "react";
import PropTypes from 'prop-types'; import { MatrixEvent } from "matrix-js-sdk/src/models/event";
import RoomContext from "../../../contexts/RoomContext"; import RoomContext from "../../../contexts/RoomContext";
import * as TextForEvent from "../../../TextForEvent"; import * as TextForEvent from "../../../TextForEvent";
import {replaceableComponent} from "../../../utils/replaceableComponent"; import { replaceableComponent } from "../../../utils/replaceableComponent";
interface IProps {
// The event to show
mxEvent: MatrixEvent;
}
@replaceableComponent("views.messages.TextualEvent") @replaceableComponent("views.messages.TextualEvent")
export default class TextualEvent extends React.Component { export default class TextualEvent extends React.Component<IProps> {
static propTypes = {
/* the MatrixEvent to show */
mxEvent: PropTypes.object.isRequired,
};
static contextType = RoomContext; static contextType = RoomContext;
render() { public render() {
const text = TextForEvent.textForEvent(this.props.mxEvent, this.context?.showHiddenEventsInTimeline); const text = TextForEvent.textForEvent(this.props.mxEvent, this.context?.showHiddenEventsInTimeline);
if (text == null || text.length === 0) return null; if (text == null || text.length === 0) return null;
return ( return <div className="mx_TextualEvent">{ text }</div>;
<div className="mx_TextualEvent">{ text }</div>
);
} }
} }

View File

@ -15,41 +15,41 @@ See the License for the specific language governing permissions and
limitations under the License. limitations under the License.
*/ */
import React from 'react'; import React from "react";
import PropTypes from 'prop-types'; import { SearchResult } from "matrix-js-sdk/src/models/search-result";
import * as sdk from '../../../index';
import RoomContext from "../../../contexts/RoomContext"; import RoomContext from "../../../contexts/RoomContext";
import {haveTileForEvent} from "./EventTile"; import { haveTileForEvent } from "./EventTile";
import SettingsStore from "../../../settings/SettingsStore"; import SettingsStore from "../../../settings/SettingsStore";
import {UIFeature} from "../../../settings/UIFeature"; import { UIFeature } from "../../../settings/UIFeature";
import {replaceableComponent} from "../../../utils/replaceableComponent"; import { replaceableComponent } from "../../../utils/replaceableComponent";
import { RoomPermalinkCreator } from "../../../utils/permalinks/Permalinks";
import DateSeparator from "../messages/DateSeparator";
import EventTile from "./EventTile";
interface IProps {
// The details of this result
searchResult: SearchResult;
// Strings to be highlighted in the results
searchHighlights?: string[];
// href for the highlights in this result
resultLink?: string;
onHeightChanged: () => void;
permalinkCreator: RoomPermalinkCreator;
}
@replaceableComponent("views.rooms.SearchResultTile") @replaceableComponent("views.rooms.SearchResultTile")
export default class SearchResultTile extends React.Component { export default class SearchResultTile extends React.Component<IProps> {
static propTypes = {
// a matrix-js-sdk SearchResult containing the details of this result
searchResult: PropTypes.object.isRequired,
// a list of strings to be highlighted in the results
searchHighlights: PropTypes.array,
// href for the highlights in this result
resultLink: PropTypes.string,
onHeightChanged: PropTypes.func,
};
static contextType = RoomContext; static contextType = RoomContext;
render() { public render() {
const DateSeparator = sdk.getComponent('messages.DateSeparator');
const EventTile = sdk.getComponent('rooms.EventTile');
const result = this.props.searchResult; const result = this.props.searchResult;
const mxEv = result.context.getEvent(); const mxEv = result.context.getEvent();
const eventId = mxEv.getId(); const eventId = mxEv.getId();
const ts1 = mxEv.getTs(); const ts1 = mxEv.getTs();
const ret = [<DateSeparator key={ts1 + "-search"} ts={ts1} />]; const ret = [<DateSeparator key={ts1 + "-search"} ts={ts1} />];
const layout = SettingsStore.getValue("layout");
const isTwelveHour = SettingsStore.getValue("showTwelveHourTimestamps");
const alwaysShowTimestamps = SettingsStore.getValue("alwaysShowTimestamps"); const alwaysShowTimestamps = SettingsStore.getValue("alwaysShowTimestamps");
const timeline = result.context.getTimeline(); const timeline = result.context.getTimeline();
@ -61,25 +61,24 @@ export default class SearchResultTile extends React.Component {
highlights = this.props.searchHighlights; highlights = this.props.searchHighlights;
} }
if (haveTileForEvent(ev, this.context?.showHiddenEventsInTimeline)) { if (haveTileForEvent(ev, this.context?.showHiddenEventsInTimeline)) {
ret.push(( ret.push(
<EventTile <EventTile
key={`${eventId}+${j}`} key={`${eventId}+${j}`}
mxEvent={ev} mxEvent={ev}
layout={layout}
contextual={contextual} contextual={contextual}
highlights={highlights} highlights={highlights}
permalinkCreator={this.props.permalinkCreator} permalinkCreator={this.props.permalinkCreator}
highlightLink={this.props.resultLink} highlightLink={this.props.resultLink}
onHeightChanged={this.props.onHeightChanged} onHeightChanged={this.props.onHeightChanged}
isTwelveHour={SettingsStore.getValue("showTwelveHourTimestamps")} isTwelveHour={isTwelveHour}
alwaysShowTimestamps={alwaysShowTimestamps} alwaysShowTimestamps={alwaysShowTimestamps}
enableFlair={SettingsStore.getValue(UIFeature.Flair)} enableFlair={SettingsStore.getValue(UIFeature.Flair)}
/> />,
)); );
} }
} }
return (
<li data-scroll-tokens={eventId}> return <li data-scroll-tokens={eventId}>{ ret }</li>;
{ ret }
</li>);
} }
} }