Adding following/followers lists to the UI

This commit is contained in:
Eugen Rochko 2016-10-27 21:59:56 +02:00
parent 909d0d5e88
commit 1c84d505c8
16 changed files with 369 additions and 30 deletions

View file

@ -6,6 +6,8 @@ import follow from './follow';
import notifications from './notifications';
import { loadingBarReducer } from 'react-redux-loading-bar';
import modal from './modal';
import user_lists from './user_lists';
import suggestions from './suggestions';
export default combineReducers({
timelines,
@ -15,4 +17,6 @@ export default combineReducers({
notifications,
loadingBar: loadingBarReducer,
modal,
user_lists,
suggestions
});

View file

@ -0,0 +1,13 @@
import { SUGGESTIONS_FETCH_SUCCESS } from '../actions/suggestions';
import Immutable from 'immutable';
const initialState = Immutable.List();
export default function suggestions(state = initialState, action) {
switch(action.type) {
case SUGGESTIONS_FETCH_SUCCESS:
return Immutable.List(action.accounts.map(item => item.id));
default:
return state;
}
}

View file

@ -18,7 +18,9 @@ import {
ACCOUNT_BLOCK_SUCCESS,
ACCOUNT_UNBLOCK_SUCCESS,
ACCOUNT_TIMELINE_FETCH_SUCCESS,
ACCOUNT_TIMELINE_EXPAND_SUCCESS
ACCOUNT_TIMELINE_EXPAND_SUCCESS,
FOLLOWERS_FETCH_SUCCESS,
FOLLOWING_FETCH_SUCCESS
} from '../actions/accounts';
import {
STATUS_FETCH_SUCCESS,
@ -206,12 +208,12 @@ function normalizeContext(state, status, ancestors, descendants) {
});
};
function normalizeSuggestions(state, accounts) {
function normalizeAccounts(state, accounts) {
accounts.forEach(account => {
state = state.setIn(['accounts', account.get('id')], account);
});
return state.set('suggestions', accounts.map(account => account.get('id')));
return state;
};
export default function timelines(state = initialState, action) {
@ -247,7 +249,9 @@ export default function timelines(state = initialState, action) {
case ACCOUNT_TIMELINE_EXPAND_SUCCESS:
return appendNormalizedAccountTimeline(state, action.id, Immutable.fromJS(action.statuses));
case SUGGESTIONS_FETCH_SUCCESS:
return normalizeSuggestions(state, Immutable.fromJS(action.suggestions));
case FOLLOWERS_FETCH_SUCCESS:
case FOLLOWING_FETCH_SUCCESS:
return normalizeAccounts(state, Immutable.fromJS(action.accounts));
default:
return state;
}

View file

@ -0,0 +1,21 @@
import {
FOLLOWERS_FETCH_SUCCESS,
FOLLOWING_FETCH_SUCCESS
} from '../actions/accounts';
import Immutable from 'immutable';
const initialState = Immutable.Map({
followers: Immutable.Map(),
following: Immutable.Map()
});
export default function userLists(state = initialState, action) {
switch(action.type) {
case FOLLOWERS_FETCH_SUCCESS:
return state.setIn(['followers', action.id], Immutable.List(action.accounts.map(item => item.id)));
case FOLLOWING_FETCH_SUCCESS:
return state.setIn(['following', action.id], Immutable.List(action.accounts.map(item => item.id)));
default:
return state;
}
};