Merge branch 'configurable-autoload-more' into 'develop'

ScrollableList: Add option to disable loading more items when scrolled to bottom

See merge request soapbox-pub/soapbox-fe!822
merge-requests/823/merge
Alex Gleason 2021-10-24 18:32:07 +00:00
commit f8ca45f5fb
3 zmienionych plików z 21 dodań i 2 usunięć

Wyświetl plik

@ -32,6 +32,7 @@ export const defaultSettings = ImmutableMap({
explanationBox: true, explanationBox: true,
otpEnabled: false, otpEnabled: false,
autoloadTimelines: true, autoloadTimelines: true,
autoloadMore: true,
systemFont: false, systemFont: false,
dyslexicFont: false, dyslexicFont: false,

Wyświetl plik

@ -1,5 +1,6 @@
import React, { PureComponent } from 'react'; import React, { PureComponent } from 'react';
import PropTypes from 'prop-types'; import PropTypes from 'prop-types';
import { connect } from 'react-redux';
import IntersectionObserverArticleContainer from '../containers/intersection_observer_article_container'; import IntersectionObserverArticleContainer from '../containers/intersection_observer_article_container';
import LoadMore from './load_more'; import LoadMore from './load_more';
import MoreFollows from './more_follows'; import MoreFollows from './more_follows';
@ -7,10 +8,20 @@ import IntersectionObserverWrapper from '../features/ui/util/intersection_observ
import { throttle } from 'lodash'; import { throttle } from 'lodash';
import { List as ImmutableList } from 'immutable'; import { List as ImmutableList } from 'immutable';
import LoadingIndicator from './loading_indicator'; import LoadingIndicator from './loading_indicator';
import { getSettings } from 'soapbox/actions/settings';
const MOUSE_IDLE_DELAY = 300; const MOUSE_IDLE_DELAY = 300;
export default class ScrollableList extends PureComponent { const mapStateToProps = state => {
const settings = getSettings(state);
return {
autoload: settings.get('autoloadMore'),
};
};
export default @connect(mapStateToProps)
class ScrollableList extends PureComponent {
static contextTypes = { static contextTypes = {
router: PropTypes.object, router: PropTypes.object,
@ -31,6 +42,7 @@ export default class ScrollableList extends PureComponent {
onScroll: PropTypes.func, onScroll: PropTypes.func,
placeholderComponent: PropTypes.func, placeholderComponent: PropTypes.func,
placeholderCount: PropTypes.number, placeholderCount: PropTypes.number,
autoload: PropTypes.bool,
}; };
state = { state = {
@ -126,12 +138,14 @@ export default class ScrollableList extends PureComponent {
} }
handleScroll = throttle(() => { handleScroll = throttle(() => {
const { autoload } = this.props;
if (this.window) { if (this.window) {
const { scrollTop, scrollHeight } = this.documentElement; const { scrollTop, scrollHeight } = this.documentElement;
const { innerHeight } = this.window; const { innerHeight } = this.window;
const offset = scrollHeight - scrollTop - innerHeight; const offset = scrollHeight - scrollTop - innerHeight;
if (400 > offset && this.props.onLoadMore && this.props.hasMore && !this.props.isLoading) { if (autoload && 400 > offset && this.props.onLoadMore && this.props.hasMore && !this.props.isLoading) {
this.props.onLoadMore(); this.props.onLoadMore();
} }

Wyświetl plik

@ -234,6 +234,10 @@ class Preferences extends ImmutablePureComponent {
label={<FormattedMessage id='preferences.fields.autoload_timelines_label' defaultMessage='Automatically load new posts when scrolled to the top of the page' />} label={<FormattedMessage id='preferences.fields.autoload_timelines_label' defaultMessage='Automatically load new posts when scrolled to the top of the page' />}
path={['autoloadTimelines']} path={['autoloadTimelines']}
/> />
<SettingsCheckbox
label={<FormattedMessage id='preferences.fields.autoload_more_label' defaultMessage='Automatically load more items when scrolled to the bottom of the page' />}
path={['autoloadMore']}
/>
<SettingsCheckbox <SettingsCheckbox
label={<FormattedMessage id='preferences.fields.underline_links_label' defaultMessage='Always underline links in posts' />} label={<FormattedMessage id='preferences.fields.underline_links_label' defaultMessage='Always underline links in posts' />}
path={['underlineLinks']} path={['underlineLinks']}