refesh data on config change
This commit is contained in:
parent
84d3bcf68e
commit
5004e2941f
|
@ -17,7 +17,7 @@ export type Config = {
|
||||||
locale: string
|
locale: string
|
||||||
}
|
}
|
||||||
class MovieClass implements Movie {
|
class MovieClass implements Movie {
|
||||||
id = null
|
id = 0
|
||||||
poster_path = null
|
poster_path = null
|
||||||
backdrop_path = null
|
backdrop_path = null
|
||||||
title = null
|
title = null
|
||||||
|
@ -47,6 +47,12 @@ function App() {
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
tmdb.getWhereToWatch(chosenMovie, setWatchProviders, config)
|
tmdb.getWhereToWatch(chosenMovie, setWatchProviders, config)
|
||||||
}, [chosenMovie])
|
}, [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 = {
|
const crossfadeImageStyles = {
|
||||||
width: "2560px",
|
width: "2560px",
|
||||||
minHeight: "100%",
|
minHeight: "100%",
|
||||||
|
|
|
@ -11,6 +11,18 @@ const tmdb = axios.create({
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
export default {
|
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
|
* Calls tmdb API/popular and then fires the callback with res.data.results as argument
|
||||||
* @param {Function} callback
|
* @param {Function} callback
|
||||||
|
|
Loading…
Reference in New Issue