sforkowany z mirror/soapbox
StatusListContainer: convert to TSX
rodzic
8624dbd5f2
commit
878d26cb4b
|
@ -235,3 +235,4 @@ const StatusList: React.FC<IStatusList> = ({
|
|||
};
|
||||
|
||||
export default StatusList;
|
||||
export type { IStatusList };
|
||||
|
|
|
@ -1,41 +0,0 @@
|
|||
import { OrderedSet as ImmutableOrderedSet } from 'immutable';
|
||||
import { debounce } from 'lodash';
|
||||
import { connect } from 'react-redux';
|
||||
|
||||
import { dequeueTimeline } from 'soapbox/actions/timelines';
|
||||
import { scrollTopTimeline } from 'soapbox/actions/timelines';
|
||||
import StatusList from 'soapbox/components/status_list';
|
||||
import { makeGetStatusIds } from 'soapbox/selectors';
|
||||
|
||||
const makeMapStateToProps = () => {
|
||||
const getStatusIds = makeGetStatusIds();
|
||||
|
||||
const mapStateToProps = (state, { timelineId }) => {
|
||||
const lastStatusId = state.getIn(['timelines', timelineId, 'items'], ImmutableOrderedSet()).last();
|
||||
|
||||
return {
|
||||
statusIds: getStatusIds(state, { type: timelineId }),
|
||||
lastStatusId: lastStatusId,
|
||||
isLoading: state.getIn(['timelines', timelineId, 'isLoading'], true),
|
||||
isPartial: state.getIn(['timelines', timelineId, 'isPartial'], false),
|
||||
hasMore: state.getIn(['timelines', timelineId, 'hasMore']),
|
||||
totalQueuedItemsCount: state.getIn(['timelines', timelineId, 'totalQueuedItemsCount']),
|
||||
};
|
||||
};
|
||||
|
||||
return mapStateToProps;
|
||||
};
|
||||
|
||||
const mapDispatchToProps = (dispatch, ownProps) => ({
|
||||
onDequeueTimeline(timelineId) {
|
||||
dispatch(dequeueTimeline(timelineId, ownProps.onLoadMore));
|
||||
},
|
||||
onScrollToTop: debounce(() => {
|
||||
dispatch(scrollTopTimeline(ownProps.timelineId, true));
|
||||
}, 100),
|
||||
onScroll: debounce(() => {
|
||||
dispatch(scrollTopTimeline(ownProps.timelineId, false));
|
||||
}, 100),
|
||||
});
|
||||
|
||||
export default connect(makeMapStateToProps, mapDispatchToProps)(StatusList);
|
|
@ -0,0 +1,59 @@
|
|||
import { OrderedSet as ImmutableOrderedSet } from 'immutable';
|
||||
import { debounce } from 'lodash';
|
||||
import React, { useCallback } from 'react';
|
||||
|
||||
import { dequeueTimeline } from 'soapbox/actions/timelines';
|
||||
import { scrollTopTimeline } from 'soapbox/actions/timelines';
|
||||
import StatusList, { IStatusList } from 'soapbox/components/status_list';
|
||||
import { useAppSelector, useAppDispatch } from 'soapbox/hooks';
|
||||
import { makeGetStatusIds } from 'soapbox/selectors';
|
||||
|
||||
interface IStatusListContainer extends Omit<IStatusList, 'statusIds' | 'isLoading' | 'hasMore'> {
|
||||
timelineId: string,
|
||||
}
|
||||
|
||||
const StatusListContainer: React.FC<IStatusListContainer> = ({
|
||||
timelineId,
|
||||
onLoadMore,
|
||||
...rest
|
||||
}) => {
|
||||
const dispatch = useAppDispatch();
|
||||
const getStatusIds = useCallback(makeGetStatusIds, [])();
|
||||
|
||||
const lastStatusId = useAppSelector(state => state.timelines.getIn([timelineId, 'items'], ImmutableOrderedSet()).last() as string | undefined);
|
||||
const statusIds = useAppSelector(state => getStatusIds(state, { type: timelineId }));
|
||||
const isLoading = useAppSelector(state => state.timelines.getIn([timelineId, 'isLoading'], true) === true);
|
||||
const isPartial = useAppSelector(state => state.timelines.getIn([timelineId, 'isPartial'], false) === true);
|
||||
const hasMore = useAppSelector(state => state.timelines.getIn([timelineId, 'hasMore']) === true);
|
||||
const totalQueuedItemsCount = useAppSelector(state => state.timelines.getIn([timelineId, 'totalQueuedItemsCount']));
|
||||
|
||||
const handleDequeueTimeline = (timelineId: string) => {
|
||||
dispatch(dequeueTimeline(timelineId, onLoadMore));
|
||||
};
|
||||
|
||||
const handleScrollToTop = useCallback(debounce(() => {
|
||||
dispatch(scrollTopTimeline(timelineId, true));
|
||||
}, 100), []);
|
||||
|
||||
const handleScroll = useCallback(debounce(() => {
|
||||
dispatch(scrollTopTimeline(timelineId, false));
|
||||
}, 100), []);
|
||||
|
||||
return (
|
||||
<StatusList
|
||||
onDequeueTimeline={handleDequeueTimeline}
|
||||
onScrollToTop={handleScrollToTop}
|
||||
onScroll={handleScroll}
|
||||
lastStatusId={lastStatusId}
|
||||
statusIds={statusIds}
|
||||
isLoading={isLoading}
|
||||
isPartial={isPartial}
|
||||
hasMore={hasMore}
|
||||
totalQueuedItemsCount={totalQueuedItemsCount}
|
||||
onLoadMore={onLoadMore}
|
||||
{...rest}
|
||||
/>
|
||||
);
|
||||
};
|
||||
|
||||
export default StatusListContainer;
|
|
@ -365,7 +365,7 @@ export const makeGetStatusIds = () => createSelector([
|
|||
(state: RootState, { type, prefix }: ColumnQuery) => getSettings(state).get(prefix || type, ImmutableMap()),
|
||||
(state: RootState, { type }: ColumnQuery) => state.timelines.getIn([type, 'items'], ImmutableOrderedSet()),
|
||||
(state: RootState) => state.statuses,
|
||||
], (columnSettings, statusIds: string[], statuses) => {
|
||||
], (columnSettings, statusIds: ImmutableOrderedSet<string>, statuses) => {
|
||||
return statusIds.filter((id: string) => {
|
||||
const status = statuses.get(id);
|
||||
if (!status) return true;
|
||||
|
|
Ładowanie…
Reference in New Issue