From 9788e6960cf179c4abf056d5d618f9d41253cfa0 Mon Sep 17 00:00:00 2001
From: Daniel Kovacs <daniel.kovacs@inepex.com>
Date: Fri, 6 Dec 2019 01:30:40 +0100
Subject: [PATCH] asd

---
 backend/server.js                             |  4 ++++
 frontend/src/actions/playlistActions.js       | 15 -------------
 .../components/dashboard/SpotifyPlaylist.js   |  2 +-
 frontend/src/components/join/Join.js          | 21 ++++++++++++-------
 4 files changed, 18 insertions(+), 24 deletions(-)

diff --git a/backend/server.js b/backend/server.js
index 4682124..4151af6 100644
--- a/backend/server.js
+++ b/backend/server.js
@@ -113,6 +113,7 @@ app.post('/joinparty/:partyid', (req, res) => {
   var config ={
     headers: {Authorization: 'Bearer ' + req.body.token}
   };
+  console.log(request.body.token).
   let genres = [];
   let genres_temp = [];
   let trackNum=0;
@@ -249,10 +250,13 @@ app.post('/saveplaylist/:id', (req,res) => {
               axios.post(`https://api.spotify.com/v1/playlists/${playlistId}/tracks?${track_ids}`,{},config).then(result =>{
                 console.log(result.data)
                 db.run('DELETE FROM party WHERE id=?',[req.params.id], () => {
+                  console.log("one")
                   db.run('DELETE FROM songs WHERE party_id=?', [req.params.id],
                       () => {
+                    console.log("two")
                         db.run('DELETE FROM party_members WHERE party_id =?',
                             [req.params.id], () => {
+                          console.log("three")
                             }
                         )
                       })
diff --git a/frontend/src/actions/playlistActions.js b/frontend/src/actions/playlistActions.js
index d75a2f7..ac0d3be 100644
--- a/frontend/src/actions/playlistActions.js
+++ b/frontend/src/actions/playlistActions.js
@@ -79,21 +79,6 @@ export const getPartyDetails = (partyId) => dispatch => {
   );
 }
 
-export const joinParty = (pData) => dispatch => {
-
-  console.log(pData)
-  axios.post(`https://thespotifierapp.herokuapp.com/joinparty/${pData.party_id}`,pData)
-  .then(res =>{
-    console.log(res.data)
-      }
-     )
-  .catch(err=>
-      dispatch({
-        type: GET_ERRORS,
-        payload: err
-      })
-  );
-}
 
 
 //ADD PLAYLIST
diff --git a/frontend/src/components/dashboard/SpotifyPlaylist.js b/frontend/src/components/dashboard/SpotifyPlaylist.js
index 4268d68..84e8e2a 100644
--- a/frontend/src/components/dashboard/SpotifyPlaylist.js
+++ b/frontend/src/components/dashboard/SpotifyPlaylist.js
@@ -42,7 +42,7 @@ class AllProject extends Component {
 
         let playlistContent;
 
-            if (this.props.playlists.loading===false && playlists!==null){
+            if (this.props.playlists.loading===false && playlists!==null && playlists.spotifyPlaylists!==null){
             playlistContent=(
                 playlists.spotifyPlaylists.items.map(playlist => (
                         <tr key={playlist.name}>
diff --git a/frontend/src/components/join/Join.js b/frontend/src/components/join/Join.js
index 6ecbde0..488a27d 100644
--- a/frontend/src/components/join/Join.js
+++ b/frontend/src/components/join/Join.js
@@ -1,8 +1,8 @@
 import React, { Component, Fragment } from 'react'
 import {Link, withRouter} from 'react-router-dom';
-import {joinParty} from '../../actions/playlistActions'
 import connect from "react-redux/es/connect/connect";
 import {getCurrentProfile} from "../../actions/profileActions";
+import axios from "axios";
 
 
 class Join extends Component {
@@ -15,14 +15,18 @@ class Join extends Component {
     this.onSubmit = this.onSubmit.bind(this);
     this.state={
       profile : null,
-      token: null
+      token: null,
+      joined: false
     }
 
   }
 
-  onSubmit = param => (e) => {
+  onSubmit = param => async (e) => {
 
-    this.props.joinParty(param, this.props.history);
+
+    const response = await axios.post(`https://thespotifierapp.herokuapp.com/joinparty/${param.party_id}`,param)
+    console.log(response)
+    this.setState({joined:true})
 
   }
 
@@ -50,7 +54,7 @@ class Join extends Component {
 
 
 
-    return <div className="add-project">
+    return (!this.state.joined) ? (<div className="add-project">
       <div className="containter">
         <div className="row">
           <div className="col-lg-12">
@@ -91,8 +95,9 @@ class Join extends Component {
           </div>
         </div>
       </div>
-    </div>
-  }
+    </div>) : <div className="col-lg-12"> You joined to this event! </div>
+
+    }
 }
 
 
@@ -101,4 +106,4 @@ const mapStateToProps = state => ({
   auth: state.auth
 })
 
-export default connect(mapStateToProps,{getCurrentProfile,joinParty})(withRouter(Join));
\ No newline at end of file
+export default connect(mapStateToProps,{getCurrentProfile})(withRouter(Join));
\ No newline at end of file
-- 
GitLab