mirror of
https://github.com/Prowlarr/Prowlarr.git
synced 2025-09-17 17:14:18 +02:00
New: Add List and Discovery Pages (#3803)
This commit is contained in:
@@ -4,11 +4,19 @@ import { batchActions } from 'redux-batched-actions';
|
||||
import getSectionState from 'Utilities/State/getSectionState';
|
||||
import updateSectionState from 'Utilities/State/updateSectionState';
|
||||
import createAjaxRequest from 'Utilities/createAjaxRequest';
|
||||
import createFetchHandler from './Creators/createFetchHandler';
|
||||
import getNewMovie from 'Utilities/Movie/getNewMovie';
|
||||
import { filterBuilderTypes, filterBuilderValueTypes, sortDirections } from 'Helpers/Props';
|
||||
import sortByName from 'Utilities/Array/sortByName';
|
||||
import { createThunk, handleThunks } from 'Store/thunks';
|
||||
import createSetSettingValueReducer from './Creators/Reducers/createSetSettingValueReducer';
|
||||
import createHandleActions from './Creators/createHandleActions';
|
||||
import { set, update, updateItem } from './baseActions';
|
||||
import { filterPredicates, sortPredicates } from './movieActions';
|
||||
import createSetTableOptionReducer from './Creators/Reducers/createSetTableOptionReducer';
|
||||
import createSetClientSideCollectionSortReducer from './Creators/Reducers/createSetClientSideCollectionSortReducer';
|
||||
import createSetClientSideCollectionFilterReducer from './Creators/Reducers/createSetClientSideCollectionFilterReducer';
|
||||
import createClearReducer from './Creators/Reducers/createClearReducer';
|
||||
|
||||
//
|
||||
// Variables
|
||||
@@ -27,17 +35,213 @@ export const defaultState = {
|
||||
isAdded: false,
|
||||
addError: null,
|
||||
items: [],
|
||||
sortKey: 'sortTitle',
|
||||
sortDirection: sortDirections.ASCENDING,
|
||||
secondarySortKey: 'sortTitle',
|
||||
secondarySortDirection: sortDirections.ASCENDING,
|
||||
view: 'overview',
|
||||
|
||||
defaults: {
|
||||
rootFolderPath: '',
|
||||
monitor: 'true',
|
||||
qualityProfileId: 0,
|
||||
tags: []
|
||||
}
|
||||
},
|
||||
|
||||
posterOptions: {
|
||||
size: 'large',
|
||||
showTitle: false
|
||||
},
|
||||
|
||||
overviewOptions: {
|
||||
detailedProgressBar: false,
|
||||
size: 'medium',
|
||||
showStudio: true
|
||||
},
|
||||
|
||||
tableOptions: {
|
||||
// showSearchAction: false
|
||||
},
|
||||
|
||||
columns: [
|
||||
{
|
||||
name: 'select',
|
||||
columnLabel: 'select',
|
||||
isSortable: false,
|
||||
isVisible: true,
|
||||
isModifiable: false
|
||||
},
|
||||
{
|
||||
name: 'status',
|
||||
columnLabel: 'Status',
|
||||
isSortable: true,
|
||||
isVisible: true,
|
||||
isModifiable: false
|
||||
},
|
||||
{
|
||||
name: 'sortTitle',
|
||||
label: 'Movie Title',
|
||||
isSortable: true,
|
||||
isVisible: true,
|
||||
isModifiable: false
|
||||
},
|
||||
{
|
||||
name: 'studio',
|
||||
label: 'Studio',
|
||||
isSortable: true,
|
||||
isVisible: true
|
||||
},
|
||||
{
|
||||
name: 'inCinemas',
|
||||
label: 'In Cinemas',
|
||||
isSortable: true,
|
||||
isVisible: true
|
||||
},
|
||||
{
|
||||
name: 'physicalRelease',
|
||||
label: 'Physical Release',
|
||||
isSortable: true,
|
||||
isVisible: false
|
||||
},
|
||||
{
|
||||
name: 'genres',
|
||||
label: 'Genres',
|
||||
isSortable: false,
|
||||
isVisible: false
|
||||
},
|
||||
{
|
||||
name: 'ratings',
|
||||
label: 'Rating',
|
||||
isSortable: true,
|
||||
isVisible: false
|
||||
},
|
||||
{
|
||||
name: 'certification',
|
||||
label: 'Certification',
|
||||
isSortable: false,
|
||||
isVisible: false
|
||||
},
|
||||
{
|
||||
name: 'actions',
|
||||
columnLabel: 'Actions',
|
||||
isVisible: true,
|
||||
isModifiable: false
|
||||
}
|
||||
],
|
||||
|
||||
sortPredicates: {
|
||||
...sortPredicates,
|
||||
|
||||
studio: function(item) {
|
||||
const studio = item.studio;
|
||||
|
||||
return studio ? studio.toLowerCase() : '';
|
||||
},
|
||||
|
||||
ratings: function(item) {
|
||||
const { ratings = {} } = item;
|
||||
|
||||
return ratings.value;
|
||||
}
|
||||
},
|
||||
|
||||
selectedFilterKey: 'all',
|
||||
|
||||
filters: [
|
||||
{
|
||||
key: 'all',
|
||||
label: 'All',
|
||||
filters: []
|
||||
}
|
||||
],
|
||||
|
||||
filterPredicates,
|
||||
|
||||
filterBuilderProps: [
|
||||
{
|
||||
name: 'status',
|
||||
label: 'Status',
|
||||
type: filterBuilderTypes.EXACT,
|
||||
valueType: filterBuilderValueTypes.SERIES_STATUS
|
||||
},
|
||||
{
|
||||
name: 'studio',
|
||||
label: 'Studio',
|
||||
type: filterBuilderTypes.ARRAY,
|
||||
optionsSelector: function(items) {
|
||||
const tagList = items.reduce((acc, movie) => {
|
||||
acc.push({
|
||||
id: movie.studio,
|
||||
name: movie.studio
|
||||
});
|
||||
|
||||
return acc;
|
||||
}, []);
|
||||
|
||||
return tagList.sort(sortByName);
|
||||
}
|
||||
},
|
||||
{
|
||||
name: 'inCinemas',
|
||||
label: 'In Cinemas',
|
||||
type: filterBuilderTypes.DATE,
|
||||
valueType: filterBuilderValueTypes.DATE
|
||||
},
|
||||
{
|
||||
name: 'physicalRelease',
|
||||
label: 'Physical Release',
|
||||
type: filterBuilderTypes.DATE,
|
||||
valueType: filterBuilderValueTypes.DATE
|
||||
},
|
||||
{
|
||||
name: 'genres',
|
||||
label: 'Genres',
|
||||
type: filterBuilderTypes.ARRAY,
|
||||
optionsSelector: function(items) {
|
||||
const tagList = items.reduce((acc, movie) => {
|
||||
movie.genres.forEach((genre) => {
|
||||
acc.push({
|
||||
id: genre,
|
||||
name: genre
|
||||
});
|
||||
});
|
||||
|
||||
return acc;
|
||||
}, []);
|
||||
|
||||
return tagList.sort(sortByName);
|
||||
}
|
||||
},
|
||||
{
|
||||
name: 'ratings',
|
||||
label: 'Rating',
|
||||
type: filterBuilderTypes.NUMBER
|
||||
},
|
||||
{
|
||||
name: 'certification',
|
||||
label: 'Certification',
|
||||
type: filterBuilderTypes.EXACT
|
||||
},
|
||||
{
|
||||
name: 'tags',
|
||||
label: 'Tags',
|
||||
type: filterBuilderTypes.ARRAY,
|
||||
valueType: filterBuilderValueTypes.TAG
|
||||
}
|
||||
]
|
||||
};
|
||||
|
||||
export const persistState = [
|
||||
'addMovie.defaults'
|
||||
'addMovie.defaults',
|
||||
'addMovie.sortKey',
|
||||
'addMovie.sortDirection',
|
||||
'addMovie.selectedFilterKey',
|
||||
'addMovie.customFilters',
|
||||
'addMovie.view',
|
||||
'addMovie.columns',
|
||||
'addMovie.posterOptions',
|
||||
'addMovie.overviewOptions',
|
||||
'addMovie.tableOptions'
|
||||
];
|
||||
|
||||
//
|
||||
@@ -49,6 +253,16 @@ export const SET_ADD_MOVIE_VALUE = 'addMovie/setAddMovieValue';
|
||||
export const CLEAR_ADD_MOVIE = 'addMovie/clearAddMovie';
|
||||
export const SET_ADD_MOVIE_DEFAULT = 'addMovie/setAddMovieDefault';
|
||||
|
||||
export const FETCH_LIST_MOVIES = 'addMovie/fetchListMovies';
|
||||
export const FETCH_DISCOVER_MOVIES = 'addMovie/fetchDiscoverMovies';
|
||||
|
||||
export const SET_LIST_MOVIE_SORT = 'addMovie/setListMovieSort';
|
||||
export const SET_LIST_MOVIE_FILTER = 'addMovie/setListMovieFilter';
|
||||
export const SET_LIST_MOVIE_VIEW = 'addMovie/setListMovieView';
|
||||
export const SET_LIST_MOVIE_TABLE_OPTION = 'addMovie/setListMovieTableOption';
|
||||
export const SET_LIST_MOVIE_POSTER_OPTION = 'addMovie/setListMoviePosterOption';
|
||||
export const SET_LIST_MOVIE_OVERVIEW_OPTION = 'addMovie/setListMovieOverviewOption';
|
||||
|
||||
//
|
||||
// Action Creators
|
||||
|
||||
@@ -57,6 +271,16 @@ export const addMovie = createThunk(ADD_MOVIE);
|
||||
export const clearAddMovie = createAction(CLEAR_ADD_MOVIE);
|
||||
export const setAddMovieDefault = createAction(SET_ADD_MOVIE_DEFAULT);
|
||||
|
||||
export const fetchListMovies = createThunk(FETCH_LIST_MOVIES);
|
||||
export const fetchDiscoverMovies = createThunk(FETCH_DISCOVER_MOVIES);
|
||||
|
||||
export const setListMovieSort = createAction(SET_LIST_MOVIE_SORT);
|
||||
export const setListMovieFilter = createAction(SET_LIST_MOVIE_FILTER);
|
||||
export const setListMovieView = createAction(SET_LIST_MOVIE_VIEW);
|
||||
export const setListMovieTableOption = createAction(SET_LIST_MOVIE_TABLE_OPTION);
|
||||
export const setListMoviePosterOption = createAction(SET_LIST_MOVIE_POSTER_OPTION);
|
||||
export const setListMovieOverviewOption = createAction(SET_LIST_MOVIE_OVERVIEW_OPTION);
|
||||
|
||||
export const setAddMovieValue = createAction(SET_ADD_MOVIE_VALUE, (payload) => {
|
||||
return {
|
||||
section,
|
||||
@@ -69,6 +293,10 @@ export const setAddMovieValue = createAction(SET_ADD_MOVIE_VALUE, (payload) => {
|
||||
|
||||
export const actionHandlers = handleThunks({
|
||||
|
||||
[FETCH_LIST_MOVIES]: createFetchHandler(section, '/netimport/movies'),
|
||||
|
||||
[FETCH_DISCOVER_MOVIES]: createFetchHandler(section, '/movies/discover'),
|
||||
|
||||
[LOOKUP_MOVIE]: function(getState, payload, dispatch) {
|
||||
dispatch(set({ section, isFetching: true }));
|
||||
|
||||
@@ -164,13 +392,54 @@ export const reducers = createHandleActions({
|
||||
return updateSectionState(state, section, newState);
|
||||
},
|
||||
|
||||
[CLEAR_ADD_MOVIE]: function(state) {
|
||||
const {
|
||||
defaults,
|
||||
...otherDefaultState
|
||||
} = defaultState;
|
||||
[SET_LIST_MOVIE_SORT]: createSetClientSideCollectionSortReducer(section),
|
||||
[SET_LIST_MOVIE_FILTER]: createSetClientSideCollectionFilterReducer(section),
|
||||
|
||||
return Object.assign({}, state, otherDefaultState);
|
||||
}
|
||||
[SET_LIST_MOVIE_VIEW]: function(state, { payload }) {
|
||||
return Object.assign({}, state, { view: payload.view });
|
||||
},
|
||||
|
||||
[SET_LIST_MOVIE_TABLE_OPTION]: createSetTableOptionReducer(section),
|
||||
|
||||
[SET_LIST_MOVIE_POSTER_OPTION]: function(state, { payload }) {
|
||||
const posterOptions = state.posterOptions;
|
||||
|
||||
return {
|
||||
...state,
|
||||
posterOptions: {
|
||||
...posterOptions,
|
||||
...payload
|
||||
}
|
||||
};
|
||||
},
|
||||
|
||||
[SET_LIST_MOVIE_OVERVIEW_OPTION]: function(state, { payload }) {
|
||||
const overviewOptions = state.overviewOptions;
|
||||
|
||||
return {
|
||||
...state,
|
||||
overviewOptions: {
|
||||
...overviewOptions,
|
||||
...payload
|
||||
}
|
||||
};
|
||||
},
|
||||
|
||||
// [CLEAR_ADD_MOVIE]: function(state) {
|
||||
// const {
|
||||
// defaults,
|
||||
// view,
|
||||
// ...otherDefaultState
|
||||
// } = defaultState;
|
||||
|
||||
// return Object.assign({}, state, otherDefaultState);
|
||||
// }
|
||||
|
||||
[CLEAR_ADD_MOVIE]: createClearReducer(section, {
|
||||
isFetching: false,
|
||||
isPopulated: false,
|
||||
error: null,
|
||||
items: []
|
||||
})
|
||||
|
||||
}, defaultState, section);
|
||||
|
Reference in New Issue
Block a user