[Glitch] Use local instead of global loading indicator for timelines, account timelines

Port dd00cd19d2 to glitch-soc
This commit is contained in:
Thibaut Girka 2018-11-09 16:47:50 +01:00 committed by ThibG
parent c5a4dc9118
commit 5ebbaffaa3
5 changed files with 38 additions and 6 deletions

View File

@ -101,6 +101,7 @@ export function expandTimelineRequest(timeline) {
return { return {
type: TIMELINE_EXPAND_REQUEST, type: TIMELINE_EXPAND_REQUEST,
timeline, timeline,
skipLoading: true,
}; };
}; };
@ -111,6 +112,7 @@ export function expandTimelineSuccess(timeline, statuses, next, partial) {
statuses, statuses,
next, next,
partial, partial,
skipLoading: true,
}; };
}; };
@ -119,6 +121,7 @@ export function expandTimelineFail(timeline, error) {
type: TIMELINE_EXPAND_FAIL, type: TIMELINE_EXPAND_FAIL,
timeline, timeline,
error, error,
skipLoading: true,
}; };
}; };

View File

@ -8,6 +8,7 @@ import { throttle } from 'lodash';
import { List as ImmutableList } from 'immutable'; import { List as ImmutableList } from 'immutable';
import classNames from 'classnames'; import classNames from 'classnames';
import { attachFullscreenListener, detachFullscreenListener, isFullscreen } from 'flavours/glitch/util/fullscreen'; import { attachFullscreenListener, detachFullscreenListener, isFullscreen } from 'flavours/glitch/util/fullscreen';
import LoadingIndicator from './loading_indicator';
export default class ScrollableList extends PureComponent { export default class ScrollableList extends PureComponent {
@ -23,6 +24,7 @@ export default class ScrollableList extends PureComponent {
trackScroll: PropTypes.bool, trackScroll: PropTypes.bool,
shouldUpdateScroll: PropTypes.func, shouldUpdateScroll: PropTypes.func,
isLoading: PropTypes.bool, isLoading: PropTypes.bool,
showLoading: PropTypes.bool,
hasMore: PropTypes.bool, hasMore: PropTypes.bool,
prepend: PropTypes.node, prepend: PropTypes.node,
emptyMessage: PropTypes.node, emptyMessage: PropTypes.node,
@ -131,12 +133,14 @@ export default class ScrollableList extends PureComponent {
getFirstChildKey (props) { getFirstChildKey (props) {
const { children } = props; const { children } = props;
let firstChild = children; let firstChild = children;
if (children instanceof ImmutableList) { if (children instanceof ImmutableList) {
firstChild = children.get(0); firstChild = children.get(0);
} else if (Array.isArray(children)) { } else if (Array.isArray(children)) {
firstChild = children[0]; firstChild = children[0];
} }
return firstChild && firstChild.key; return firstChild && firstChild.key;
} }
@ -144,7 +148,7 @@ export default class ScrollableList extends PureComponent {
this.node = c; this.node = c;
} }
handleLoadMore = (e) => { handleLoadMore = e => {
e.preventDefault(); e.preventDefault();
this.props.onLoadMore(); this.props.onLoadMore();
} }
@ -155,14 +159,26 @@ export default class ScrollableList extends PureComponent {
} }
render () { render () {
const { children, scrollKey, trackScroll, shouldUpdateScroll, isLoading, hasMore, prepend, emptyMessage, onLoadMore } = this.props; const { children, scrollKey, trackScroll, shouldUpdateScroll, showLoading, isLoading, hasMore, prepend, emptyMessage, onLoadMore } = this.props;
const { fullscreen } = this.state; const { fullscreen } = this.state;
const childrenCount = React.Children.count(children); const childrenCount = React.Children.count(children);
const loadMore = (hasMore && childrenCount > 0 && onLoadMore) ? <LoadMore visible={!isLoading} onClick={this.handleLoadMore} /> : null; const loadMore = (hasMore && childrenCount > 0 && onLoadMore) ? <LoadMore visible={!isLoading} onClick={this.handleLoadMore} /> : null;
let scrollableArea = null; let scrollableArea = null;
if (isLoading || childrenCount > 0 || !emptyMessage) { if (showLoading) {
scrollableArea = (
<div className='scrollable scrollable--flex' ref={this.setRef}>
<div role='feed' className='item-list'>
{prepend}
</div>
<div className='scrollable__append'>
<LoadingIndicator />
</div>
</div>
);
} else if (isLoading || childrenCount > 0 || !emptyMessage) {
scrollableArea = ( scrollableArea = (
<div className={classNames('scrollable', { fullscreen })} ref={this.setRef}> <div className={classNames('scrollable', { fullscreen })} ref={this.setRef}>
<div role='feed' className='item-list'> <div role='feed' className='item-list'>

View File

@ -24,7 +24,7 @@ export default class StatusList extends ImmutablePureComponent {
hasMore: PropTypes.bool, hasMore: PropTypes.bool,
prepend: PropTypes.node, prepend: PropTypes.node,
emptyMessage: PropTypes.node, emptyMessage: PropTypes.node,
timelineId: PropTypes.string.isRequired, timelineId: PropTypes.string,
}; };
static defaultProps = { static defaultProps = {
@ -121,7 +121,7 @@ export default class StatusList extends ImmutablePureComponent {
} }
return ( return (
<ScrollableList {...other} onLoadMore={onLoadMore && this.handleLoadOlder} ref={this.setRef}> <ScrollableList {...other} showLoading={isLoading && statusIds.size === 0} onLoadMore={onLoadMore && this.handleLoadOlder} ref={this.setRef}>
{scrollableContent} {scrollableContent}
</ScrollableList> </ScrollableList>
); );

View File

@ -11,6 +11,7 @@ import HeaderContainer from './containers/header_container';
import ColumnBackButton from '../../components/column_back_button'; import ColumnBackButton from '../../components/column_back_button';
import { List as ImmutableList } from 'immutable'; import { List as ImmutableList } from 'immutable';
import ImmutablePureComponent from 'react-immutable-pure-component'; import ImmutablePureComponent from 'react-immutable-pure-component';
import { FormattedMessage } from 'react-intl';
const mapStateToProps = (state, { params: { accountId }, withReplies = false }) => { const mapStateToProps = (state, { params: { accountId }, withReplies = false }) => {
const path = withReplies ? `${accountId}:with_replies` : accountId; const path = withReplies ? `${accountId}:with_replies` : accountId;
@ -77,12 +78,14 @@ export default class AccountTimeline extends ImmutablePureComponent {
<StatusList <StatusList
prepend={<HeaderContainer accountId={this.props.params.accountId} />} prepend={<HeaderContainer accountId={this.props.params.accountId} />}
alwaysPrepend
scrollKey='account_timeline' scrollKey='account_timeline'
statusIds={statusIds} statusIds={statusIds}
featuredStatusIds={featuredStatusIds} featuredStatusIds={featuredStatusIds}
isLoading={isLoading} isLoading={isLoading}
hasMore={hasMore} hasMore={hasMore}
onLoadMore={this.handleLoadMore} onLoadMore={this.handleLoadMore}
emptyMessage={<FormattedMessage id='empty_column.account_timeline' defaultMessage='No toots here!' />}
/> />
</Column> </Column>
); );

View File

@ -597,6 +597,16 @@
@supports(display: grid) { // hack to fix Chrome <57 @supports(display: grid) { // hack to fix Chrome <57
contain: strict; contain: strict;
} }
&--flex {
display: flex;
flex-direction: column;
}
&__append {
flex: 1 1 auto;
position: relative;
}
} }
.scrollable.fullscreen { .scrollable.fullscreen {