From dff1f8d998d28c5ed4b0493e8abbc267f8c8c909 Mon Sep 17 00:00:00 2001 From: chronoDave Date: Sun, 24 May 2020 12:11:38 +0200 Subject: [PATCH] Fixed library shuffle not shuffling - Removed double sort from library play --- packages/doombox-react/src/redux/index.js | 3 ++- .../src/redux/slices/mixtape.slice.js | 8 ++++++++ .../src/routers/Library/LibraryRouter.jsx | 17 ++++++++++------- 3 files changed, 20 insertions(+), 8 deletions(-) diff --git a/packages/doombox-react/src/redux/index.js b/packages/doombox-react/src/redux/index.js index 99e401bc..cdf7978c 100644 --- a/packages/doombox-react/src/redux/index.js +++ b/packages/doombox-react/src/redux/index.js @@ -20,7 +20,8 @@ export const { setLibrary } = librarySlice.actions; export const { setMixtape, addMixtape, - shuffleMixtape + shuffleMixtape, + addShuffleMixtape } = mixtapeSlice.actions; export const { setPlaylist } = playlistSlice.actions; export const { setConfig } = configSlice.actions; diff --git a/packages/doombox-react/src/redux/slices/mixtape.slice.js b/packages/doombox-react/src/redux/slices/mixtape.slice.js index c679a893..c25bc053 100644 --- a/packages/doombox-react/src/redux/slices/mixtape.slice.js +++ b/packages/doombox-react/src/redux/slices/mixtape.slice.js @@ -34,6 +34,14 @@ export const mixtapeSlice = createSlice({ ] }); }, + addShuffleMixtape(state, action) { + return ({ + ...state, + ...action.payload, + action: ACTION.PLAYLIST.SET, + collection: shuffleArray(action.payload.collection) + }); + }, shuffleMixtape(state) { return ({ ...state, diff --git a/packages/doombox-react/src/routers/Library/LibraryRouter.jsx b/packages/doombox-react/src/routers/Library/LibraryRouter.jsx index aeb594c7..6349608d 100644 --- a/packages/doombox-react/src/routers/Library/LibraryRouter.jsx +++ b/packages/doombox-react/src/routers/Library/LibraryRouter.jsx @@ -45,7 +45,8 @@ import { // Redux import { addMixtape, - setMixtape + setMixtape, + addShuffleMixtape } from '../../redux'; // Hooks @@ -56,8 +57,7 @@ import { sortLibrary, createDividerDisc, createDividerAlbum, - getTotalDuration, - shuffleArray + getTotalDuration } from '../../utils'; import { PATH, @@ -72,6 +72,7 @@ const LibraryRouter = props => { songs, cacheSize, addToMixtape, + shuffle, playMixtape, reverseScroll } = props; @@ -247,16 +248,16 @@ const LibraryRouter = props => { action: ACTION.PLAYLIST.SET, name: t('library'), // Slice makes sure a NEW array is created - collection: songs.slice().sort(sortLibrary) + collection: songs.slice() })} primary={t('action:play', { context: 'library' })} /> playMixtape({ + onClick={() => shuffle({ action: ACTION.PLAYLIST.SET, name: t('library'), // Slice makes sure a NEW array is created - collection: shuffleArray(songs.slice().sort(sortLibrary)) + collection: songs.slice() })} primary={t('action:shuffle', { context: 'library' })} /> @@ -305,6 +306,7 @@ LibraryRouter.propTypes = { cacheSize: PropTypes.number.isRequired, addToMixtape: PropTypes.func.isRequired, playMixtape: PropTypes.func.isRequired, + shuffle: PropTypes.func.isRequired, reverseScroll: PropTypes.bool.isRequired }; @@ -316,7 +318,8 @@ const mapStateToProps = state => ({ const mapDispatchToProps = { addToMixtape: addMixtape, - playMixtape: setMixtape + playMixtape: setMixtape, + shuffle: addShuffleMixtape }; export default connect(