-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
WJ-17 - Update: Refactoring Movie container to component;
- Loading branch information
Lucas Teixeira
committed
Sep 4, 2020
1 parent
262fccd
commit 5a3ce30
Showing
13 changed files
with
109 additions
and
2 deletions.
There are no files selected for viewing
File renamed without changes.
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
export { default as Footer } from './Footer'; | ||
export { default as Header } from './Header'; | ||
export { default as Highlights } from './Highlights'; | ||
export { default as Movie } from './Movie'; | ||
export { default as Movie } from '../components/Movie'; | ||
export { default as MovieList } from './MovieList'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
export default interface RawResponse { | ||
id: string; | ||
user_id: string; | ||
movie_id: string; | ||
created_at: string; | ||
updated_at: string; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
export default interface Response { | ||
id: string; | ||
userId: string; | ||
movieId: string; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
import api from 'services/api'; | ||
|
||
import RawResponse from 'domains/Favorites/api/List/RawResponse'; | ||
import Response from 'domains/Favorites/api/List/Response'; | ||
|
||
const Favorites = async (): Promise<Response[]> => { | ||
const response = await rawFavorites(); | ||
|
||
return parseResponse(response); | ||
}; | ||
|
||
export const rawFavorites = async (): Promise<RawResponse[]> => { | ||
const response = await api.get('/favorites'); | ||
|
||
return response.data; | ||
}; | ||
|
||
const parseResponse = (rawResponse: RawResponse[]): Response[] => { | ||
let response = [] as Response[]; | ||
|
||
rawResponse.forEach(favorite => { | ||
const parsedFavorite = { | ||
id: favorite.id, | ||
userId: favorite.user_id, | ||
movieId: favorite.movie_id, | ||
} as Response; | ||
|
||
response = [...response, parsedFavorite]; | ||
}); | ||
|
||
return response; | ||
}; | ||
|
||
export default Favorites; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export { default as Favorites } from './List'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
// import LoginCredentials from './LoginCredentials'; | ||
|
||
export default interface ContextData { | ||
user?: object; | ||
// login(loginCredentials: LoginCredentials): Promise<void>; | ||
// logout(): void; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
export default interface FavoritesState { | ||
token?: string; | ||
user?: object; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
import React, { createContext, useCallback, useContext, useState } from 'react'; | ||
import api from 'services/api'; | ||
|
||
// import { postRawFavorites } from 'domains/Favorites/api/PostFavorites'; | ||
import ContextData from '../dtos/ContextData'; | ||
import FavoritesState from '../dtos/FavoritesState'; | ||
|
||
const FavoritesContext = createContext<ContextData>({} as ContextData); | ||
|
||
const FavoritesProvider: React.FC = ({ children }) => { | ||
const [data, setData] = useState<FavoritesState>(() => { | ||
return {} as FavoritesState; | ||
}); | ||
|
||
// const update = useCallback(async ({ movieId }): Promise<void> => { | ||
// const response = await updateFavorites({ movieId }); | ||
|
||
// if (response) { | ||
// setData({ ...data, response }); | ||
// return; | ||
// } | ||
|
||
// const newData = data.filter(favorite => favorite) | ||
|
||
// }, []); | ||
|
||
return ( | ||
<FavoritesContext.Provider value={{}}>{children}</FavoritesContext.Provider> | ||
); | ||
}; | ||
|
||
function useFavorites(): ContextData { | ||
const context = useContext(FavoritesContext); | ||
|
||
if (!context) { | ||
throw new Error('useFavorites must be used within an FavoritesProvider.'); | ||
} | ||
|
||
return context; | ||
} | ||
|
||
export { FavoritesProvider, useFavorites }; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters