|
@@ -60,7 +60,8 @@ function jwtDecode(token) {
|
|
|
|
|
|
const actionLoadFile = (file, type) => {
|
|
|
let fd = new FormData()
|
|
|
- fd.append(type, file)
|
|
|
+ console.log('TYPE', type)
|
|
|
+ fd.append(type === 'upload'? 'photo' : type, file)
|
|
|
|
|
|
return (
|
|
|
actionPromise('loadFile', fetch(backendURL + `/${type}`,{
|
|
@@ -119,18 +120,64 @@ const actionGetUserTracks = () => {
|
|
|
)
|
|
|
}
|
|
|
|
|
|
+const actionGetPlaylistById = (_id) =>
|
|
|
+ actionPromise('playlistTracks', gql(`
|
|
|
+ query playlistById($playlistId: String!) {
|
|
|
+ PlaylistFind(query: $playlistId) {
|
|
|
+ _id,
|
|
|
+ name,
|
|
|
+ tracks { _id, url, originalFileName }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ `, { playlistId: JSON.stringify([{ _id }]) }))
|
|
|
+
|
|
|
+const actionGetTrackById = (_id) =>
|
|
|
+ actionPromise('track', gql(`
|
|
|
+ query trackById($trackId: String!) {
|
|
|
+ TrackFind(query: $trackId) {
|
|
|
+ _id, url, originalFileName
|
|
|
+ }
|
|
|
+ }
|
|
|
+ `, { trackId: JSON.stringify([{ _id }]) }))
|
|
|
+
|
|
|
+//add track to playlist
|
|
|
const actionAddTrack = file =>
|
|
|
async (dispatch, getState) => {
|
|
|
- await dispatch(actionLoadFile(file, 'track'))
|
|
|
- let trackId = getState().promise?.loadFile?.payload?._id
|
|
|
let playlistId = "61e3506ac2305e2f502aca03"
|
|
|
- await dispatch(actionPromise('trackToPlaylist', gql(`
|
|
|
+ await dispatch(actionLoadFile(file, 'track'))
|
|
|
+ await dispatch(actionGetTrackById(getState().promise.loadFile.payload?._id))
|
|
|
+ await dispatch(actionGetPlaylistById(playlistId))
|
|
|
+
|
|
|
+ let arr = [...getState().promise.track.payload]
|
|
|
+ arr.push(...getState().promise.playlistTracks.payload[0].tracks)
|
|
|
+ console.log('newarr', arr)
|
|
|
+ //let updated = JSON.stringify(arr)
|
|
|
+ //let trackId = getState().promise?.loadFile?.payload?._id
|
|
|
+
|
|
|
+ // await dispatch(actionPromise('trackToPlaylist', gql(`
|
|
|
+ // mutation {
|
|
|
+ // PlaylistUpsert(playlist:{ _id: "${playlistId}", tracks: {_id: "${trackId}"}}) {
|
|
|
+ // _id, name, tracks { _id, originalFileName }
|
|
|
+ // }
|
|
|
+ // }
|
|
|
+ // `)))
|
|
|
+
|
|
|
+ await dispatch(actionPromise('trackToPlaylist', gql(`
|
|
|
mutation {
|
|
|
- PlaylistUpsert(playlist:{ _id: ${playlistId}, tracks: {_id: ${trackId} } }) {
|
|
|
+ PlaylistUpsert(playlist:{ _id: "${playlistId}", tracks: [{_id: "61e4b26ec2305e2f502acaae"}, {_id: "61e4a4cac2305e2f502aca98"}] })] {
|
|
|
_id, name, tracks { _id, originalFileName }
|
|
|
}
|
|
|
}
|
|
|
`)))
|
|
|
+
|
|
|
+ // await dispatch(actionPromise('trackToPlaylist', gql(`
|
|
|
+ // mutation {
|
|
|
+ // PlaylistUpsert(playlist:{ _id: $playlistId, tracks: $tracks}}) {
|
|
|
+ // _id, name, tracks { _id, originalFileName }
|
|
|
+ // }
|
|
|
+ // }
|
|
|
+ // `, { playlistId:JSON.stringify([{ playlistId }]), tracks: JSON.stringify(arr) })))
|
|
|
+
|
|
|
dispatch(actionGetUserTracks())
|
|
|
}
|
|
|
|