Add emoji reaction api pagination support
This commit is contained in:
parent
5fd2a57502
commit
2667e478d3
4 changed files with 104 additions and 15 deletions
|
@ -57,7 +57,12 @@ import {
|
|||
FAVOURITES_EXPAND_REQUEST,
|
||||
FAVOURITES_EXPAND_SUCCESS,
|
||||
FAVOURITES_EXPAND_FAIL,
|
||||
EMOJI_REACTIONS_FETCH_REQUEST,
|
||||
EMOJI_REACTIONS_FETCH_SUCCESS,
|
||||
EMOJI_REACTIONS_FETCH_FAIL,
|
||||
EMOJI_REACTIONS_EXPAND_REQUEST,
|
||||
EMOJI_REACTIONS_EXPAND_SUCCESS,
|
||||
EMOJI_REACTIONS_EXPAND_FAIL,
|
||||
STATUS_REFERENCES_FETCH_SUCCESS,
|
||||
} from '../actions/interactions';
|
||||
import {
|
||||
|
@ -101,12 +106,33 @@ const normalizeList = (state, path, accounts, next) => {
|
|||
}));
|
||||
};
|
||||
|
||||
const normalizeEmojiReactionList = (state, path, rows, next) => {
|
||||
return state.setIn(path, ImmutableMap({
|
||||
next,
|
||||
items: ImmutableList(rows.map(normalizeEmojiReactionRow)),
|
||||
isLoading: false,
|
||||
}));
|
||||
};
|
||||
|
||||
const appendToList = (state, path, accounts, next) => {
|
||||
return state.updateIn(path, map => {
|
||||
return map.set('next', next).set('isLoading', false).update('items', list => list.concat(accounts.map(item => item.id)));
|
||||
});
|
||||
};
|
||||
|
||||
const appendToEmojiReactionList = (state, path, rows, next) => {
|
||||
return state.updateIn(path, map => {
|
||||
return map.set('next', next).set('isLoading', false).update('items', list => list.concat(rows.map(normalizeEmojiReactionRow)));
|
||||
});
|
||||
};
|
||||
|
||||
const normalizeEmojiReactionRow = (row) => {
|
||||
const accountId = row.account ? row.account.id : 0;
|
||||
delete row.account;
|
||||
row.account_id = accountId;
|
||||
return row;
|
||||
};
|
||||
|
||||
const normalizeFollowRequest = (state, notification) => {
|
||||
return state.updateIn(['follow_requests', 'items'], list => {
|
||||
return list.filterNot(item => item === notification.account.id).unshift(notification.account.id);
|
||||
|
@ -167,8 +193,16 @@ export default function userLists(state = initialState, action) {
|
|||
case FAVOURITES_FETCH_FAIL:
|
||||
case FAVOURITES_EXPAND_FAIL:
|
||||
return state.setIn(['favourited_by', action.id, 'isLoading'], false);
|
||||
case EMOJI_REACTIONS_FETCH_REQUEST:
|
||||
case EMOJI_REACTIONS_EXPAND_REQUEST:
|
||||
return state.setIn(['emoji_reactioned_by', action.id, 'isLoading'], true);
|
||||
case EMOJI_REACTIONS_FETCH_FAIL:
|
||||
case EMOJI_REACTIONS_EXPAND_FAIL:
|
||||
return state.setIn(['emoji_reactioned_by', action.id, 'isLoading'], false);
|
||||
case EMOJI_REACTIONS_FETCH_SUCCESS:
|
||||
return state.setIn(['emoji_reactioned_by', action.id], ImmutableList(action.accounts));
|
||||
return normalizeEmojiReactionList(state, ['emoji_reactioned_by', action.id], action.accounts, action.next);
|
||||
case EMOJI_REACTIONS_EXPAND_SUCCESS:
|
||||
return appendToEmojiReactionList(state, ['emoji_reactioned_by', action.id], action.accounts, action.next);
|
||||
case STATUS_REFERENCES_FETCH_SUCCESS:
|
||||
return state.setIn(['referred_by', action.id], ImmutableList(action.statuses.map(item => item.id)));
|
||||
case NOTIFICATIONS_UPDATE:
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue