From 3e6dc0cfe7a79e104ebadf4e4125d8a62befc36d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?marcin=20miko=C5=82ajczak?= Date: Wed, 13 Jul 2022 21:03:45 +0200 Subject: [PATCH] PinnedStatuses: TS, FC MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: marcin mikołajczak --- app/soapbox/components/status_list.tsx | 2 +- app/soapbox/features/pinned_statuses/index.js | 66 ------------------- .../features/pinned_statuses/index.tsx | 51 ++++++++++++++ 3 files changed, 52 insertions(+), 67 deletions(-) delete mode 100644 app/soapbox/features/pinned_statuses/index.js create mode 100644 app/soapbox/features/pinned_statuses/index.tsx diff --git a/app/soapbox/components/status_list.tsx b/app/soapbox/components/status_list.tsx index 35edc9283..408506997 100644 --- a/app/soapbox/components/status_list.tsx +++ b/app/soapbox/components/status_list.tsx @@ -36,7 +36,7 @@ interface IStatusList extends Omit { /** ID of the timeline in Redux. */ timelineId?: string, /** Whether to display a gap or border between statuses in the list. */ - divideType: 'space' | 'border', + divideType?: 'space' | 'border', } /** Feed of statuses, built atop ScrollableList. */ diff --git a/app/soapbox/features/pinned_statuses/index.js b/app/soapbox/features/pinned_statuses/index.js deleted file mode 100644 index 9901131ba..000000000 --- a/app/soapbox/features/pinned_statuses/index.js +++ /dev/null @@ -1,66 +0,0 @@ -import PropTypes from 'prop-types'; -import React from 'react'; -import ImmutablePropTypes from 'react-immutable-proptypes'; -import ImmutablePureComponent from 'react-immutable-pure-component'; -import { defineMessages, injectIntl, FormattedMessage } from 'react-intl'; -import { connect } from 'react-redux'; - -import { fetchPinnedStatuses } from 'soapbox/actions/pin_statuses'; -import MissingIndicator from 'soapbox/components/missing_indicator'; -import StatusList from 'soapbox/components/status_list'; - -import Column from '../ui/components/column'; - -const messages = defineMessages({ - heading: { id: 'column.pins', defaultMessage: 'Pinned posts' }, -}); - -const mapStateToProps = (state, { params }) => { - const username = params.username || ''; - const me = state.get('me'); - const meUsername = state.getIn(['accounts', me, 'username'], ''); - return { - isMyAccount: (username.toLowerCase() === meUsername.toLowerCase()), - statusIds: state.status_lists.get('pins').items, - hasMore: !!state.status_lists.get('pins').next, - }; -}; - -export default @connect(mapStateToProps) -@injectIntl -class PinnedStatuses extends ImmutablePureComponent { - - static propTypes = { - dispatch: PropTypes.func.isRequired, - statusIds: ImmutablePropTypes.orderedSet.isRequired, - intl: PropTypes.object.isRequired, - hasMore: PropTypes.bool.isRequired, - isMyAccount: PropTypes.bool.isRequired, - }; - - componentDidMount() { - this.props.dispatch(fetchPinnedStatuses()); - } - - render() { - const { intl, statusIds, hasMore, isMyAccount } = this.props; - - if (!isMyAccount) { - return ( - - ); - } - - return ( - - } - /> - - ); - } - -} diff --git a/app/soapbox/features/pinned_statuses/index.tsx b/app/soapbox/features/pinned_statuses/index.tsx new file mode 100644 index 000000000..74d4d0f98 --- /dev/null +++ b/app/soapbox/features/pinned_statuses/index.tsx @@ -0,0 +1,51 @@ +import React, { useEffect } from 'react'; +import { defineMessages, FormattedMessage, useIntl } from 'react-intl'; +import { useParams } from 'react-router-dom'; + +import { fetchPinnedStatuses } from 'soapbox/actions/pin_statuses'; +import MissingIndicator from 'soapbox/components/missing_indicator'; +import StatusList from 'soapbox/components/status_list'; +import { useAppDispatch, useAppSelector } from 'soapbox/hooks'; + +import Column from '../ui/components/column'; + +const messages = defineMessages({ + heading: { id: 'column.pins', defaultMessage: 'Pinned posts' }, +}); + +const PinnedStatuses = () => { + const intl = useIntl(); + const dispatch = useAppDispatch(); + const { username } = useParams<{ username: string }>(); + + const meUsername = useAppSelector((state) => state.accounts.get(state.me)?.username || ''); + const statusIds = useAppSelector((state) => state.status_lists.get('pins')!.items); + const isLoading = useAppSelector((state) => !!state.status_lists.get('pins')!.isLoading); + const hasMore = useAppSelector((state) => !!state.status_lists.get('pins')!.next); + + const isMyAccount = username.toLowerCase() === meUsername.toLowerCase(); + + useEffect(() => { + dispatch(fetchPinnedStatuses()); + }, []); + + if (!isMyAccount) { + return ( + + ); + } + + return ( + + } + /> + + ); +}; + +export default PinnedStatuses;