diff --git a/web/modals/history/history-revision.react.js b/web/modals/history/history-revision.react.js index f7d24420e..76ed80c97 100644 --- a/web/modals/history/history-revision.react.js +++ b/web/modals/history/history-revision.react.js @@ -1,84 +1,67 @@ // @flow import classNames from 'classnames'; import dateFormat from 'dateformat'; -import PropTypes from 'prop-types'; import * as React from 'react'; import TimeAgo from 'react-timeago'; import { threadInfoSelector } from 'lib/selectors/thread-selectors'; import { colorIsDark } from 'lib/shared/thread-utils'; import type { HistoryRevisionInfo } from 'lib/types/history-types'; -import { historyRevisionInfoPropType } from 'lib/types/history-types'; -import type { ThreadInfo } from 'lib/types/thread-types'; -import { threadInfoPropType } from 'lib/types/thread-types'; -import { connect } from 'lib/utils/redux-utils'; -import type { AppState } from '../../redux/redux-setup'; +import { useSelector } from '../../redux/redux-utils'; import css from './history.css'; -type Props = { - revisionInfo: HistoryRevisionInfo, - threadInfo: ThreadInfo, - isDeletionOrRestoration: boolean, -}; +type Props = {| + +revisionInfo: HistoryRevisionInfo, + +isDeletionOrRestoration: boolean, +|}; -class HistoryRevision extends React.PureComponent { - render() { - let change; - if (this.props.isDeletionOrRestoration && this.props.revisionInfo.deleted) { - change =
Deleted
; - } else if (this.props.isDeletionOrRestoration) { - change =
Restored
; - } else { - const textClasses = classNames({ - [css.entry]: true, - [css.darkEntry]: colorIsDark(this.props.threadInfo.color), - }); - const textStyle = { backgroundColor: '#' + this.props.threadInfo.color }; - change = ( -
- {this.props.revisionInfo.text} -
- ); - } - - const author = - this.props.revisionInfo.author === null ? ( - 'Anonymous' - ) : ( - - {this.props.revisionInfo.author} - - ); - - const date = new Date(this.props.revisionInfo.lastUpdate); - const hovertext = dateFormat(date, "dddd, mmmm dS, yyyy 'at' h:MM TT"); - return ( -
  • - {change} - - {'updated by '} - {author} - - -
    -
  • +export default function HistoryRevision(props: Props) { + const threadInfo = useSelector( + (state) => threadInfoSelector(state)[props.revisionInfo.threadID], + ); + let change; + if (props.isDeletionOrRestoration && props.revisionInfo.deleted) { + change =
    Deleted
    ; + } else if (props.isDeletionOrRestoration) { + change =
    Restored
    ; + } else { + const textClasses = classNames({ + [css.entry]: true, + [css.darkEntry]: colorIsDark(threadInfo.color), + }); + const textStyle = { backgroundColor: '#' + threadInfo.color }; + change = ( +
    + {props.revisionInfo.text} +
    ); } -} -HistoryRevision.propTypes = { - revisionInfo: historyRevisionInfoPropType, - threadInfo: threadInfoPropType, - isDeletionOrRestoration: PropTypes.bool.isRequired, -}; + const author = + props.revisionInfo.author === null ? ( + 'Anonymous' + ) : ( + {props.revisionInfo.author} + ); + + const date = new Date(props.revisionInfo.lastUpdate); + const hovertext = dateFormat(date, "dddd, mmmm dS, yyyy 'at' h:MM TT"); -type OwnProps = { revisionInfo: HistoryRevisionInfo }; -export default connect((state: AppState, ownProps: OwnProps) => ({ - threadInfo: threadInfoSelector(state)[ownProps.revisionInfo.threadID], -}))(HistoryRevision); + return ( +
  • + {change} + + {'updated by '} + {author} + + +
    +
  • + ); +}