StatusList TypeScript fixes

This commit is contained in:
Alex Gleason 2022-06-02 14:00:35 -05:00
parent d0d9c0b460
commit a185ad45cd
No known key found for this signature in database
GPG Key ID: 7211D1F99744FBB7
7 changed files with 32 additions and 26 deletions

View File

@ -9,8 +9,8 @@ const messages = defineMessages({
interface ILoadGap { interface ILoadGap {
disabled?: boolean, disabled?: boolean,
maxId: string | null, maxId: string,
onClick: (id: string | null) => void, onClick: (id: string) => void,
} }
const LoadGap: React.FC<ILoadGap> = ({ disabled, maxId, onClick }) => { const LoadGap: React.FC<ILoadGap> = ({ disabled, maxId, onClick }) => {

View File

@ -212,3 +212,4 @@ const ScrollableList = React.forwardRef<VirtuosoHandle, IScrollableList>(({
}); });
export default ScrollableList; export default ScrollableList;
export type { IScrollableList };

View File

@ -101,6 +101,7 @@ interface IStatus extends RouteComponentProps {
focusable: boolean, focusable: boolean,
history: History, history: History,
featured?: boolean, featured?: boolean,
withDismiss?: boolean,
} }
interface IStatusState { interface IStatusState {

View File

@ -16,31 +16,32 @@ import type {
OrderedSet as ImmutableOrderedSet, OrderedSet as ImmutableOrderedSet,
} from 'immutable'; } from 'immutable';
import type { VirtuosoHandle } from 'react-virtuoso'; import type { VirtuosoHandle } from 'react-virtuoso';
import type { IScrollableList } from 'soapbox/components/scrollable_list';
const messages = defineMessages({ const messages = defineMessages({
queue: { id: 'status_list.queue_label', defaultMessage: 'Click to see {count} new {count, plural, one {post} other {posts}}' }, queue: { id: 'status_list.queue_label', defaultMessage: 'Click to see {count} new {count, plural, one {post} other {posts}}' },
}); });
interface IStatusList { interface IStatusList extends Omit<IScrollableList, 'onLoadMore' | 'children'> {
scrollKey: string, scrollKey: string,
statusIds: ImmutableOrderedSet<string>, statusIds: ImmutableOrderedSet<string>,
lastStatusId: string, lastStatusId?: string,
featuredStatusIds?: ImmutableOrderedSet<string>, featuredStatusIds?: ImmutableOrderedSet<string>,
onLoadMore: (lastStatusId: string | null) => void, onLoadMore?: (lastStatusId: string) => void,
isLoading: boolean, isLoading: boolean,
isPartial: boolean, isPartial?: boolean,
hasMore: boolean, hasMore: boolean,
prepend: React.ReactNode, prepend?: React.ReactNode,
emptyMessage: React.ReactNode, emptyMessage: React.ReactNode,
alwaysPrepend: boolean, alwaysPrepend?: boolean,
timelineId: string, timelineId?: string,
queuedItemSize: number, queuedItemSize?: number,
onDequeueTimeline: (timelineId: string) => void, onDequeueTimeline?: (timelineId: string) => void,
totalQueuedItemsCount: number, totalQueuedItemsCount?: number,
group?: ImmutableMap<string, any>, group?: ImmutableMap<string, any>,
withGroupAdmin: boolean, withGroupAdmin?: boolean,
onScrollToTop: () => void, onScrollToTop?: () => void,
onScroll: () => void, onScroll?: () => void,
divideType: 'space' | 'border', divideType: 'space' | 'border',
} }
@ -85,7 +86,7 @@ const StatusList: React.FC<IStatusList> = ({
const handleLoadOlder = useCallback(debounce(() => { const handleLoadOlder = useCallback(debounce(() => {
const loadMoreID = lastStatusId || statusIds.last(); const loadMoreID = lastStatusId || statusIds.last();
if (loadMoreID) { if (onLoadMore && loadMoreID) {
onLoadMore(loadMoreID); onLoadMore(loadMoreID);
} }
}, 300, { leading: true }), []); }, 300, { leading: true }), []);
@ -108,12 +109,16 @@ const StatusList: React.FC<IStatusList> = ({
const renderLoadGap = (index: number) => { const renderLoadGap = (index: number) => {
const ids = statusIds.toList(); const ids = statusIds.toList();
const nextId = ids.get(index + 1);
const prevId = ids.get(index - 1);
if (index < 1 || !nextId || !prevId || !onLoadMore) return null;
return ( return (
<LoadGap <LoadGap
key={'gap:' + ids.get(index + 1)} key={'gap:' + nextId}
disabled={isLoading} disabled={isLoading}
maxId={index > 0 ? ids.get(index - 1) || null : null} maxId={prevId!}
onClick={onLoadMore} onClick={onLoadMore}
/> />
); );
@ -143,7 +148,7 @@ const StatusList: React.FC<IStatusList> = ({
); );
}; };
const renderFeaturedStatuses = (): JSX.Element[] => { const renderFeaturedStatuses = (): React.ReactNode[] => {
if (!featuredStatusIds) return []; if (!featuredStatusIds) return [];
return featuredStatusIds.toArray().map(statusId => ( return featuredStatusIds.toArray().map(statusId => (
@ -159,7 +164,7 @@ const StatusList: React.FC<IStatusList> = ({
)); ));
}; };
const renderStatuses = (): JSX.Element[] => { const renderStatuses = (): React.ReactNode[] => {
if (isLoading || statusIds.size > 0) { if (isLoading || statusIds.size > 0) {
return statusIds.toArray().map((statusId, index) => { return statusIds.toArray().map((statusId, index) => {
if (statusId === null) { if (statusId === null) {

View File

@ -1,13 +1,12 @@
import { debounce } from 'lodash'; import { debounce } from 'lodash';
import React from 'react'; import React from 'react';
import { defineMessages, FormattedMessage, useIntl } from 'react-intl'; import { defineMessages, FormattedMessage, useIntl } from 'react-intl';
import { useDispatch } from 'react-redux';
import { fetchBookmarkedStatuses, expandBookmarkedStatuses } from 'soapbox/actions/bookmarks'; import { fetchBookmarkedStatuses, expandBookmarkedStatuses } from 'soapbox/actions/bookmarks';
import StatusList from 'soapbox/components/status_list'; import StatusList from 'soapbox/components/status_list';
import SubNavigation from 'soapbox/components/sub_navigation'; import SubNavigation from 'soapbox/components/sub_navigation';
import { Column } from 'soapbox/components/ui'; import { Column } from 'soapbox/components/ui';
import { useAppSelector } from 'soapbox/hooks'; import { useAppSelector, useAppDispatch } from 'soapbox/hooks';
const messages = defineMessages({ const messages = defineMessages({
heading: { id: 'column.bookmarks', defaultMessage: 'Bookmarks' }, heading: { id: 'column.bookmarks', defaultMessage: 'Bookmarks' },
@ -18,7 +17,7 @@ const handleLoadMore = debounce((dispatch) => {
}, 300, { leading: true }); }, 300, { leading: true });
const Bookmarks: React.FC = () => { const Bookmarks: React.FC = () => {
const dispatch = useDispatch(); const dispatch = useAppDispatch();
const intl = useIntl(); const intl = useIntl();
const statusIds = useAppSelector((state) => state.status_lists.getIn(['bookmarks', 'items'])); const statusIds = useAppSelector((state) => state.status_lists.getIn(['bookmarks', 'items']));
@ -42,7 +41,7 @@ const Bookmarks: React.FC = () => {
</div> </div>
<StatusList <StatusList
statusIds={statusIds} statusIds={statusIds}
scrollKey={'bookmarked_statuses'} scrollKey='bookmarked_statuses'
hasMore={hasMore} hasMore={hasMore}
isLoading={isLoading} isLoading={isLoading}
onLoadMore={() => handleLoadMore(dispatch)} onLoadMore={() => handleLoadMore(dispatch)}

View File

@ -48,8 +48,8 @@ const Conversation: React.FC<IConversation> = ({ conversationId, onMoveUp, onMov
} }
return ( return (
<StatusContainer
// @ts-ignore // @ts-ignore
<StatusContainer
id={lastStatusId} id={lastStatusId}
unread={unread} unread={unread}
otherAccounts={accounts} otherAccounts={accounts}

View File

@ -260,8 +260,8 @@ const Notification: React.FC<INotificaton> = (props) => {
case 'poll': case 'poll':
case 'pleroma:emoji_reaction': case 'pleroma:emoji_reaction':
return status && typeof status === 'object' ? ( return status && typeof status === 'object' ? (
<StatusContainer
// @ts-ignore // @ts-ignore
<StatusContainer
id={status.id} id={status.id}
withDismiss withDismiss
hidden={hidden} hidden={hidden}