Simplify PlayQueue store
This commit is contained in:
parent
804d969427
commit
1686e358fe
|
@ -10435,6 +10435,11 @@
|
|||
"resolved": "https://registry.npmjs.org/lodash.memoize/-/lodash.memoize-4.1.2.tgz",
|
||||
"integrity": "sha1-vMbEmkKihA7Zl/Mj6tpezRguC/4="
|
||||
},
|
||||
"lodash.pick": {
|
||||
"version": "4.4.0",
|
||||
"resolved": "https://registry.npmjs.org/lodash.pick/-/lodash.pick-4.4.0.tgz",
|
||||
"integrity": "sha1-UvBWEP/53tQiYRRB7R/BI6AwAbM="
|
||||
},
|
||||
"lodash.sortby": {
|
||||
"version": "4.7.0",
|
||||
"resolved": "https://registry.npmjs.org/lodash.sortby/-/lodash.sortby-4.7.0.tgz",
|
||||
|
|
|
@ -7,6 +7,7 @@
|
|||
"deepmerge": "^4.2.2",
|
||||
"jwt-decode": "^2.2.0",
|
||||
"lodash.get": "^4.4.2",
|
||||
"lodash.pick": "^4.4.0",
|
||||
"lodash.throttle": "^4.1.1",
|
||||
"md5-hex": "^3.0.1",
|
||||
"prop-types": "^15.7.2",
|
||||
|
|
|
@ -83,7 +83,7 @@ const Player = () => {
|
|||
const addQueueToOptions = (queue) => {
|
||||
return {
|
||||
...defaultOptions,
|
||||
autoPlay: queue.playing,
|
||||
autoPlay: false,
|
||||
clearPriorAudioLists: queue.clear,
|
||||
audioLists: queue.queue.map((item) => item),
|
||||
}
|
||||
|
|
|
@ -99,7 +99,7 @@ const currentPlaying = (audioInfo) => ({
|
|||
data: audioInfo,
|
||||
})
|
||||
|
||||
const initialState = { queue: [], clear: true, playing: false, current: {} }
|
||||
const initialState = { queue: [], clear: true, current: {} }
|
||||
|
||||
const playQueueReducer = (previousState = initialState, payload) => {
|
||||
let queue, current
|
||||
|
@ -130,7 +130,6 @@ const playQueueReducer = (previousState = initialState, payload) => {
|
|||
...previousState,
|
||||
queue: [mapToAudioLists(data)],
|
||||
clear: true,
|
||||
playing: true,
|
||||
}
|
||||
case PLAYER_SYNC_QUEUE:
|
||||
current = data.length > 0 ? previousState.current : {}
|
||||
|
@ -152,7 +151,6 @@ const playQueueReducer = (previousState = initialState, payload) => {
|
|||
...previousState,
|
||||
queue: newQueue,
|
||||
clear: false,
|
||||
playing: true,
|
||||
}
|
||||
case PLAYER_PLAY_TRACKS:
|
||||
queue = []
|
||||
|
@ -169,7 +167,6 @@ const playQueueReducer = (previousState = initialState, payload) => {
|
|||
...previousState,
|
||||
queue,
|
||||
clear: true,
|
||||
playing: true,
|
||||
}
|
||||
default:
|
||||
return previousState
|
||||
|
|
|
@ -4,6 +4,7 @@ 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 pick from 'lodash.pick'
|
||||
import { loadState, saveState } from './persistState'
|
||||
|
||||
export default ({
|
||||
|
@ -36,10 +37,6 @@ export default ({
|
|||
compose
|
||||
|
||||
const persistedState = loadState()
|
||||
// TODO Better encapsulate state in general
|
||||
if (persistedState && persistedState.queue) {
|
||||
persistedState.queue.playing = false
|
||||
}
|
||||
const store = createStore(
|
||||
resettableAppReducer,
|
||||
persistedState,
|
||||
|
@ -51,7 +48,7 @@ export default ({
|
|||
const state = store.getState()
|
||||
saveState({
|
||||
theme: state.theme,
|
||||
queue: state.queue,
|
||||
queue: pick(state.queue, ['queue']),
|
||||
albumView: state.albumView,
|
||||
})
|
||||
}),
|
||||
|
|
Loading…
Reference in New Issue