Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix #3665 - Refactor timelines reducer #3686

Merged
merged 7 commits into from
Jun 11, 2017
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
6 changes: 2 additions & 4 deletions app/javascript/mastodon/actions/notifications.js
Original file line number Diff line number Diff line change
Expand Up @@ -124,10 +124,9 @@ export function refreshNotificationsFail(error, skipLoading) {

export function expandNotifications() {
return (dispatch, getState) => {
const url = getState().getIn(['notifications', 'next'], null);
const lastId = getState().getIn(['notifications', 'items']).last();
Copy link
Contributor

@unarist unarist Jun 11, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, lastId is whole entity, not id...


if (url === null || getState().getIn(['notifications', 'isLoading'])) {
if (getState().getIn(['notifications', 'isLoading'])) {
return;
}

Expand All @@ -140,9 +139,8 @@ export function expandNotifications() {

params.exclude_types = excludeTypesFromSettings(getState());

api(getState).get(url, params).then(response => {
api(getState).get('/api/v1/notifications', { params }).then(response => {
const next = getLinks(response).refs.find(link => link.rel === 'next');

dispatch(expandNotificationsSuccess(response.data, next ? next.uri : null));
fetchRelatedRelationships(dispatch, response.data);
}).catch(error => {
Expand Down
4 changes: 2 additions & 2 deletions app/javascript/mastodon/reducers/timelines.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,13 @@ const initialState = Immutable.Map();
const normalizeTimeline = (state, timeline, statuses, next) => {
const ids = Immutable.List(statuses.map(status => status.get('id')));
const wasLoaded = state.getIn([timeline, 'loaded']);
const hadNext = state.getIn([timeline, 'next']) === null;
const hadNext = state.getIn([timeline, 'next']);
const oldIds = state.getIn([timeline, 'items'], Immutable.List());

return state.update(timeline, Immutable.Map(), map => map.withMutations(mMap => {
mMap.set('loaded', true);
mMap.set('isLoading', false);
mMap.set('next', next);
if (!hadNext) mMap.set('next', next);
mMap.set('items', wasLoaded ? ids.concat(oldIds) : ids);
}));
};
Expand Down