Bruno Predot

Modification du composable useTMDB en ajoutant et export de la fonction fetchPop…

…ularMovies, suppresion des export des const apiUrl et apiKey.
... ... @@ -2,9 +2,27 @@ import type { RuntimeConfig } from "nuxt/schema";
export const useTMDB = function() {
const runtimeconfig: RuntimeConfig = useRuntimeConfig();
const apiUrl = runtimeconfig.public.apiTMDBUrl;
const apiKey = runtimeconfig.public.apiTMDBSecret;
return {apiUrl, apiKey}
/**
* Fetch popular movies.
* @param page
*/
const fetchPopularMovies = async (page: number) => {
try {
const response = await fetch(
`${apiUrl}/movie/popular?api_key=${apiKey}&language=fr-FR&page=${page}`,
);
if (!response.ok) {
console.error("An error occured when fetching popular movies:");
} else {
return await response.json();
}
} catch (error) {
console.error("Error fetching popular movies:", error);
}
};
return { fetchPopularMovies }
}
\ No newline at end of file
... ...