diff --git a/README.md b/README.md index 0ea29ec..4281739 100644 --- a/README.md +++ b/README.md @@ -1,23 +1,17 @@ -A simple app that allows users to search for movies by title, review the search results and navigate to a movie’s detail page. -It contains: +# Movie Search +### `A simple app that allows users to search for movies by title, review the search results and navigate to a movie’s detail page.` -- Navbar +### Containing: + +- NavBar - A page to search for movies by title: - - searchParams to string - - Object.entries(searchParams) - .map( - ([key, value], i, arr) => - `${key}=${value}${i < arr.length - 1 ? "&" : ""}` - ) - .toString(); - - SearchBar component: - Input for Title - Submit button - Clear button - - List of results - paginated so we might need a pagination component: + - List of results: - Title - Year - Type (Filter out "series"?) - hidden ? @@ -26,7 +20,7 @@ It contains: Error Handling component - A page for individual movie details: - - Movie component: + - Movie Details component: - Title - Year - Rated @@ -41,7 +35,7 @@ It contains: - Country - Awards - Poster - - Ratings: [ { Source } ] + - Ratings: `[ { Source, Value } ]` - Metascore - imdbRating - imdbVotes @@ -53,27 +47,28 @@ It contains: - Website - Response -External API Docs: https://www.omdbapi.com/ +### External API Docs: [OMDB](https://www.omdbapi.com/) -Built on: -Next.js -Server side rendering for list & movie details to hide api token/network requests and eliminate the need for state-management on data returned from the external API. +### Built on: + Next.js + Server side rendering for search results list & movie details to hide api token/network requests and eliminate the need for state-management on data returned from the external API. -Switched to Tailwindcss for styling. Was using chakra ui components but it isn't server-side render friendly + Switched to [tailwindcss](https://tailwindcss.com/) for styling. Was using [chakra ui](https://v2.chakra-ui.com/) components but it isn't server-side render friendly -Using React Context because Redux is cool for a good number of things, but when built correctly - React Context is powerful enough for most apps. It can be layered if need be, but for this example we will stick with a simple context: +### State Management: + Using React Context + simple useState management because Redux is cool for a good number of things, especially larger apps that need a central, client-side store to manage many peices of state in one place, as well as helper functions to manage data functions and state mutation. - React Context in combination with simple state managment hooks like useState or useReducer is powerful enough for most small apps that only need to manage a small amount of state in separate places. It can be layered if need be, but for this example we will stick with a simple context: -Since we're using server side rendering for pages that fetch data, we don't need a lot of state management. -We can implement Context in a client component for managing "Favorites" for a user if we'd like -this might look like: + Since we're using server side rendering for pages that fetch data, we don't need a lot of state management. + We can implement Context in a client component for managing "Favorites" for a user if we'd like + this might look like: -- FavoriteContext - favorites, setFavorites + - FavoriteContext - favorites, setFavorites -- FavoriteProvider - A wrapper for FavoriteContext.Provider with local state that we can render client-side and pass children through to make use of server-side rendering for child components (interleaving) + - FavoriteProvider - A wrapper for FavoriteContext.Provider with local state that we can render client-side and pass children through to make use of server-side rendering for child components (interleaving) -- FavoriteBtn - a client-side component rendering a button and using useContext(FormContext) to consume favorites and setFavorites - filter favorites by id to prevent duplicats/allow removing from list. + - FavoriteBtn - a client-side component rendering a button and using useContext(FormContext) to consume favorites and setFavorites - filter favorites by id to prevent duplicats/allow removing from list. -Known issues: - * https://github.com/vercel/next.js/issues/65161 - * https://github.com/vercel/next.js/issues/54757 - \ No newline at end of file +### Known Issues: + * [Error when testing components using NextJS Image](https://github.com/vercel/next.js/issues/65161) + * [Jest cannot test form actions - this is how we would test our SearchBar component fully in a unit test. E2E testing should be able to cover this though](https://github.com/vercel/next.js/issues/54757) + diff --git a/movie-search/src/common/components/FavoriteBtn.tsx b/movie-search/src/common/components/FavoriteBtn.tsx index 34002f0..79e5b7d 100644 --- a/movie-search/src/common/components/FavoriteBtn.tsx +++ b/movie-search/src/common/components/FavoriteBtn.tsx @@ -4,7 +4,10 @@ import { useContext } from "react"; import { FavoriteContext } from "./FavoriteContext"; export default function FavoriteBtn({ movie }: any) { - const { favorites, setFavorites } = useContext(FavoriteContext); + const { favorites, + dispatch + // setFavorites + } = useContext(FavoriteContext); const filteredFavorites = favorites.filter((f) => f.imdbID != movie.imdbID); const isFavorite = favorites.filter((f) => f.imdbID == movie.imdbID).length == 1; @@ -13,9 +16,11 @@ export default function FavoriteBtn({ movie }: any) {