feat: add the remainder of the album to the queue when clicking on an album's track
This commit is contained in:
@@ -4,19 +4,23 @@ import { DurationField, PlayButton, SimpleList } from '../common'
|
|||||||
import { addTrack, setTrack } from '../player'
|
import { addTrack, setTrack } from '../player'
|
||||||
import AddIcon from '@material-ui/icons/Add'
|
import AddIcon from '@material-ui/icons/Add'
|
||||||
import { useDispatch } from 'react-redux'
|
import { useDispatch } from 'react-redux'
|
||||||
|
import { playAlbum } from '../player/queue'
|
||||||
|
|
||||||
const AlbumSongList = (props) => {
|
const AlbumSongList = (props) => {
|
||||||
const dispatch = useDispatch()
|
const dispatch = useDispatch()
|
||||||
const { record } = props
|
const { record } = props
|
||||||
|
|
||||||
const { data, total, loading, error } = useGetList(
|
const { data, total, loading, error } = useGetList(
|
||||||
'song',
|
'song',
|
||||||
{ page: 0, perPage: 100 },
|
{ page: 0, perPage: 100 },
|
||||||
{ field: 'album', order: 'ASC' },
|
{ field: 'album', order: 'ASC' },
|
||||||
{ album_id: record.id }
|
{ album_id: record.id }
|
||||||
)
|
)
|
||||||
|
|
||||||
if (error) {
|
if (error) {
|
||||||
return <p>ERROR: {error}</p>
|
return <p>ERROR: {error}</p>
|
||||||
}
|
}
|
||||||
|
|
||||||
const trackName = (r) => {
|
const trackName = (r) => {
|
||||||
const name = r.title
|
const name = r.title
|
||||||
if (r.trackNumber) {
|
if (r.trackNumber) {
|
||||||
@@ -24,6 +28,7 @@ const AlbumSongList = (props) => {
|
|||||||
}
|
}
|
||||||
return name
|
return name
|
||||||
}
|
}
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<SimpleList
|
<SimpleList
|
||||||
data={data}
|
data={data}
|
||||||
@@ -32,7 +37,7 @@ const AlbumSongList = (props) => {
|
|||||||
total={total}
|
total={total}
|
||||||
primaryText={(r) => (
|
primaryText={(r) => (
|
||||||
<>
|
<>
|
||||||
<PlayButton action={setTrack(r)} />
|
<PlayButton action={playAlbum(r.id, data)} />
|
||||||
<PlayButton action={addTrack(r)} icon={<AddIcon />} />
|
<PlayButton action={addTrack(r)} icon={<AddIcon />} />
|
||||||
{trackName(r)}
|
{trackName(r)}
|
||||||
</>
|
</>
|
||||||
@@ -41,7 +46,7 @@ const AlbumSongList = (props) => {
|
|||||||
r.albumArtist && r.artist !== r.albumArtist ? r.artist : ''
|
r.albumArtist && r.artist !== r.albumArtist ? r.artist : ''
|
||||||
}
|
}
|
||||||
tertiaryText={(r) => <DurationField record={r} source={'duration'} />}
|
tertiaryText={(r) => <DurationField record={r} source={'duration'} />}
|
||||||
linkType={(id, basePath, record) => dispatch(setTrack(record))}
|
linkType={(id) => dispatch(playAlbum(id, data))}
|
||||||
/>
|
/>
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|||||||
+24
-4
@@ -5,9 +5,9 @@ const PLAYER_ADD_TRACK = 'PLAYER_ADD_TRACK'
|
|||||||
const PLAYER_SET_TRACK = 'PLAYER_SET_TRACK'
|
const PLAYER_SET_TRACK = 'PLAYER_SET_TRACK'
|
||||||
const PLAYER_SYNC_QUEUE = 'PLAYER_SYNC_QUEUE'
|
const PLAYER_SYNC_QUEUE = 'PLAYER_SYNC_QUEUE'
|
||||||
const PLAYER_SCROBBLE = 'PLAYER_SCROBBLE'
|
const PLAYER_SCROBBLE = 'PLAYER_SCROBBLE'
|
||||||
|
const PLAYER_PLAY_ALBUM = 'PLAYER_PLAY_ALBUM'
|
||||||
|
|
||||||
const mapToAudioLists = (item) => ({
|
const mapToAudioLists = (item) => ({
|
||||||
id: item.id,
|
|
||||||
name: item.title,
|
name: item.title,
|
||||||
singer: item.artist,
|
singer: item.artist,
|
||||||
cover: subsonicUrl('getCoverArt', item.id, 'size=300'),
|
cover: subsonicUrl('getCoverArt', item.id, 'size=300'),
|
||||||
@@ -25,6 +25,12 @@ const setTrack = (data) => ({
|
|||||||
data
|
data
|
||||||
})
|
})
|
||||||
|
|
||||||
|
const playAlbum = (id, data) => ({
|
||||||
|
type: PLAYER_PLAY_ALBUM,
|
||||||
|
data,
|
||||||
|
id
|
||||||
|
})
|
||||||
|
|
||||||
const syncQueue = (data) => ({
|
const syncQueue = (data) => ({
|
||||||
type: PLAYER_SYNC_QUEUE,
|
type: PLAYER_SYNC_QUEUE,
|
||||||
data
|
data
|
||||||
@@ -37,11 +43,13 @@ const scrobble = (id) => ({
|
|||||||
|
|
||||||
const playQueueReducer = (
|
const playQueueReducer = (
|
||||||
previousState = { queue: [], clear: true },
|
previousState = { queue: [], clear: true },
|
||||||
{ type, data }
|
payload
|
||||||
) => {
|
) => {
|
||||||
|
let queue
|
||||||
|
const { type, data } = payload
|
||||||
switch (type) {
|
switch (type) {
|
||||||
case PLAYER_ADD_TRACK:
|
case PLAYER_ADD_TRACK:
|
||||||
const queue = previousState.queue
|
queue = previousState.queue
|
||||||
queue.push(mapToAudioLists(data))
|
queue.push(mapToAudioLists(data))
|
||||||
return { queue, clear: false }
|
return { queue, clear: false }
|
||||||
case PLAYER_SET_TRACK:
|
case PLAYER_SET_TRACK:
|
||||||
@@ -56,9 +64,21 @@ const playQueueReducer = (
|
|||||||
}
|
}
|
||||||
})
|
})
|
||||||
return { queue: newQueue, clear: false }
|
return { queue: newQueue, clear: false }
|
||||||
|
case PLAYER_PLAY_ALBUM:
|
||||||
|
queue = []
|
||||||
|
let match = false
|
||||||
|
Object.keys(data).forEach((id) => {
|
||||||
|
if (id === payload.id) {
|
||||||
|
match = true
|
||||||
|
}
|
||||||
|
if (match) {
|
||||||
|
queue.push(mapToAudioLists(data[id]))
|
||||||
|
}
|
||||||
|
})
|
||||||
|
return { queue, clear: true }
|
||||||
default:
|
default:
|
||||||
return previousState
|
return previousState
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export { addTrack, setTrack, syncQueue, scrobble, playQueueReducer }
|
export { addTrack, setTrack, playAlbum, syncQueue, scrobble, playQueueReducer }
|
||||||
|
|||||||
Reference in New Issue
Block a user