Skip to content

🎧 Your Personal Streaming Service

Save perPage selection in localstorage

Deluan9490374faa5c
diff --git a/ui/src/store/createAdminStore.js b/ui/src/store/createAdminStore.js
index f7866624f..84afb4430 100644
--- a/ui/src/store/createAdminStore.js
+++ b/ui/src/store/createAdminStore.js
@@ -1,10 +1,11 @@
import { applyMiddleware, combineReducers, compose, createStore } from 'redux'
-import { routerMiddleware, connectRouter } from 'connected-react-router'
+import { connectRouter, routerMiddleware } from 'connected-react-router'
import createSagaMiddleware from 'redux-saga'
import { all, fork } from 'redux-saga/effects'
import { adminReducer, adminSaga, USER_LOGOUT } from 'react-admin'
import throttle from 'lodash.throttle'
import { loadState, saveState } from './persistState'
+import { pruneResources } from './pruneResources'
export default ({
authProvider,
@@ -50,6 +51,9 @@ export default ({
throttle(() => {
const state = store.getState()
saveState({
+ admin: {
+ resources: pruneResources(state),
+ },
theme: state.theme,
queue: state.queue,
albumView: state.albumView,
diff --git a/ui/src/store/pruneResources.js b/ui/src/store/pruneResources.js
new file mode 100644
index 000000000..d3552c884
--- /dev/null
+++ b/ui/src/store/pruneResources.js
@@ -0,0 +1,39 @@
+function getParts(object, fragments) {
+ if (!object) {
+ return object
+ }
+ const [part, ...rest] = fragments.split('.')
+
+ return Object.assign(
+ {},
+ ...Object.entries(object)
+ .filter(([key]) => key.toLowerCase().includes(part))
+ .map(([k, v]) => {
+ if (!rest.length) return { [k]: v }
+ const parts = v && typeof v === 'object' && getParts(v, rest.join('.'))
+ if (parts) return { [k]: parts }
+ return undefined
+ })
+ )
+}
+
+const pruneResource = (resource) => ({
+ props: {},
+ list: {
+ param: {
+ perPage: getParts(resource.list.param, 'perPage'),
+ filter: {},
+ },
+ selectedIds: [],
+ },
+})
+
+export const pruneResources = (state) => {
+ return Object.keys(state.admin.resources).reduce(
+ (acc, cur) => ({
+ ...acc,
+ [cur]: pruneResource(state.admin.resources[cur]),
+ }),
+ {}
+ )
+}