|
@@ -1,6 +1,21 @@
|
|
|
// import {gql} from "../utils/getGQL";
|
|
|
-import { getGQL } from "../utils/getGQL";
|
|
|
+import { getGQL, openNotification } from "../utils/getGQL";
|
|
|
import * as actions from "../constants/actions/index";
|
|
|
+// import { Button, notification } from "antd";
|
|
|
+
|
|
|
+// const openNotification = (
|
|
|
+// type = "info",
|
|
|
+// title = "info",
|
|
|
+// description = "Some params are missing"
|
|
|
+// ) => {
|
|
|
+// notification[type]({
|
|
|
+// message: title,
|
|
|
+// description: description,
|
|
|
+// onClick: () => {
|
|
|
+// console.log("Notification Clicked!");
|
|
|
+// },
|
|
|
+// });
|
|
|
+// };
|
|
|
|
|
|
const setTracks = (tracks) => ({
|
|
|
type: actions.SET_TRACKS,
|
|
@@ -29,18 +44,11 @@ export const getTracks = () => async (dispatch) => {
|
|
|
query: JSON.stringify([
|
|
|
{},
|
|
|
{
|
|
|
- limit: [10],
|
|
|
+ limit: [12],
|
|
|
},
|
|
|
]),
|
|
|
}
|
|
|
);
|
|
|
- // .then((data) => {
|
|
|
- // console.log(data)
|
|
|
- // return
|
|
|
- // await dispatch(setTracks(data.data.TrackFind));
|
|
|
- // console.log(response);
|
|
|
-
|
|
|
- // });
|
|
|
await dispatch(setTracks(response.data.TrackFind));
|
|
|
console.log("response.data.TrackFind: ", response.data.TrackFind);
|
|
|
} catch (error) {
|
|
@@ -48,13 +56,17 @@ export const getTracks = () => async (dispatch) => {
|
|
|
}
|
|
|
};
|
|
|
|
|
|
+export const setTrack = (track) => ({
|
|
|
+ type: actions.SET_TRACK,
|
|
|
+ track,
|
|
|
+});
|
|
|
+
|
|
|
export const clearTrackList = () => ({
|
|
|
type: actions.CLEAR_TRACK_LIST,
|
|
|
});
|
|
|
|
|
|
export const getPlaylist = () => async (dispatch) => {
|
|
|
try {
|
|
|
- // debugger
|
|
|
let response = await getGQL("/graphql", {
|
|
|
Authorization: `Bearer ${localStorage.authToken}`,
|
|
|
})(
|
|
@@ -65,6 +77,7 @@ export const getPlaylist = () => async (dispatch) => {
|
|
|
name
|
|
|
description
|
|
|
tracks{
|
|
|
+ originalFileName
|
|
|
url
|
|
|
id3{
|
|
|
artist
|
|
@@ -79,12 +92,7 @@ export const getPlaylist = () => async (dispatch) => {
|
|
|
}
|
|
|
}`,
|
|
|
{
|
|
|
- query: JSON.stringify([
|
|
|
- {},
|
|
|
- // {
|
|
|
- // limit: [10],
|
|
|
- // },
|
|
|
- ]),
|
|
|
+ query: JSON.stringify([{}]),
|
|
|
}
|
|
|
);
|
|
|
console.log("response in getPlaylist: ", response);
|
|
@@ -99,11 +107,6 @@ const setPlayList = (playlists) => ({
|
|
|
playlists,
|
|
|
});
|
|
|
|
|
|
-// export const setTrack = (track) => ({
|
|
|
-// type: actions.SET_TRACK,
|
|
|
-// track,
|
|
|
-// });
|
|
|
-
|
|
|
export const createMyPlaylist = (name, id) => async (dispatch) => {
|
|
|
console.log("name in action: ", name);
|
|
|
try {
|
|
@@ -138,16 +141,14 @@ export const findMyPlaylists = () => async (dispatch) => {
|
|
|
name
|
|
|
_id
|
|
|
description
|
|
|
- tracks{
|
|
|
- _id
|
|
|
- }}
|
|
|
+ }
|
|
|
}`,
|
|
|
{
|
|
|
query: JSON.stringify([{}]),
|
|
|
}
|
|
|
);
|
|
|
console.log(response.data.PlaylistFind);
|
|
|
- await dispatch(setFindMyPlaylists(response.data.PlaylistFind))
|
|
|
+ await dispatch(setFindMyPlaylists(response.data.PlaylistFind));
|
|
|
} catch (error) {
|
|
|
console.log(error);
|
|
|
}
|
|
@@ -158,11 +159,6 @@ const setFindMyPlaylists = (showMyPlaylists) => ({
|
|
|
showMyPlaylists,
|
|
|
});
|
|
|
|
|
|
-export const setTrack = (track) => ({
|
|
|
- type: actions.SET_TRACK,
|
|
|
- track,
|
|
|
-});
|
|
|
-
|
|
|
export const oneTrackFind = (id) => async (dispatch) => {
|
|
|
try {
|
|
|
let response = await getGQL("/graphql", {
|
|
@@ -193,8 +189,6 @@ export const oneTrackFind = (id) => async (dispatch) => {
|
|
|
)
|
|
|
);
|
|
|
});
|
|
|
- // console.log('response: ', response);
|
|
|
- // dispatch(actionSetTrack(response.data.PlaylistFindOne.tracks, response.data.PlaylistFindOne.name, response.data.PlaylistFindOne._id));
|
|
|
} catch (error) {}
|
|
|
};
|
|
|
|
|
@@ -233,3 +227,145 @@ export const setFindUser = (userId) => ({
|
|
|
type: actions.FIND_MY_USER,
|
|
|
userId,
|
|
|
});
|
|
|
+
|
|
|
+export const findCurrentPlaylist = () => async (dispatch) => {
|
|
|
+ let response = await getGQL("/graphql", {
|
|
|
+ Authorization: `Bearer ${localStorage.authToken}`,
|
|
|
+ })(
|
|
|
+ `query allPlaylists{
|
|
|
+ PlaylistFindOne(query:"[{\\"_id\\":\\"${localStorage.lastPLaylist}\\"}]"){
|
|
|
+ _id
|
|
|
+ name
|
|
|
+ tracks {
|
|
|
+ _id
|
|
|
+ originalFileName
|
|
|
+ url
|
|
|
+ id3{
|
|
|
+ title
|
|
|
+ album
|
|
|
+ artist
|
|
|
+ }}}
|
|
|
+ }`,
|
|
|
+ {
|
|
|
+ query: JSON.stringify([{}]),
|
|
|
+ }
|
|
|
+ );
|
|
|
+ console.log(response.data.PlaylistFindOne);
|
|
|
+ await dispatch(myCurrentPlaylist(response.data.PlaylistFindOne));
|
|
|
+};
|
|
|
+
|
|
|
+const myCurrentPlaylist = (playlist) => ({
|
|
|
+ type: actions.MY_CURRENT_PLAYLIST,
|
|
|
+ playlist,
|
|
|
+});
|
|
|
+
|
|
|
+export const searchTrack = (trackName) => async (dispatch) => {
|
|
|
+ let response = await getGQL("/graphql", {
|
|
|
+ Authorization: `Bearer ${localStorage.authToken}`,
|
|
|
+ })(
|
|
|
+ `query trackFind{
|
|
|
+ TrackFindOne(query: "[{\\"originalFileName\\":\\"${trackName}\\"}]"){
|
|
|
+ originalFileName
|
|
|
+ url
|
|
|
+ _id
|
|
|
+ id3 {
|
|
|
+ title
|
|
|
+ album
|
|
|
+ artist
|
|
|
+ }
|
|
|
+ }`
|
|
|
+ );
|
|
|
+ console.log(response.data.TrackFindOne);
|
|
|
+ await dispatch(setSearchTrack(response.data.TrackFindOne));
|
|
|
+};
|
|
|
+
|
|
|
+const setSearchTrack = (findTrack) => ({
|
|
|
+ type: actions.SEARCH_TRACK,
|
|
|
+ findTrack,
|
|
|
+});
|
|
|
+
|
|
|
+export const addTrackToPlaylist = (idPlaylist, arrTracks, idTrack) => async (
|
|
|
+ dispatch
|
|
|
+) => {
|
|
|
+ try {
|
|
|
+ let tracksArr = [...arrTracks, { ["_id"]: idTrack }];
|
|
|
+ console.log("tracksArr in addTrackToPlaylist: ", tracksArr);
|
|
|
+
|
|
|
+ let response = await getGQL("/graphql", {
|
|
|
+ Authorization: `Bearer ${localStorage.authToken}`,
|
|
|
+ })(
|
|
|
+ `mutation addtrack($idPlaylist:ID,$tracksArr:[TrackInput]){
|
|
|
+ PlaylistUpsert(playlist: {
|
|
|
+ _id: $idPlaylist,
|
|
|
+ tracks:$tracksArr
|
|
|
+ }){_id}
|
|
|
+ }`,
|
|
|
+ {
|
|
|
+ idPlaylist: idPlaylist,
|
|
|
+ tracksArr: tracksArr,
|
|
|
+ }
|
|
|
+ );
|
|
|
+ openNotification(
|
|
|
+ "success",
|
|
|
+ "Info",
|
|
|
+ "Uploading was completed successfully!"
|
|
|
+ );
|
|
|
+ dispatch(findCurrentPlaylist());
|
|
|
+ } catch (error) {
|
|
|
+ console.error(error);
|
|
|
+ openNotification(
|
|
|
+ "error",
|
|
|
+ "Error",
|
|
|
+ `Uploading was interrupted! ${error.message}`
|
|
|
+ );
|
|
|
+ }
|
|
|
+};
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+export const deleteTrackFromPlaylist = (
|
|
|
+ // idPlaylist,
|
|
|
+ // arrTracks,
|
|
|
+ // trackIndex
|
|
|
+ idPlaylist,
|
|
|
+ playlist,
|
|
|
+ currentIndex
|
|
|
+) => async (dispatch) => {
|
|
|
+try {
|
|
|
+ let tracksArr = []
|
|
|
+ playlist.tracks && playlist.tracks.map( (track)=>tracksArr.push({["_id"]: track._id}) )
|
|
|
+ tracksArr.splice(currentIndex, 1)
|
|
|
+
|
|
|
+// let response = await getGQL("/graphql",
|
|
|
+
|
|
|
+// )
|
|
|
+
|
|
|
+ let response = await getGQL("/graphql", {
|
|
|
+ Authorization: `Bearer ${localStorage.authToken}`,
|
|
|
+ })(
|
|
|
+ `mutation addtrack($idPlaylist:ID,$tracksArr:[TrackInput]){
|
|
|
+ PlaylistUpsert(playlist: {
|
|
|
+ _id: $idPlaylist,
|
|
|
+ tracks:$tracksArr
|
|
|
+ }){_id}
|
|
|
+ }`,
|
|
|
+ {
|
|
|
+ idPlaylist: idPlaylist,
|
|
|
+ tracksArr: tracksArr,
|
|
|
+ }
|
|
|
+ );
|
|
|
+ openNotification(
|
|
|
+ "success",
|
|
|
+ "Info",
|
|
|
+ "Delete was completed successfully!"
|
|
|
+ );
|
|
|
+ dispatch(findCurrentPlaylist());
|
|
|
+} catch (error) {
|
|
|
+ console.error(error);
|
|
|
+ openNotification(
|
|
|
+ "error",
|
|
|
+ "Error",
|
|
|
+ `Delete was interrupted! ${error.message}`
|
|
|
+ );
|
|
|
+}
|
|
|
+};
|