Fix 'Automatically load more items…'

Signed-off-by: marcin mikołajczak <git@mkljczk.pl>
edit-profile-fix
marcin mikołajczak 2022-05-01 21:28:31 +02:00
rodzic 023b327751
commit d6795a55b1
2 zmienionych plików z 19 dodań i 4 usunięć

Wyświetl plik

@ -15,7 +15,7 @@ const LoadMore: React.FC<ILoadMore> = ({ onClick, disabled, visible = true }) =>
} }
return ( return (
<Button theme='secondary' block disabled={disabled || !visible} onClick={onClick}> <Button theme='primary' block disabled={disabled || !visible} onClick={onClick}>
<FormattedMessage id='status.load_more' defaultMessage='Load more' /> <FormattedMessage id='status.load_more' defaultMessage='Load more' />
</Button> </Button>
); );

Wyświetl plik

@ -1,8 +1,11 @@
import React from 'react'; import React from 'react';
import { Virtuoso, Components } from 'react-virtuoso'; import { Virtuoso, Components } from 'react-virtuoso';
import { getSettings } from 'soapbox/actions/settings';
import PullToRefresh from 'soapbox/components/pull-to-refresh'; import PullToRefresh from 'soapbox/components/pull-to-refresh';
import { useAppSelector } from 'soapbox/hooks';
import LoadMore from './load_more';
import { Spinner, Text } from './ui'; import { Spinner, Text } from './ui';
type Context = { type Context = {
@ -60,6 +63,9 @@ const ScrollableList: React.FC<IScrollableList> = ({
placeholderComponent: Placeholder, placeholderComponent: Placeholder,
placeholderCount = 0, placeholderCount = 0,
}) => { }) => {
const settings = useAppSelector((state) => getSettings(state));
const autoloadMore = settings.get('autoloadMore');
/** Normalized children */ /** Normalized children */
const elements = Array.from(children || []); const elements = Array.from(children || []);
@ -72,9 +78,9 @@ const ScrollableList: React.FC<IScrollableList> = ({
// Add a placeholder at the bottom for loading // Add a placeholder at the bottom for loading
// (Don't use Virtuoso's `Footer` component because it doesn't preserve its height) // (Don't use Virtuoso's `Footer` component because it doesn't preserve its height)
if (hasMore && Placeholder) { if (hasMore && (autoloadMore || isLoading) && Placeholder) {
data.push(<Placeholder />); data.push(<Placeholder />);
} else if (hasMore) { } else if (hasMore && (autoloadMore || isLoading)) {
data.push(<Spinner />); data.push(<Spinner />);
} }
@ -105,11 +111,19 @@ const ScrollableList: React.FC<IScrollableList> = ({
}; };
const handleEndReached = () => { const handleEndReached = () => {
if (hasMore && onLoadMore) { if (autoloadMore && hasMore && onLoadMore) {
onLoadMore(); onLoadMore();
} }
}; };
const loadMore = () => {
if (autoloadMore || !hasMore || !onLoadMore) {
return null;
} else {
return <LoadMore visible={!isLoading} onClick={onLoadMore} />;
}
};
/** Render the actual Virtuoso list */ /** Render the actual Virtuoso list */
const renderFeed = (): JSX.Element => ( const renderFeed = (): JSX.Element => (
<Virtuoso <Virtuoso
@ -130,6 +144,7 @@ const ScrollableList: React.FC<IScrollableList> = ({
EmptyPlaceholder: () => renderEmpty(), EmptyPlaceholder: () => renderEmpty(),
List, List,
Item, Item,
Footer: loadMore,
}} }}
/> />
); );