diff options
author | namelessGonbai <43787036+namelessGonbai@users.noreply.github.com> | 2018-11-06 02:52:38 +0900 |
---|---|---|
committer | Eugen Rochko <eugen@zeonfederated.com> | 2018-11-05 18:52:38 +0100 |
commit | bb5558de627ca9bc26949570025f6193cd7cbd98 (patch) | |
tree | e4bb5df10e67760271a7ab9a1a0c7272f2cca088 /app/javascript/mastodon/reducers/list_adder.js | |
parent | a7e3bd0300ee67acfe81c7727baacb0e4e34fead (diff) |
Implement adding a user to a list from their profile (#9062)
* Add add user to list from thier profile * Fix listAdderCss
Diffstat (limited to 'app/javascript/mastodon/reducers/list_adder.js')
-rw-r--r-- | app/javascript/mastodon/reducers/list_adder.js | 47 |
1 files changed, 47 insertions, 0 deletions
diff --git a/app/javascript/mastodon/reducers/list_adder.js b/app/javascript/mastodon/reducers/list_adder.js new file mode 100644 index 000000000..b8c1b0e26 --- /dev/null +++ b/app/javascript/mastodon/reducers/list_adder.js @@ -0,0 +1,47 @@ +import { Map as ImmutableMap, List as ImmutableList } from 'immutable'; +import { + LIST_ADDER_RESET, + LIST_ADDER_SETUP, + LIST_ADDER_LISTS_FETCH_REQUEST, + LIST_ADDER_LISTS_FETCH_SUCCESS, + LIST_ADDER_LISTS_FETCH_FAIL, + LIST_EDITOR_ADD_SUCCESS, + LIST_EDITOR_REMOVE_SUCCESS, +} from '../actions/lists'; + +const initialState = ImmutableMap({ + accountId: null, + + lists: ImmutableMap({ + items: ImmutableList(), + loaded: false, + isLoading: false, + }), +}); + +export default function listAdderReducer(state = initialState, action) { + switch(action.type) { + case LIST_ADDER_RESET: + return initialState; + case LIST_ADDER_SETUP: + return state.withMutations(map => { + map.set('accountId', action.account.get('id')); + }); + case LIST_ADDER_LISTS_FETCH_REQUEST: + return state.setIn(['lists', 'isLoading'], true); + case LIST_ADDER_LISTS_FETCH_FAIL: + return state.setIn(['lists', 'isLoading'], false); + case LIST_ADDER_LISTS_FETCH_SUCCESS: + return state.update('lists', lists => lists.withMutations(map => { + map.set('isLoading', false); + map.set('loaded', true); + map.set('items', ImmutableList(action.lists.map(item => item.id))); + })); + case LIST_EDITOR_ADD_SUCCESS: + return state.updateIn(['lists', 'items'], list => list.unshift(action.listId)); + case LIST_EDITOR_REMOVE_SUCCESS: + return state.updateIn(['lists', 'items'], list => list.filterNot(item => item === action.listId)); + default: + return state; + } +}; |