function addTofavorites()

in Elastiflix/javascript-client/src/components/Header.js [9:35]


function addTofavorites(movie, favorites, setfavorites, setIsLoading, setLastRequestSuccessful) {
  setIsLoading(true);
  // sleep for 1 second

  fetch(endpoint + '/api/favorites', {
    method: 'POST',
    mode: "cors",
    headers: {
      'Content-Type': 'application/json'
    },
    
    body: JSON.stringify(movie)
  })
  .then(res => res.json())
  .then(data => {
    console.log(data.favorites)
    console.log(movie.id)
    console.log(data)
    if (data.error != null) {
      setLastRequestSuccessful(false);
    } else {
      setfavorites(data.favorites)
      setLastRequestSuccessful(true);
    }
    setIsLoading(false);
  })
}