Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
11 changed files
with
225 additions
and
25 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
package app | ||
|
||
import ( | ||
"encoding/json" | ||
"fmt" | ||
"net/http" | ||
|
||
"github.com/deluan/navidrome/model" | ||
"github.com/deluan/navidrome/utils" | ||
) | ||
|
||
type addTracksPayload struct { | ||
Ids []string `json:"ids"` | ||
} | ||
|
||
func addToPlaylist(ds model.DataStore) http.HandlerFunc { | ||
return func(w http.ResponseWriter, r *http.Request) { | ||
playlistId := utils.ParamString(r, ":playlistId") | ||
tracksRepo := ds.Playlist(r.Context()).Tracks(playlistId) | ||
var payload addTracksPayload | ||
err := json.NewDecoder(r.Body).Decode(&payload) | ||
if err != nil { | ||
http.Error(w, err.Error(), http.StatusBadRequest) | ||
return | ||
} | ||
_, err = tracksRepo.Add(payload.Ids) | ||
if err != nil { | ||
http.Error(w, err.Error(), http.StatusBadRequest) | ||
return | ||
} | ||
|
||
// Must return an object with an ID, to satisfy ReactAdmin `create` call | ||
_, err = w.Write([]byte(fmt.Sprintf(`{"id":"%s"}`, playlistId))) | ||
if err != nil { | ||
http.Error(w, err.Error(), http.StatusBadRequest) | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
import React from 'react' | ||
import PropTypes from 'prop-types' | ||
import { useGetList, useTranslate } from 'react-admin' | ||
import { makeStyles } from '@material-ui/core/styles' | ||
import Avatar from '@material-ui/core/Avatar' | ||
import List from '@material-ui/core/List' | ||
import ListItem from '@material-ui/core/ListItem' | ||
import ListItemAvatar from '@material-ui/core/ListItemAvatar' | ||
import ListItemText from '@material-ui/core/ListItemText' | ||
import DialogTitle from '@material-ui/core/DialogTitle' | ||
import Dialog from '@material-ui/core/Dialog' | ||
import { blue } from '@material-ui/core/colors' | ||
import PlaylistIcon from '../icons/Playlist' | ||
|
||
const useStyles = makeStyles({ | ||
avatar: { | ||
backgroundColor: blue[100], | ||
color: blue[600], | ||
}, | ||
}) | ||
|
||
function SelectPlaylistDialog(props) { | ||
const classes = useStyles() | ||
const translate = useTranslate() | ||
const { onClose, selectedValue, open } = props | ||
const { ids, data, loaded } = useGetList( | ||
'playlist', | ||
{ page: 1, perPage: -1 }, | ||
{ field: '', order: '' }, | ||
{} | ||
) | ||
|
||
if (!loaded) { | ||
return <div /> | ||
} | ||
|
||
const handleClose = () => { | ||
onClose(selectedValue) | ||
} | ||
|
||
const handleListItemClick = (value) => { | ||
onClose(value) | ||
} | ||
|
||
return ( | ||
<Dialog | ||
onClose={handleClose} | ||
aria-labelledby="select-playlist-dialog-title" | ||
open={open} | ||
scroll={'paper'} | ||
> | ||
<DialogTitle id="select-playlist-dialog-title"> | ||
{translate('resources.playlist.actions.selectPlaylist')} | ||
</DialogTitle> | ||
<List> | ||
{ids.map((id) => ( | ||
<ListItem button onClick={() => handleListItemClick(id)} key={id}> | ||
<ListItemAvatar> | ||
<Avatar className={classes.avatar}> | ||
<PlaylistIcon /> | ||
</Avatar> | ||
</ListItemAvatar> | ||
<ListItemText primary={data[id].name} /> | ||
</ListItem> | ||
))} | ||
</List> | ||
</Dialog> | ||
) | ||
} | ||
|
||
SelectPlaylistDialog.propTypes = { | ||
onClose: PropTypes.func.isRequired, | ||
open: PropTypes.bool.isRequired, | ||
selectedValue: PropTypes.string.isRequired, | ||
} | ||
|
||
export default SelectPlaylistDialog |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
import React, { useState } from 'react' | ||
import { | ||
Button, | ||
useTranslate, | ||
useUnselectAll, | ||
useDataProvider, | ||
useNotify, | ||
} from 'react-admin' | ||
import SelectPlaylistDialog from '../common/SelectPlaylistDialog' | ||
import PlaylistAddIcon from '@material-ui/icons/PlaylistAdd' | ||
|
||
const AddToPlaylistButton = ({ resource, selectedIds }) => { | ||
const [open, setOpen] = useState(false) | ||
const [selectedValue, setSelectedValue] = useState('') | ||
const translate = useTranslate() | ||
const unselectAll = useUnselectAll() | ||
const notify = useNotify() | ||
const dataProvider = useDataProvider() | ||
|
||
const handleClickOpen = () => { | ||
setOpen(true) | ||
} | ||
|
||
const handleClose = (value) => { | ||
if (value !== '') { | ||
dataProvider | ||
.create('playlistTrack', { | ||
data: { ids: selectedIds }, | ||
filter: { playlist_id: value }, | ||
}) | ||
.then(() => { | ||
notify(`Added ${selectedIds.length} songs to playlist`) | ||
}) | ||
.catch(() => { | ||
notify('ra.page.error', 'warning') | ||
}) | ||
} | ||
setOpen(false) | ||
setSelectedValue(value) | ||
unselectAll(resource) | ||
} | ||
|
||
return ( | ||
<> | ||
<Button | ||
color="secondary" | ||
onClick={handleClickOpen} | ||
label={translate('resources.song.actions.addToPlaylist')} | ||
> | ||
<PlaylistAddIcon /> | ||
</Button> | ||
<SelectPlaylistDialog | ||
selectedValue={selectedValue} | ||
open={open} | ||
onClose={handleClose} | ||
/> | ||
</> | ||
) | ||
} | ||
|
||
export default AddToPlaylistButton |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,12 @@ | ||
import React, { Fragment } from 'react' | ||
import AddToQueueButton from './AddToQueueButton' | ||
import AddToPlaylistButton from './AddToPlaylistButton' | ||
|
||
export const SongBulkActions = (props) => { | ||
return ( | ||
<Fragment> | ||
<AddToQueueButton {...props} /> | ||
<AddToPlaylistButton {...props} /> | ||
</Fragment> | ||
) | ||
} |