refesh data on config change
This commit is contained in:
		
							parent
							
								
									84d3bcf68e
								
							
						
					
					
						commit
						5004e2941f
					
				| 
						 | 
				
			
			@ -17,7 +17,7 @@ export type Config = {
 | 
			
		|||
  locale: string
 | 
			
		||||
}
 | 
			
		||||
class MovieClass implements Movie {
 | 
			
		||||
  id = null
 | 
			
		||||
  id = 0
 | 
			
		||||
  poster_path = null
 | 
			
		||||
  backdrop_path = null
 | 
			
		||||
  title = null
 | 
			
		||||
| 
						 | 
				
			
			@ -47,6 +47,12 @@ function App() {
 | 
			
		|||
  useEffect(() => {
 | 
			
		||||
    tmdb.getWhereToWatch(chosenMovie, setWatchProviders, config)
 | 
			
		||||
  }, [chosenMovie])
 | 
			
		||||
  //Whenever config changes, refresh data for current selection
 | 
			
		||||
  useEffect(() => {
 | 
			
		||||
    console.log("CONFIG CHANGED!!")
 | 
			
		||||
    tmdb.getMovie(config, chosenMovie.id, setChosenMovie)
 | 
			
		||||
    tmdb.getSimilar(config, chosenMovie, setMovies, setSimilarMoviesAvailable)
 | 
			
		||||
  }, [config])
 | 
			
		||||
  const crossfadeImageStyles = {
 | 
			
		||||
    width: "2560px",
 | 
			
		||||
    minHeight: "100%",
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -11,6 +11,18 @@ const tmdb = axios.create({
 | 
			
		|||
  }
 | 
			
		||||
})
 | 
			
		||||
export default {
 | 
			
		||||
  getMovie: async function({ language }: Config, id: number, setChosenMovie: Function) {
 | 
			
		||||
    let res = await tmdb.get("/" + id, {
 | 
			
		||||
      params: {
 | 
			
		||||
        language
 | 
			
		||||
      }
 | 
			
		||||
    })
 | 
			
		||||
    if (res.status == 200) {
 | 
			
		||||
      setChosenMovie(res.data)
 | 
			
		||||
    } else {
 | 
			
		||||
      throw Error("API call failed! Response: " + JSON.stringify(res))
 | 
			
		||||
    }
 | 
			
		||||
  },
 | 
			
		||||
  /**
 | 
			
		||||
* Calls tmdb API/popular and then fires the callback with res.data.results as argument
 | 
			
		||||
* @param {Function} callback
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
		Reference in New Issue