New groups

This commit is contained in:
2458773093
2019-07-15 16:47:05 +03:00
parent fd50f03304
commit 1fabd28498
30 changed files with 809 additions and 285 deletions

View File

@@ -0,0 +1,21 @@
import { Map as ImmutableMap, List as ImmutableList } from 'immutable';
import { GROUPS_FETCH_SUCCESS } from '../actions/groups';
const initialState = ImmutableMap({
featured: ImmutableList(),
member: ImmutableList(),
admin: ImmutableList(),
});
const normalizeList = (state, type, id, groups) => {
return state.set(type, ImmutableList(groups.map(item => item.id)));
};
export default function groupLists(state = initialState, action) {
switch(action.type) {
case GROUPS_FETCH_SUCCESS:
return normalizeList(state, action.tab, action.id, action.groups);
default:
return state;
}
};

View File

@@ -34,6 +34,7 @@ import identity_proofs from './identity_proofs';
import trends from './trends';
import groups from './groups';
import group_relationships from './group_relationships';
import group_lists from './group_lists';
const reducers = {
dropdown_menu,
@@ -71,6 +72,7 @@ const reducers = {
trends,
groups,
group_relationships,
group_lists,
};
export default combineReducers(reducers);

View File

@@ -21,6 +21,10 @@ import {
MUTES_EXPAND_SUCCESS,
} from '../actions/mutes';
import { Map as ImmutableMap, List as ImmutableList } from 'immutable';
import {
GROUP_MEMBERS_FETCH_SUCCESS,
GROUP_MEMBERS_EXPAND_SUCCESS,
} from '../actions/groups';
const initialState = ImmutableMap({
followers: ImmutableMap(),
@@ -30,6 +34,7 @@ const initialState = ImmutableMap({
follow_requests: ImmutableMap(),
blocks: ImmutableMap(),
mutes: ImmutableMap(),
groups: ImmutableMap(),
});
const normalizeList = (state, type, id, accounts, next) => {
@@ -74,6 +79,10 @@ export default function userLists(state = initialState, action) {
return state.setIn(['mutes', 'items'], ImmutableList(action.accounts.map(item => item.id))).setIn(['mutes', 'next'], action.next);
case MUTES_EXPAND_SUCCESS:
return state.updateIn(['mutes', 'items'], list => list.concat(action.accounts.map(item => item.id))).setIn(['mutes', 'next'], action.next);
case GROUP_MEMBERS_FETCH_SUCCESS:
return normalizeList(state, 'groups', action.id, action.accounts, action.next);
case GROUP_MEMBERS_EXPAND_SUCCESS:
return appendToList(state, 'groups', action.id, action.accounts, action.next);
default:
return state;
}