refesh data on config change

This commit is contained in:
andrzej 2024-05-22 14:38:30 +02:00
parent 84d3bcf68e
commit 5004e2941f
2 changed files with 19 additions and 1 deletions

View File

@ -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%",

View File

@ -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