diff --git a/app/soapbox/components/scrollable_list.tsx b/app/soapbox/components/scrollable_list.tsx index d38706437..ce35228c8 100644 --- a/app/soapbox/components/scrollable_list.tsx +++ b/app/soapbox/components/scrollable_list.tsx @@ -6,6 +6,7 @@ import PullToRefresh from 'soapbox/components/pull-to-refresh'; import { Spinner, Text } from './ui'; +// Ensure the className winds up here const List = React.forwardRef((props: any, ref: React.ForwardedRef) => { const { context, ...rest } = props; return
; @@ -29,8 +30,10 @@ interface IScrollableList { className?: string, } +/** Legacy ScrollableList with Virtuoso for backwards-compatibility */ const ScrollableList: React.FC = ({ prepend = null, + alwaysPrepend, children, isLoading, emptyMessage, @@ -40,6 +43,7 @@ const ScrollableList: React.FC = ({ onScrollToTop, onLoadMore, className, + hasMore, placeholderComponent: Placeholder, placeholderCount = 0, }) => { @@ -47,7 +51,26 @@ const ScrollableList: React.FC = ({ // const autoload = settings.get('autoloadMore'); const showPlaceholder = showLoading && Placeholder && placeholderCount > 0; + const data = showPlaceholder ? Array(placeholderCount).fill('') : Array.from(children || []); + /* Render an empty state instead of the scrollable list */ + const renderEmpty = () => { + return ( +
+ {alwaysPrepend && prepend} + +
+ {isLoading ? ( + + ) : ( + {emptyMessage} + )} +
+
+ ); + }; + + /** Render the actual item */ const renderItem = (_i: number, element: JSX.Element) => { if (showPlaceholder) { return ; @@ -56,12 +79,22 @@ const ScrollableList: React.FC = ({ } }; + // Don't use Virtuoso's EmptyPlaceholder component so it preserves height + if (data.length === 0) { + return renderEmpty(); + } + + // Don't use Virtuoso's Footer component so it preserves spacing + if (hasMore && Placeholder) { + data.push(); + } + return ( isScrolling && onScroll && onScroll()} @@ -72,11 +105,7 @@ const ScrollableList: React.FC = ({ components={{ Header: () => prepend, ScrollSeekPlaceholder: Placeholder as any, - EmptyPlaceholder: () => isLoading ? ( - - ) : ( - {emptyMessage} - ), + EmptyPlaceholder: () => renderEmpty(), List, }} />