|
@@ -1,7 +1,6 @@
|
|
|
import { jwtDecode, gql } from '../App'
|
|
|
|
|
|
const actionPending = name => ({ type: 'PROMISE', status: 'PENDING', name })
|
|
|
-
|
|
|
const actionResolved = (name, payload) => ({ type: 'PROMISE', status: 'RESOLVED', name, payload })
|
|
|
const actionRejected = (name, error) => ({ type: 'PROMISE', status: 'REJECTED', name, error })
|
|
|
export const actionPromise = (name, promise) =>
|
|
@@ -31,7 +30,9 @@ export const actionFullLogin = (login = 'tst', password = '123') =>
|
|
|
let token = await dispatch(actionLogin(login, password))
|
|
|
if (token) {
|
|
|
await dispatch(actionAuthLogin(token))
|
|
|
- dispatch(actionGetUserData())
|
|
|
+ await dispatch(actionGetUserData())
|
|
|
+ dispatch(actionGetUserPlaylists())
|
|
|
+ dispatch(actionGetUserTracks())
|
|
|
}
|
|
|
}
|
|
|
|
|
@@ -64,14 +65,35 @@ export const actionGetUserData = () => {
|
|
|
)
|
|
|
}
|
|
|
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
+const actionGetUserPlaylists = () => {
|
|
|
+ let _id = jwtDecode(localStorage.authToken).sub.id
|
|
|
+ return(
|
|
|
+ actionPromise('userPlaylists', gql(`
|
|
|
+ query getPlaylistByOwnerId($ownerId:String!) {
|
|
|
+ PlaylistFind(query: $ownerId) {
|
|
|
+ _id, name
|
|
|
+ }
|
|
|
+ }
|
|
|
+ `, { ownerId: JSON.stringify([{ ___owner: _id }]) } ))
|
|
|
+ )
|
|
|
+}
|
|
|
+
|
|
|
+const actionGetUserTracks = () => {
|
|
|
+ let _id = jwtDecode(localStorage.authToken).sub.id
|
|
|
+ return(
|
|
|
+ actionPromise('userTracks', gql(`
|
|
|
+ query getUserTracks($ownerId: String!) {
|
|
|
+ TrackFind(query: $ownerId) {
|
|
|
+ _id,
|
|
|
+ id3 {
|
|
|
+ title, artist
|
|
|
+ }
|
|
|
+ playlists {
|
|
|
+ _id, name
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ `, { ownerId: JSON.stringify([{ ___owner: _id }]) } ))
|
|
|
+ )
|
|
|
+}
|
|
|
|