mirror of
https://github.com/lidarr/lidarr.git
synced 2025-07-31 04:00:18 -07:00
[UI] Refactor TrackFile Modal
This commit is contained in:
parent
e3c6bc3263
commit
9be4ec4c15
43 changed files with 280 additions and 290 deletions
|
@ -95,11 +95,11 @@ export const CLEAR_TRACKS = 'CLEAR_TRACKS';
|
|||
//
|
||||
// Episode Files
|
||||
|
||||
export const FETCH_EPISODE_FILES = 'FETCH_EPISODE_FILES';
|
||||
export const CLEAR_EPISODE_FILES = 'CLEAR_EPISODE_FILES';
|
||||
export const DELETE_EPISODE_FILE = 'DELETE_EPISODE_FILE';
|
||||
export const DELETE_EPISODE_FILES = 'DELETE_EPISODE_FILES';
|
||||
export const UPDATE_EPISODE_FILES = 'UPDATE_EPISODE_FILES';
|
||||
export const FETCH_TRACK_FILES = 'FETCH_TRACK_FILES';
|
||||
export const CLEAR_TRACK_FILES = 'CLEAR_TRACK_FILES';
|
||||
export const DELETE_TRACK_FILE = 'DELETE_TRACK_FILE';
|
||||
export const DELETE_TRACK_FILES = 'DELETE_TRACK_FILES';
|
||||
export const UPDATE_TRACK_FILES = 'UPDATE_TRACK_FILES';
|
||||
|
||||
//
|
||||
// Episode History
|
||||
|
|
|
@ -1,9 +0,0 @@
|
|||
import { createAction } from 'redux-actions';
|
||||
import * as types from './actionTypes';
|
||||
import episodeFileActionHandlers from './episodeFileActionHandlers';
|
||||
|
||||
export const fetchEpisodeFiles = episodeFileActionHandlers[types.FETCH_EPISODE_FILES];
|
||||
export const deleteEpisodeFile = episodeFileActionHandlers[types.DELETE_EPISODE_FILE];
|
||||
export const deleteEpisodeFiles = episodeFileActionHandlers[types.DELETE_EPISODE_FILES];
|
||||
export const updateEpisodeFiles = episodeFileActionHandlers[types.UPDATE_EPISODE_FILES];
|
||||
export const clearEpisodeFiles = createAction(types.CLEAR_EPISODE_FILES);
|
|
@ -7,33 +7,33 @@ import createRemoveItemHandler from './Creators/createRemoveItemHandler';
|
|||
import * as types from './actionTypes';
|
||||
import { set, removeItem, updateItem } from './baseActions';
|
||||
|
||||
const section = 'episodeFiles';
|
||||
const deleteEpisodeFile = createRemoveItemHandler(section, '/trackFile');
|
||||
const section = 'trackFiles';
|
||||
const deleteTrackFile = createRemoveItemHandler(section, '/trackFile');
|
||||
|
||||
const episodeFileActionHandlers = {
|
||||
[types.FETCH_EPISODE_FILES]: createFetchHandler(section, '/trackFile'),
|
||||
const trackFileActionHandlers = {
|
||||
[types.FETCH_TRACK_FILES]: createFetchHandler(section, '/trackFile'),
|
||||
|
||||
[types.DELETE_EPISODE_FILE]: function(payload) {
|
||||
[types.DELETE_TRACK_FILE]: function(payload) {
|
||||
return function(dispatch, getState) {
|
||||
const {
|
||||
id: episodeFileId,
|
||||
id: trackFileId,
|
||||
episodeEntity = episodeEntities.EPISODES
|
||||
} = payload;
|
||||
|
||||
const episodeSection = _.last(episodeEntity.split('.'));
|
||||
|
||||
const deletePromise = deleteEpisodeFile(payload)(dispatch, getState);
|
||||
const deletePromise = deleteTrackFile(payload)(dispatch, getState);
|
||||
|
||||
deletePromise.done(() => {
|
||||
const episodes = getState().episodes.items;
|
||||
const episodesWithRemovedFiles = _.filter(episodes, { episodeFileId });
|
||||
const episodesWithRemovedFiles = _.filter(episodes, { trackFileId });
|
||||
|
||||
dispatch(batchActions([
|
||||
...episodesWithRemovedFiles.map((episode) => {
|
||||
return updateItem({
|
||||
section: episodeSection,
|
||||
...episode,
|
||||
episodeFileId: 0,
|
||||
trackFileId: 0,
|
||||
hasFile: false
|
||||
});
|
||||
})
|
||||
|
@ -42,31 +42,31 @@ const episodeFileActionHandlers = {
|
|||
};
|
||||
},
|
||||
|
||||
[types.DELETE_EPISODE_FILES]: function(payload) {
|
||||
[types.DELETE_TRACK_FILES]: function(payload) {
|
||||
return function(dispatch, getState) {
|
||||
const {
|
||||
episodeFileIds
|
||||
trackFileIds
|
||||
} = payload;
|
||||
|
||||
dispatch(set({ section, isDeleting: true }));
|
||||
|
||||
const promise = $.ajax({
|
||||
url: '/episodeFile/bulk',
|
||||
url: '/trackFile/bulk',
|
||||
method: 'DELETE',
|
||||
dataType: 'json',
|
||||
data: JSON.stringify({ episodeFileIds })
|
||||
data: JSON.stringify({ trackFileIds })
|
||||
});
|
||||
|
||||
promise.done(() => {
|
||||
const episodes = getState().episodes.items;
|
||||
const episodesWithRemovedFiles = episodeFileIds.reduce((acc, episodeFileId) => {
|
||||
acc.push(..._.filter(episodes, { episodeFileId }));
|
||||
const episodesWithRemovedFiles = trackFileIds.reduce((acc, trackFileId) => {
|
||||
acc.push(..._.filter(episodes, { trackFileId }));
|
||||
|
||||
return acc;
|
||||
}, []);
|
||||
|
||||
dispatch(batchActions([
|
||||
...episodeFileIds.map((id) => {
|
||||
...trackFileIds.map((id) => {
|
||||
return removeItem({ section, id });
|
||||
}),
|
||||
|
||||
|
@ -74,7 +74,7 @@ const episodeFileActionHandlers = {
|
|||
return updateItem({
|
||||
section: 'episodes',
|
||||
...episode,
|
||||
episodeFileId: 0,
|
||||
trackFileId: 0,
|
||||
hasFile: false
|
||||
});
|
||||
}),
|
||||
|
@ -97,10 +97,10 @@ const episodeFileActionHandlers = {
|
|||
};
|
||||
},
|
||||
|
||||
[types.UPDATE_EPISODE_FILES]: function(payload) {
|
||||
[types.UPDATE_TRACK_FILES]: function(payload) {
|
||||
return function(dispatch, getState) {
|
||||
const {
|
||||
episodeFileIds,
|
||||
trackFileIds,
|
||||
language,
|
||||
quality
|
||||
} = payload;
|
||||
|
@ -108,7 +108,7 @@ const episodeFileActionHandlers = {
|
|||
dispatch(set({ section, isSaving: true }));
|
||||
|
||||
const data = {
|
||||
episodeFileIds
|
||||
trackFileIds
|
||||
};
|
||||
|
||||
if (language) {
|
||||
|
@ -120,7 +120,7 @@ const episodeFileActionHandlers = {
|
|||
}
|
||||
|
||||
const promise = $.ajax({
|
||||
url: '/episodeFile/editor',
|
||||
url: '/trackFile/editor',
|
||||
method: 'PUT',
|
||||
dataType: 'json',
|
||||
data: JSON.stringify(data)
|
||||
|
@ -128,7 +128,7 @@ const episodeFileActionHandlers = {
|
|||
|
||||
promise.done(() => {
|
||||
dispatch(batchActions([
|
||||
...episodeFileIds.map((id) => {
|
||||
...trackFileIds.map((id) => {
|
||||
const props = {};
|
||||
|
||||
if (language) {
|
||||
|
@ -161,4 +161,4 @@ const episodeFileActionHandlers = {
|
|||
}
|
||||
};
|
||||
|
||||
export default episodeFileActionHandlers;
|
||||
export default trackFileActionHandlers;
|
9
frontend/src/Store/Actions/trackFileActions.js
Normal file
9
frontend/src/Store/Actions/trackFileActions.js
Normal file
|
@ -0,0 +1,9 @@
|
|||
import { createAction } from 'redux-actions';
|
||||
import * as types from './actionTypes';
|
||||
import trackFileActionHandlers from './trackFileActionHandlers';
|
||||
|
||||
export const fetchTrackFiles = trackFileActionHandlers[types.FETCH_TRACK_FILES];
|
||||
export const deleteTrackFile = trackFileActionHandlers[types.DELETE_TRACK_FILE];
|
||||
export const deleteTrackFiles = trackFileActionHandlers[types.DELETE_TRACK_FILES];
|
||||
export const updateTrackFiles = trackFileActionHandlers[types.UPDATE_TRACK_FILES];
|
||||
export const clearTrackFiles = createAction(types.CLEAR_TRACK_FILES);
|
|
@ -14,7 +14,7 @@ import queue, { defaultState as defaultQueueState } from './queueReducers';
|
|||
import blacklist, { defaultState as defaultBlacklistState } from './blacklistReducers';
|
||||
import episodes, { defaultState as defaultEpisodesState } from './episodeReducers';
|
||||
import tracks, { defaultState as defaultTracksState } from './trackReducers';
|
||||
import episodeFiles, { defaultState as defaultEpisodeFilesState } from './episodeFileReducers';
|
||||
import trackFiles, { defaultState as defaultTrackFilesState } from './trackFileReducers';
|
||||
import albumHistory, { defaultState as defaultAlbumHistoryState } from './albumHistoryReducers';
|
||||
import releases, { defaultState as defaultReleasesState } from './releaseReducers';
|
||||
import wanted, { defaultState as defaultWantedState } from './wantedReducers';
|
||||
|
@ -43,7 +43,7 @@ export const defaultState = {
|
|||
blacklist: defaultBlacklistState,
|
||||
episodes: defaultEpisodesState,
|
||||
tracks: defaultTracksState,
|
||||
episodeFiles: defaultEpisodeFilesState,
|
||||
trackFiles: defaultTrackFilesState,
|
||||
albumHistory: defaultAlbumHistoryState,
|
||||
releases: defaultReleasesState,
|
||||
wanted: defaultWantedState,
|
||||
|
@ -73,7 +73,7 @@ export default enableBatching(combineReducers({
|
|||
blacklist,
|
||||
episodes,
|
||||
tracks,
|
||||
episodeFiles,
|
||||
trackFiles,
|
||||
albumHistory,
|
||||
releases,
|
||||
wanted,
|
||||
|
|
|
@ -16,19 +16,19 @@ export const defaultState = {
|
|||
items: []
|
||||
};
|
||||
|
||||
const reducerSection = 'episodeFiles';
|
||||
const reducerSection = 'trackFiles';
|
||||
|
||||
const episodeFileReducers = handleActions({
|
||||
const trackFileReducers = handleActions({
|
||||
|
||||
[types.SET]: createSetReducer(reducerSection),
|
||||
[types.UPDATE]: createUpdateReducer(reducerSection),
|
||||
[types.UPDATE_ITEM]: createUpdateItemReducer(reducerSection),
|
||||
[types.REMOVE_ITEM]: createRemoveItemReducer(reducerSection),
|
||||
|
||||
[types.CLEAR_EPISODE_FILES]: (state) => {
|
||||
[types.CLEAR_TRACK_FILES]: (state) => {
|
||||
return Object.assign({}, state, defaultState);
|
||||
}
|
||||
|
||||
}, defaultState);
|
||||
|
||||
export default episodeFileReducers;
|
||||
export default trackFileReducers;
|
|
@ -1,18 +0,0 @@
|
|||
import _ from 'lodash';
|
||||
import { createSelector } from 'reselect';
|
||||
|
||||
function createEpisodeFileSelector() {
|
||||
return createSelector(
|
||||
(state, { episodeFileId }) => episodeFileId,
|
||||
(state) => state.episodeFiles,
|
||||
(episodeFileId, episodeFiles) => {
|
||||
if (!episodeFileId) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return _.find(episodeFiles.items, { id: episodeFileId });
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
export default createEpisodeFileSelector;
|
18
frontend/src/Store/Selectors/createTrackFileSelector.js
Normal file
18
frontend/src/Store/Selectors/createTrackFileSelector.js
Normal file
|
@ -0,0 +1,18 @@
|
|||
import _ from 'lodash';
|
||||
import { createSelector } from 'reselect';
|
||||
|
||||
function createTrackFileSelector() {
|
||||
return createSelector(
|
||||
(state, { trackFileId }) => trackFileId,
|
||||
(state) => state.trackFiles,
|
||||
(trackFileId, trackFiles) => {
|
||||
if (!trackFileId) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return _.find(trackFiles.items, { id: trackFileId });
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
export default createTrackFileSelector;
|
Loading…
Add table
Add a link
Reference in a new issue