function followUser(followed, follower_id) {
  return dispatch => {
    const token = localStorage.token
    const reqPostObj = {
      method: "POST",
      headers: {
        "Content-type": "application/json",
        Accepts: "application/json",
        Authorization: `Bearer ${token}`
      },
      body: JSON.stringify({
        follower_id: follower_id,
        followed_id: followed.id
      })
    }
    return fetch(fetchFollowingsUrl, reqPostObj)
      .then(res => res.json())
      .then(data => {
        console.log(data)
        if (data.error) {
          // console.log(data.error)
        } else {
          alert(`You've followed ${followed.username}`)
          // dispatch(addFollowedUser(data))
        }
      })
      .catch(err => console.log(err))
  }
}
// ! Should update the followeds array in the store
Should update the followeds array in the store
Should update the followeds array in the store
function followUser(followed, follower_id) {
  return dispatch => {
    const token = localStorage.token
    const reqPostObj = {
      method: "POST",
      headers: {
        "Content-type": "application/json",
        Accepts: "application/json",
        Authorization: `Bearer ${token}`
      },
      body: JSON.stringify({
        follower_id: follower_id,
        followed_id: followed.id
      })
    }
    return fetch(fetchFollowingsUrl, reqPostObj)
      .then(res => res.json())
      .then(data => {
        console.log(data)
        if (data.error) {
        } else {
          alert(`You've followed ${followed.username}`)
        }
      })
      .catch(err => console.log(err))
  }
}
function followUser ( followed , follower_id ) { return dispatch => { const token = localStorage . token const reqPostObj = { method : "POST" , headers : { "Content-type" : "application/json" , Accepts : "application/json" , Authorization : ` ${ token } ` } , body : JSON . stringify ( { follower_id : follower_id , followed_id : followed . id } ) } return fetch ( fetchFollowingsUrl , reqPostObj ) . then ( res => res . json ( ) ) . then ( data => { console . log ( data ) if ( data . error ) { } else { alert ( ` ${ followed . username } ` ) } } ) . catch ( err => console . log ( err ) ) } }
Should update the followeds array in the store
Should update the followeds array in the store
// console.log(data.error) // dispatch(addFollowedUser(data))