Skip to content

Commit

Permalink
Fixed library shuffle not shuffling
Browse files Browse the repository at this point in the history
 - Removed double sort from library play
  • Loading branch information
chronoDave committed May 24, 2020
1 parent 1437251 commit dff1f8d
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 8 deletions.
3 changes: 2 additions & 1 deletion packages/doombox-react/src/redux/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
8 changes: 8 additions & 0 deletions packages/doombox-react/src/redux/slices/mixtape.slice.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
17 changes: 10 additions & 7 deletions packages/doombox-react/src/routers/Library/LibraryRouter.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,8 @@ import {
// Redux
import {
addMixtape,
setMixtape
setMixtape,
addShuffleMixtape
} from '../../redux';

// Hooks
Expand All @@ -56,8 +57,7 @@ import {
sortLibrary,
createDividerDisc,
createDividerAlbum,
getTotalDuration,
shuffleArray
getTotalDuration
} from '../../utils';
import {
PATH,
Expand All @@ -72,6 +72,7 @@ const LibraryRouter = props => {
songs,
cacheSize,
addToMixtape,
shuffle,
playMixtape,
reverseScroll
} = props;
Expand Down Expand Up @@ -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' })}
/>
<ContextItem
onClick={() => 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' })}
/>
Expand Down Expand Up @@ -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
};

Expand All @@ -316,7 +318,8 @@ const mapStateToProps = state => ({

const mapDispatchToProps = {
addToMixtape: addMixtape,
playMixtape: setMixtape
playMixtape: setMixtape,
shuffle: addShuffleMixtape
};

export default connect(
Expand Down

0 comments on commit dff1f8d

Please sign in to comment.