From 1a4401ce75725d46990f4c461fda45ac68aee796 Mon Sep 17 00:00:00 2001 From: Alex Gleason Date: Mon, 4 Apr 2022 15:20:17 -0500 Subject: [PATCH] Convert ThreadStatus to tsx --- app/soapbox/components/status.tsx | 6 +- app/soapbox/components/status_action_bar.tsx | 11 ++-- .../status/components/thread-status.tsx | 51 +++++++++++++++ .../status/components/thread_status.js | 64 ------------------- app/soapbox/features/status/index.tsx | 4 +- 5 files changed, 60 insertions(+), 76 deletions(-) create mode 100644 app/soapbox/features/status/components/thread-status.tsx delete mode 100644 app/soapbox/features/status/components/thread_status.js diff --git a/app/soapbox/components/status.tsx b/app/soapbox/components/status.tsx index 8276bed34..ffb3fba09 100644 --- a/app/soapbox/components/status.tsx +++ b/app/soapbox/components/status.tsx @@ -87,8 +87,8 @@ interface IStatus extends RouteComponentProps { muted: boolean, hidden: boolean, unread: boolean, - onMoveUp: (statusId: string, featured: string) => void, - onMoveDown: (statusId: string, featured: string) => void, + onMoveUp: (statusId: string, featured?: string) => void, + onMoveDown: (statusId: string, featured?: string) => void, getScrollPosition?: () => ScrollPosition | undefined, updateScrollBottom?: (bottom: number) => void, cacheMediaWidth: () => void, @@ -658,8 +658,8 @@ class Status extends ImmutablePureComponent { {quote} void, onOpenReblogsModal: (acct: string, statusId: string) => void, @@ -718,9 +718,6 @@ const mapDispatchToProps = (dispatch: Dispatch, { status }: { status: Status}) = }, }); +const WrappedComponent = withRouter(injectIntl(StatusActionBar)); // @ts-ignore -export default withRouter(injectIntl( - // @ts-ignore - connect(mapStateToProps, mapDispatchToProps, null, { forwardRef: true }, - // @ts-ignore - )(StatusActionBar))); +export default connect(mapStateToProps, mapDispatchToProps, null, { forwardRef: true })(WrappedComponent); diff --git a/app/soapbox/features/status/components/thread-status.tsx b/app/soapbox/features/status/components/thread-status.tsx new file mode 100644 index 000000000..13a486756 --- /dev/null +++ b/app/soapbox/features/status/components/thread-status.tsx @@ -0,0 +1,51 @@ +import classNames from 'classnames'; +import { OrderedSet as ImmutableOrderedSet } from 'immutable'; +import React from 'react'; + +import StatusContainer from 'soapbox/containers/status_container'; +import PlaceholderStatus from 'soapbox/features/placeholder/components/placeholder_status'; +import { useAppSelector } from 'soapbox/hooks'; + +interface IThreadStatus { + id: string, + focusedStatusId: string, +} + +const ThreadStatus: React.FC = (props): JSX.Element => { + const { id, focusedStatusId } = props; + + const replyToId = useAppSelector(state => state.contexts.getIn(['inReplyTos', id])); + const replyCount = useAppSelector(state => state.contexts.getIn(['replies', id], ImmutableOrderedSet()).size); + const isLoaded = useAppSelector(state => Boolean(state.statuses.get(id))); + + const renderConnector = (): JSX.Element | null => { + const isConnectedTop = replyToId && replyToId !== focusedStatusId; + const isConnectedBottom = replyCount > 0; + const isConnected = isConnectedTop || isConnectedBottom; + + if (!isConnected) return null; + + return ( +
+ ); + }; + + return ( +
+ {renderConnector()} + {isLoaded ? ( + // @ts-ignore FIXME + + ) : ( + + )} +
+ ); +}; + +export default ThreadStatus; diff --git a/app/soapbox/features/status/components/thread_status.js b/app/soapbox/features/status/components/thread_status.js deleted file mode 100644 index bfb79e452..000000000 --- a/app/soapbox/features/status/components/thread_status.js +++ /dev/null @@ -1,64 +0,0 @@ -import classNames from 'classnames'; -import { OrderedSet as ImmutableOrderedSet } from 'immutable'; -import PropTypes from 'prop-types'; -import React from 'react'; -import { connect } from 'react-redux'; - -import StatusContainer from 'soapbox/containers/status_container'; -import PlaceholderStatus from 'soapbox/features/placeholder/components/placeholder_status'; - -const mapStateToProps = (state, { id }) => { - return { - replyToId: state.getIn(['contexts', 'inReplyTos', id]), - replyCount: state.getIn(['contexts', 'replies', id], ImmutableOrderedSet()).size, - isLoaded: Boolean(state.getIn(['statuses', id])), - }; -}; - -export default @connect(mapStateToProps) -class ThreadStatus extends React.Component { - - static propTypes = { - focusedStatusId: PropTypes.string, - replyToId: PropTypes.string, - replyCount: PropTypes.number, - isLoaded: PropTypes.bool, - } - - renderConnector() { - const { focusedStatusId, replyToId, replyCount } = this.props; - - const isConnectedTop = replyToId && replyToId !== focusedStatusId; - const isConnectedBottom = replyCount > 0; - const isConnected = isConnectedTop || isConnectedBottom; - - if (!isConnected) { - return null; - } - - return ( -
- ); - } - - render() { - const { isLoaded } = this.props; - - return ( -
- {this.renderConnector()} - {isLoaded ? ( - - ) : ( - - )} -
- ); - } - -} diff --git a/app/soapbox/features/status/index.tsx b/app/soapbox/features/status/index.tsx index 04971be0e..46442b704 100644 --- a/app/soapbox/features/status/index.tsx +++ b/app/soapbox/features/status/index.tsx @@ -59,7 +59,7 @@ import { attachFullscreenListener, detachFullscreenListener, isFullscreen } from import ActionBar from './components/action-bar'; import DetailedStatus from './components/detailed_status'; -import ThreadStatus from './components/thread_status'; +import ThreadStatus from './components/thread-status'; import type { AxiosError } from 'axios'; import type { History } from 'history'; @@ -558,9 +558,9 @@ class Status extends ImmutablePureComponent { key={id} id={id} focusedStatusId={status.id} + // @ts-ignore FIXME onMoveUp={this.handleMoveUp} onMoveDown={this.handleMoveDown} - contextType='thread' /> ); }