Skip to content

Commit

Permalink
WJ-17 - Update: Minifying favorite list method;
Browse files Browse the repository at this point in the history
  • Loading branch information
Lucas Teixeira committed Sep 5, 2020
1 parent 1301f05 commit 132f70f
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 15 deletions.
22 changes: 8 additions & 14 deletions src/domains/Favorites/api/List/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,27 +19,21 @@ export const rawFavorites = async (): Promise<RawResponse[]> => {
const parseResponse = async (
rawResponse: RawResponse[],
): Promise<Response[]> => {
let response = [] as any[];
const response = rawResponse.map(async (favorite: RawResponse) => {
// Get favorites details from TMDB API and merge
const details = await Details(favorite.movie_id);

// Parse API user favorites
rawResponse.forEach(favorite => {
const parsedFavorite = {
// Merge API and TMDB results
return {
...details,
id: favorite.id,
userId: favorite.user_id,
movieId: favorite.movie_id,
};

response = [...response, parsedFavorite];
});

// Get favorites details from TMDB API and merge
const parsedResponse = response.map(async (favorite: Response) => {
const details = await Details(favorite.movieId);

return { ...details, ...favorite, id: favorite.id };
});

const resolvedResponse = await Promise.all(parsedResponse);
// Resolve async requests and promises
const resolvedResponse = Promise.all(response);

return resolvedResponse;
};
Expand Down
1 change: 0 additions & 1 deletion src/screens/Home/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ const Home: React.FC = () => {
NowPlaying().then(response => setNowPlayingList(response));
Popular().then(response => setPopularList(response));
Favorites().then(response => {
console.log('response', response);
setFavoriteList(response);
});
}, []);
Expand Down

0 comments on commit 132f70f

Please sign in to comment.