diff --git a/src/App.tsx b/src/App.tsx index c8e6ff7..c79f4ee 100644 --- a/src/App.tsx +++ b/src/App.tsx @@ -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%", diff --git a/src/objects/tmdb.tsx b/src/objects/tmdb.tsx index 87a2956..4d2b995 100644 --- a/src/objects/tmdb.tsx +++ b/src/objects/tmdb.tsx @@ -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