Преглед на файлове

actions for getting user playlist and tracks written

miskson преди 2 години
родител
ревизия
14dff273f0
променени са 1 файла, в които са добавени 34 реда и са изтрити 12 реда
  1. 34 12
      src/actions/index.js

+ 34 - 12
src/actions/index.js

@@ -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 actionGetPlaylists = (userId = "5fe35e1ce926687ee86b0a3f") => {
-//     actionPromise('getPlaylists', gql(`
-//             query getPlaylistByOwnerId($ownerId:String!) {
-//                 PlaylistFind(query: $ownerId) {
-//                 _id, name
-//                 }
-//             }
-//         `, { ownerId: JSON.stringify([{ ___owner: userId }]) })
-//     )
-// }
+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 }]) } ))
+    )
+}