Set isLoading false on timelines when request fails

This commit is contained in:
Eugen Rochko 2017-01-24 13:04:12 +01:00
parent 1f5792c834
commit 21c209636d
3 changed files with 43 additions and 27 deletions

View file

@ -63,6 +63,10 @@ export function refreshTimelineRequest(timeline, id, skipLoading) {
export function refreshTimeline(timeline, id = null) { export function refreshTimeline(timeline, id = null) {
return function (dispatch, getState) { return function (dispatch, getState) {
if (getState().getIn(['timelines', timeline, 'isLoading'])) {
return;
}
const ids = getState().getIn(['timelines', timeline, 'items'], Immutable.List()); const ids = getState().getIn(['timelines', timeline, 'items'], Immutable.List());
const newestId = ids.size > 0 ? ids.first() : null; const newestId = ids.size > 0 ? ids.first() : null;
@ -102,8 +106,9 @@ export function expandTimeline(timeline, id = null) {
return (dispatch, getState) => { return (dispatch, getState) => {
const lastId = getState().getIn(['timelines', timeline, 'items'], Immutable.List()).last(); const lastId = getState().getIn(['timelines', timeline, 'items'], Immutable.List()).last();
if (!lastId) { if (!lastId || getState().getIn(['timelines', timeline, 'isLoading'])) {
// If timeline is empty, don't try to load older posts since there are none // If timeline is empty, don't try to load older posts since there are none
// Also if already loading
return; return;
} }

View file

@ -62,6 +62,7 @@ const Notifications = React.createClass({
if (trackScroll) { if (trackScroll) {
return ( return (
<Column icon='bell' heading={intl.formatMessage(messages.title)}> <Column icon='bell' heading={intl.formatMessage(messages.title)}>
<ColumnSettingsContainer />
<ScrollContainer scrollKey='notifications'> <ScrollContainer scrollKey='notifications'>
{scrollableArea} {scrollableArea}
</ScrollContainer> </ScrollContainer>

View file

@ -1,10 +1,12 @@
import { import {
TIMELINE_REFRESH_REQUEST, TIMELINE_REFRESH_REQUEST,
TIMELINE_REFRESH_SUCCESS, TIMELINE_REFRESH_SUCCESS,
TIMELINE_REFRESH_FAIL,
TIMELINE_UPDATE, TIMELINE_UPDATE,
TIMELINE_DELETE, TIMELINE_DELETE,
TIMELINE_EXPAND_SUCCESS, TIMELINE_EXPAND_SUCCESS,
TIMELINE_EXPAND_REQUEST, TIMELINE_EXPAND_REQUEST,
TIMELINE_EXPAND_FAIL,
TIMELINE_SCROLL_TOP TIMELINE_SCROLL_TOP
} from '../actions/timelines'; } from '../actions/timelines';
import { import {
@ -16,8 +18,10 @@ import {
import { import {
ACCOUNT_TIMELINE_FETCH_REQUEST, ACCOUNT_TIMELINE_FETCH_REQUEST,
ACCOUNT_TIMELINE_FETCH_SUCCESS, ACCOUNT_TIMELINE_FETCH_SUCCESS,
ACCOUNT_TIMELINE_FETCH_FAIL,
ACCOUNT_TIMELINE_EXPAND_REQUEST, ACCOUNT_TIMELINE_EXPAND_REQUEST,
ACCOUNT_TIMELINE_EXPAND_SUCCESS, ACCOUNT_TIMELINE_EXPAND_SUCCESS,
ACCOUNT_TIMELINE_EXPAND_FAIL,
ACCOUNT_BLOCK_SUCCESS ACCOUNT_BLOCK_SUCCESS
} from '../actions/accounts'; } from '../actions/accounts';
import { import {
@ -235,6 +239,9 @@ export default function timelines(state = initialState, action) {
case TIMELINE_REFRESH_REQUEST: case TIMELINE_REFRESH_REQUEST:
case TIMELINE_EXPAND_REQUEST: case TIMELINE_EXPAND_REQUEST:
return resetTimeline(state, action.timeline, action.id); return resetTimeline(state, action.timeline, action.id);
case TIMELINE_REFRESH_FAIL:
case TIMELINE_EXPAND_FAIL:
return state.setIn([action.timeline, 'isLoading'], false);
case TIMELINE_REFRESH_SUCCESS: case TIMELINE_REFRESH_SUCCESS:
return normalizeTimeline(state, action.timeline, Immutable.fromJS(action.statuses)); return normalizeTimeline(state, action.timeline, Immutable.fromJS(action.statuses));
case TIMELINE_EXPAND_SUCCESS: case TIMELINE_EXPAND_SUCCESS:
@ -248,6 +255,9 @@ export default function timelines(state = initialState, action) {
case ACCOUNT_TIMELINE_FETCH_REQUEST: case ACCOUNT_TIMELINE_FETCH_REQUEST:
case ACCOUNT_TIMELINE_EXPAND_REQUEST: case ACCOUNT_TIMELINE_EXPAND_REQUEST:
return state.updateIn(['accounts_timelines', action.id], Immutable.Map(), map => map.set('isLoading', true)); return state.updateIn(['accounts_timelines', action.id], Immutable.Map(), map => map.set('isLoading', true));
case ACCOUNT_TIMELINE_FETCH_FAIL:
case ACCOUNT_TIMELINE_EXPAND_FAIL:
return state.updateIn(['accounts_timelines', action.id], Immutable.Map(), map => map.set('isLoading', false));
case ACCOUNT_TIMELINE_FETCH_SUCCESS: case ACCOUNT_TIMELINE_FETCH_SUCCESS:
return normalizeAccountTimeline(state, action.id, Immutable.fromJS(action.statuses), action.replace); return normalizeAccountTimeline(state, action.id, Immutable.fromJS(action.statuses), action.replace);
case ACCOUNT_TIMELINE_EXPAND_SUCCESS: case ACCOUNT_TIMELINE_EXPAND_SUCCESS: