[UI Work] Add Artist, Import Artist, Calendar

This commit is contained in:
Qstick 2017-09-07 23:09:52 -04:00
parent a747c5f135
commit 77f1d2e64c
109 changed files with 891 additions and 1082 deletions

View file

@ -0,0 +1,98 @@
import _ from 'lodash';
import $ from 'jquery';
import { batchActions } from 'redux-batched-actions';
import getNewSeries from 'Utilities/Series/getNewSeries';
import * as types from './actionTypes';
import { set, update, updateItem } from './baseActions';
let currentXHR = null;
let xhrCancelled = false;
const section = 'addArtist';
const addArtistActionHandlers = {
[types.LOOKUP_ARTIST]: function(payload) {
return function(dispatch, getState) {
dispatch(set({ section, isFetching: true }));
if (currentXHR) {
xhrCancelled = true;
currentXHR.abort();
currentXHR = null;
}
currentXHR = new window.XMLHttpRequest();
xhrCancelled = false;
const promise = $.ajax({
url: '/artist/lookup',
xhr: () => currentXHR,
data: {
term: payload.term
}
});
promise.done((data) => {
dispatch(batchActions([
update({ section, data }),
set({
section,
isFetching: false,
isPopulated: true,
error: null
})
]));
});
promise.fail((xhr) => {
dispatch(set({
section,
isFetching: false,
isPopulated: false,
error: xhrCancelled ? null : xhr
}));
});
};
},
[types.ADD_ARTIST]: function(payload) {
return function(dispatch, getState) {
dispatch(set({ section, isAdding: true }));
const foreignArtistId = payload.foreignArtistId;
const items = getState().addArtist.items;
const newSeries = getNewSeries(_.cloneDeep(_.find(items, { foreignArtistId })), payload);
const promise = $.ajax({
url: '/artist',
method: 'POST',
contentType: 'application/json',
data: JSON.stringify(newSeries)
});
promise.done((data) => {
dispatch(batchActions([
updateItem({ section: 'series', ...data }),
set({
section,
isAdding: false,
isAdded: true,
addError: null
})
]));
});
promise.fail((xhr) => {
dispatch(set({
section,
isAdding: false,
isAdded: false,
addError: xhr
}));
});
};
}
};
export default addArtistActionHandlers;