Moved all reducers and actions to their own folders

This commit is contained in:
Deluan
2020-11-08 13:15:46 -05:00
parent 24b040adf9
commit 3fc81638c7
33 changed files with 204 additions and 206 deletions
+6
View File
@@ -0,0 +1,6 @@
export const ALBUM_MODE_GRID = 'ALBUM_GRID_MODE'
export const ALBUM_MODE_LIST = 'ALBUM_LIST_MODE'
export const albumViewGrid = () => ({ type: ALBUM_MODE_GRID })
export const albumViewList = () => ({ type: ALBUM_MODE_LIST })
+96
View File
@@ -0,0 +1,96 @@
export const PLAYER_ADD_TRACKS = 'PLAYER_ADD_TRACKS'
export const PLAYER_PLAY_NEXT = 'PLAYER_PLAY_NEXT'
export const PLAYER_SET_TRACK = 'PLAYER_SET_TRACK'
export const PLAYER_SYNC_QUEUE = 'PLAYER_SYNC_QUEUE'
export const PLAYER_CLEAR_QUEUE = 'PLAYER_CLEAR_QUEUE'
export const PLAYER_SCROBBLE = 'PLAYER_SCROBBLE'
export const PLAYER_PLAY_TRACKS = 'PLAYER_PLAY_TRACKS'
export const PLAYER_CURRENT = 'PLAYER_CURRENT'
export const PLAYER_SET_VOLUME = 'PLAYER_SET_VOLUME'
export const setTrack = (data) => ({
type: PLAYER_SET_TRACK,
data,
})
export const filterSongs = (data, ids) => {
if (!ids) {
return data
}
return ids.reduce((acc, id) => ({ ...acc, [id]: data[id] }), {})
}
export const addTracks = (data, ids) => {
const songs = filterSongs(data, ids)
return {
type: PLAYER_ADD_TRACKS,
data: songs,
}
}
export const playNext = (data, ids) => {
const songs = filterSongs(data, ids)
return {
type: PLAYER_PLAY_NEXT,
data: songs,
}
}
export const shuffle = (data) => {
const ids = Object.keys(data)
for (let i = ids.length - 1; i > 0; i--) {
let j = Math.floor(Math.random() * (i + 1))
;[ids[i], ids[j]] = [ids[j], ids[i]]
}
const shuffled = {}
// The "_" is to force the object key to be a string, so it keeps the order when adding to object
// or else the keys will always be in the same (numerically) order
ids.forEach((id) => (shuffled['_' + id] = data[id]))
return shuffled
}
export const shuffleTracks = (data, ids) => {
const songs = filterSongs(data, ids)
const shuffled = shuffle(songs)
const firstId = Object.keys(shuffled)[0]
return {
type: PLAYER_PLAY_TRACKS,
id: firstId,
data: shuffled,
}
}
export const playTracks = (data, ids, selectedId) => {
const songs = filterSongs(data, ids)
return {
type: PLAYER_PLAY_TRACKS,
id: selectedId || Object.keys(songs)[0],
data: songs,
}
}
export const syncQueue = (id, data) => ({
type: PLAYER_SYNC_QUEUE,
id,
data,
})
export const clearQueue = () => ({
type: PLAYER_CLEAR_QUEUE,
})
export const scrobble = (id, submit) => ({
type: PLAYER_SCROBBLE,
id,
submit,
})
export const currentPlaying = (audioInfo) => ({
type: PLAYER_CURRENT,
data: audioInfo,
})
export const setVolume = (volume) => ({
type: PLAYER_SET_VOLUME,
data: { volume },
})
+12
View File
@@ -0,0 +1,12 @@
export const ADD_TO_PLAYLIST_OPEN = 'ADD_TO_PLAYLIST_OPEN'
export const ADD_TO_PLAYLIST_CLOSE = 'ADD_TO_PLAYLIST_CLOSE'
export const openAddToPlaylist = ({ selectedIds, onSuccess }) => ({
type: ADD_TO_PLAYLIST_OPEN,
selectedIds,
onSuccess,
})
export const closeAddToPlaylist = () => ({
type: ADD_TO_PLAYLIST_CLOSE,
})
+4
View File
@@ -0,0 +1,4 @@
export * from './audioplayer'
export * from './themes'
export * from './albumView'
export * from './dialogs'
+6
View File
@@ -0,0 +1,6 @@
export const CHANGE_THEME = 'CHANGE_THEME'
export const changeTheme = (theme) => ({
type: CHANGE_THEME,
payload: theme,
})