Add hasMore field to account timeline (#2066)
This commit is contained in:
parent
93c13fe691
commit
75910abd8f
3 changed files with 12 additions and 6 deletions
|
@ -126,7 +126,8 @@ export function expandAccountTimeline(id) {
|
||||||
max_id: lastId
|
max_id: lastId
|
||||||
}
|
}
|
||||||
}).then(response => {
|
}).then(response => {
|
||||||
dispatch(expandAccountTimelineSuccess(id, response.data));
|
const next = getLinks(response).refs.find(link => link.rel === 'next');
|
||||||
|
dispatch(expandAccountTimelineSuccess(id, response.data, next));
|
||||||
}).catch(error => {
|
}).catch(error => {
|
||||||
dispatch(expandAccountTimelineFail(id, error));
|
dispatch(expandAccountTimelineFail(id, error));
|
||||||
});
|
});
|
||||||
|
@ -257,11 +258,12 @@ export function expandAccountTimelineRequest(id) {
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
export function expandAccountTimelineSuccess(id, statuses) {
|
export function expandAccountTimelineSuccess(id, statuses, next) {
|
||||||
return {
|
return {
|
||||||
type: ACCOUNT_TIMELINE_EXPAND_SUCCESS,
|
type: ACCOUNT_TIMELINE_EXPAND_SUCCESS,
|
||||||
id,
|
id,
|
||||||
statuses
|
statuses,
|
||||||
|
next
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -46,7 +46,9 @@ const AccountTimeline = React.createClass({
|
||||||
},
|
},
|
||||||
|
|
||||||
handleScrollToBottom () {
|
handleScrollToBottom () {
|
||||||
|
if (!this.props.isLoading && this.props.hasMore) {
|
||||||
this.props.dispatch(expandAccountTimeline(Number(this.props.params.accountId)));
|
this.props.dispatch(expandAccountTimeline(Number(this.props.params.accountId)));
|
||||||
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
render () {
|
render () {
|
||||||
|
|
|
@ -144,10 +144,11 @@ const normalizeAccountTimeline = (state, accountId, statuses, replace = false) =
|
||||||
return state.updateIn(['accounts_timelines', accountId], Immutable.Map(), map => map
|
return state.updateIn(['accounts_timelines', accountId], Immutable.Map(), map => map
|
||||||
.set('isLoading', false)
|
.set('isLoading', false)
|
||||||
.set('loaded', true)
|
.set('loaded', true)
|
||||||
|
.set('next', true)
|
||||||
.update('items', Immutable.List(), list => (replace ? ids : list.unshift(...ids))));
|
.update('items', Immutable.List(), list => (replace ? ids : list.unshift(...ids))));
|
||||||
};
|
};
|
||||||
|
|
||||||
const appendNormalizedAccountTimeline = (state, accountId, statuses) => {
|
const appendNormalizedAccountTimeline = (state, accountId, statuses, next) => {
|
||||||
let moreIds = Immutable.List([]);
|
let moreIds = Immutable.List([]);
|
||||||
|
|
||||||
statuses.forEach((status, i) => {
|
statuses.forEach((status, i) => {
|
||||||
|
@ -157,6 +158,7 @@ const appendNormalizedAccountTimeline = (state, accountId, statuses) => {
|
||||||
|
|
||||||
return state.updateIn(['accounts_timelines', accountId], Immutable.Map(), map => map
|
return state.updateIn(['accounts_timelines', accountId], Immutable.Map(), map => map
|
||||||
.set('isLoading', false)
|
.set('isLoading', false)
|
||||||
|
.set('next', next)
|
||||||
.update('items', list => list.push(...moreIds)));
|
.update('items', list => list.push(...moreIds)));
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -299,7 +301,7 @@ export default function timelines(state = initialState, action) {
|
||||||
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:
|
||||||
return appendNormalizedAccountTimeline(state, action.id, Immutable.fromJS(action.statuses));
|
return appendNormalizedAccountTimeline(state, action.id, Immutable.fromJS(action.statuses), action.next);
|
||||||
case ACCOUNT_BLOCK_SUCCESS:
|
case ACCOUNT_BLOCK_SUCCESS:
|
||||||
case ACCOUNT_MUTE_SUCCESS:
|
case ACCOUNT_MUTE_SUCCESS:
|
||||||
return filterTimelines(state, action.relationship, action.statuses);
|
return filterTimelines(state, action.relationship, action.statuses);
|
||||||
|
|
Loading…
Reference in a new issue