.circleci
.dependabot
.github
app
chewy
controllers
helpers
javascript
fonts
images
mastodon
actions
components
containers
features
locales
middleware
reducers
accounts.js
accounts_counters.js
alerts.js
compose.js
contexts.js
conversations.js
custom_emojis.js
domain_lists.js
dropdown_menu.js
filters.js
height_cache.js
identity_proofs.js
index.js
list_adder.js
list_editor.js
lists.js
media_attachments.js
meta.js
modal.js
mutes.js
notifications.js
polls.js
push_notifications.js
relationships.js
reports.js
search.js
settings.js
status_lists.js
statuses.js
suggestions.js
timelines.js
user_lists.js
selectors
service_worker
storage
store
utils
api.js
base_polyfills.js
common.js
compare_id.js
extra_polyfills.js
initial_state.js
is_mobile.js
load_polyfills.js
main.js
performance.js
ready.js
rtl.js
scroll.js
settings.js
stream.js
test_setup.js
uuid.js
packs
styles
lib
mailers
models
policies
presenters
serializers
services
validators
views
workers
bin
config
db
dist
lib
log
nanobox
public
spec
streaming
vendor
.buildpacks
.codeclimate.yml
.dockerignore
.editorconfig
.env.nanobox
.env.production.sample
.env.test
.env.vagrant
.eslintignore
.eslintrc.js
.foreman
.gitattributes
.gitignore
.haml-lint.yml
.nanoignore
.nvmrc
.profile
.rspec
.rubocop.yml
.ruby-version
.sass-lint.yml
.slugignore
.yarnclean
AUTHORS.md
Aptfile
CHANGELOG.md
CODE_OF_CONDUCT.md
CONTRIBUTING.md
Capfile
Dockerfile
Gemfile
Gemfile.lock
LICENSE
Procfile
Procfile.dev
README.md
Rakefile
Vagrantfile
app.json
babel.config.js
boxfile.yml
config.ru
docker-compose.yml
package.json
postcss.config.js
priv-config
scalingo.json
yarn.lock
97 lines
3.0 KiB
JavaScript
97 lines
3.0 KiB
JavaScript
import { Map as ImmutableMap, List as ImmutableList } from 'immutable';
|
|
import {
|
|
LIST_CREATE_REQUEST,
|
|
LIST_CREATE_FAIL,
|
|
LIST_CREATE_SUCCESS,
|
|
LIST_UPDATE_REQUEST,
|
|
LIST_UPDATE_FAIL,
|
|
LIST_UPDATE_SUCCESS,
|
|
LIST_EDITOR_RESET,
|
|
LIST_EDITOR_SETUP,
|
|
LIST_EDITOR_TITLE_CHANGE,
|
|
LIST_ACCOUNTS_FETCH_REQUEST,
|
|
LIST_ACCOUNTS_FETCH_SUCCESS,
|
|
LIST_ACCOUNTS_FETCH_FAIL,
|
|
LIST_EDITOR_SUGGESTIONS_READY,
|
|
LIST_EDITOR_SUGGESTIONS_CLEAR,
|
|
LIST_EDITOR_SUGGESTIONS_CHANGE,
|
|
LIST_EDITOR_ADD_SUCCESS,
|
|
LIST_EDITOR_REMOVE_SUCCESS,
|
|
} from '../actions/lists';
|
|
|
|
const initialState = ImmutableMap({
|
|
listId: null,
|
|
isSubmitting: false,
|
|
isChanged: false,
|
|
title: '',
|
|
|
|
accounts: ImmutableMap({
|
|
items: ImmutableList(),
|
|
loaded: false,
|
|
isLoading: false,
|
|
}),
|
|
|
|
suggestions: ImmutableMap({
|
|
value: '',
|
|
items: ImmutableList(),
|
|
}),
|
|
});
|
|
|
|
export default function listEditorReducer(state = initialState, action) {
|
|
switch(action.type) {
|
|
case LIST_EDITOR_RESET:
|
|
return initialState;
|
|
case LIST_EDITOR_SETUP:
|
|
return state.withMutations(map => {
|
|
map.set('listId', action.list.get('id'));
|
|
map.set('title', action.list.get('title'));
|
|
map.set('isSubmitting', false);
|
|
});
|
|
case LIST_EDITOR_TITLE_CHANGE:
|
|
return state.withMutations(map => {
|
|
map.set('title', action.value);
|
|
map.set('isChanged', true);
|
|
});
|
|
case LIST_CREATE_REQUEST:
|
|
case LIST_UPDATE_REQUEST:
|
|
return state.withMutations(map => {
|
|
map.set('isSubmitting', true);
|
|
map.set('isChanged', false);
|
|
});
|
|
case LIST_CREATE_FAIL:
|
|
case LIST_UPDATE_FAIL:
|
|
return state.set('isSubmitting', false);
|
|
case LIST_CREATE_SUCCESS:
|
|
case LIST_UPDATE_SUCCESS:
|
|
return state.withMutations(map => {
|
|
map.set('isSubmitting', false);
|
|
map.set('listId', action.list.id);
|
|
});
|
|
case LIST_ACCOUNTS_FETCH_REQUEST:
|
|
return state.setIn(['accounts', 'isLoading'], true);
|
|
case LIST_ACCOUNTS_FETCH_FAIL:
|
|
return state.setIn(['accounts', 'isLoading'], false);
|
|
case LIST_ACCOUNTS_FETCH_SUCCESS:
|
|
return state.update('accounts', accounts => accounts.withMutations(map => {
|
|
map.set('isLoading', false);
|
|
map.set('loaded', true);
|
|
map.set('items', ImmutableList(action.accounts.map(item => item.id)));
|
|
}));
|
|
case LIST_EDITOR_SUGGESTIONS_CHANGE:
|
|
return state.setIn(['suggestions', 'value'], action.value);
|
|
case LIST_EDITOR_SUGGESTIONS_READY:
|
|
return state.setIn(['suggestions', 'items'], ImmutableList(action.accounts.map(item => item.id)));
|
|
case LIST_EDITOR_SUGGESTIONS_CLEAR:
|
|
return state.update('suggestions', suggestions => suggestions.withMutations(map => {
|
|
map.set('items', ImmutableList());
|
|
map.set('value', '');
|
|
}));
|
|
case LIST_EDITOR_ADD_SUCCESS:
|
|
return state.updateIn(['accounts', 'items'], list => list.unshift(action.accountId));
|
|
case LIST_EDITOR_REMOVE_SUCCESS:
|
|
return state.updateIn(['accounts', 'items'], list => list.filterNot(item => item === action.accountId));
|
|
default:
|
|
return state;
|
|
}
|
|
};
|