Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[CBulnes-FE-Task] - Search movie app #669

Open
wants to merge 24 commits into
base: master
Choose a base branch
from

Conversation

CristinaBulnes
Copy link

@CristinaBulnes CristinaBulnes commented Dec 19, 2024

This PR implements a Movie Search Application as part of the Frontend Engineering Challenge. Below is a breakdown of the key features, approaches, and technologies used in the solution:

Features

  • Search Functionality: Search movies by typing in a debounced input field.
  • Paginated Results: Display results with a "Load More" option for additional pages.
  • Movie Details: View detailed information about a selected movie via a modal overlay.
  • State Management:
    • Implemented global state management using Context API and Redux to demonstrate knowledge of both approaches.
    • Provided a modular structure to allow scalability and easy transition between state management solutions.

Technologies

  • React for UI development.
  • TypeScript for type safety.
  • Styled-Components for component-level styling.
  • Vite as a fast development and build tool.
  • React Router for navigation.
  • Axios for API requests.
  • Debounce Logic to optimize API calls during search.

Highlights of the Solution

  1. Custom Hooks: Created useMovieSearch and useMovieSearchRedux to encapsulate logic for context-based and Redux-based state management.
  2. Scalability: Modular structure designed for extensibility, allowing for additional features in the future.
  3. Code Organization: A clean and well-documented project structure to enhance readability and maintainability.
  4. Optimized User Experience:
    • Implemented a modal for movie details to preserve search results state and avoid unnecessary re-fetching.
    • Maintained performance by reducing redundant network calls.

Project Structure
Included in the README to explain the organization of files and directories for better understanding of the codebase.

How to Review

  1. Clone the repository.
  2. Follow the setup instructions in the README to run the application.
  3. Review the implementation of both Context API and Redux approaches through the provided hooks and state management logic.

    - Created directories.
    - Added placeholder files for future development.
    - Updated `README.md` file adding development plan.
    - Installed dependencies: `react-router-dom`.
    - Implemented routing with `SearchMoviesView` and `MovieDetailsView`.
    - Configured routes in `App.tsx`.
    - Added `jest` and `react-testing-library` for testing.
    - Set up basic testing utilities.
    - Installed dependecies: `styled-components`.
    - Added global theme using `theme.ts`
- Created BaseMovieCard component to display movie details in a card format, reusable for MoviesGrid and MovieDetailsView.
- Added Poster component for image rendering with fallback and lazy loading support.
- Implemented tests for Poster component, ensuring proper image rendering, fallback behavior, and lazy loading functionality.
- Added tests for BaseMovieCard component to verify correct rendering of movie details and interaction with Poster.
…ity functions, and testing updates

    - created `MovieCard` component based on `BaseMovieCard` with added onClick functionality to be used in the `MoviesGrid`.
    - created `MoviesGrid` component to display a list of movie cards.
    - created unit tests for MovieCard and MoviesGrid components to ensure correct rendering and behavior.
    - added data-testid to BaseMovieCard for easier testing.
    - installed utility package for testing purposes and updated test configuration to use it.
    - Created a `test-utils.tsx` file inside the `utils` folder to wrap components in the `ThemeProvider` for consistent test setup.
    - Simplified test files by importing the custom render method to apply the theme.
    - Improved test consistency by avoiding repetitive ThemeProvider wrapping in each test file.
    - Created generic `Input` component to use in the SearchMovie.
    - Created generic  `Button` component.
    - Wrote unit tests for input and button.
    - Refactor BaseCard to use the compound component pattern for flexibility
        - Allows displaying content in row or column layouts
        - Update BaseCard tests to cover new behavior
    - Update MovieCard to align with new BaseCard changes
        - Improve test coverage for MovieCard in the search view
    - Add MovieDetailsCard component for the movie details view
        - Ensure tests validate all displayed movie details and interactions
    - Create reusable Typography component for consistent text styling
    - Installed axios to handle API requests.
    - Created `apiClient.ts` to configure and export an Axios instance with default settings.
    - Added tests for `apiClient` to ensure proper request handling and response interceptors.
    - Implemented `movieService.ts` with functions to fetch movies and movie details, utilizing `apiClient`.
    - Created tests for `movieService.ts` to mock API responses and ensure proper error handling.
    - Configured environment variable handling for `process.env` to allow API keys and base URL configuration.
    - Updated `SearchMoviesView` to fetch movies dynamically based on the search query.
    - Updated `MovieDetailsView` to fetch and display movie details using API.
    - Integrated response mapping helpers (`mapFetchMoviesResponse` and `mapFetchMovieDetailsResponse`) for clean transformation of API data.
    - Implemented `getPosterPath` to generate full poster URLs or return a placeholder image if unavailable.
    - Created `arrayToString` to convert arrays or object data (e.g., genres) into a formatted string.
    - Updated relevant components to utilize these utilities, reducing duplication and improving readability.
    - Added unit tests for `getPosterPath` and `arrayToString` to ensure correctness and edge case handling.
    - Refactored existing tests to align with updated components and the new utilities.
    - Added pagination support to fetch additional movie results.
    - Implemented a "Load More" button to load subsequent pages of results.
    - Updated useEffect to debounce input changes and reset pagination on new search.
    - Added a separate effect to handle fetching movies on pagination state change.
    - Extracted movie search logic into a custom hook (`useMovieSearch`) for better code organization and reusability.
    - Refactored `SearchMoviesView` to use the `useMovieSearch` hook, improving readability and maintainability.
    - Added tests for the `useMovieSearch` hook.
    - Created a custom hook `useMovieDetails` for fetching and managing movie details state (loading, error, movie data).
    - Refactored `MovieDetailsView` to use `useMovieDetails` for state management and API calls.
    - Added unit tests for `useMovieDetails` to check for loading, error handling, and success cases.
…croll, and update useMovieSearch.

    - Moved debounce logic into a standalone custom hook (useDebounce).
    - Created a hook to handle infinite scroll using IntersectionObserver.
    - Updated `useMovieSearch` and its test.
    - Created tests for `useDebounce` and `useIntersectionObserver`.
    - Addressed the issue where navigating back from the movie details view caused the search view to re-render.
…tching data, and connect with SearchMoviesView component

    - Set up Redux store and moviesSlice for managing movies, loading states, and pagination.
    - Create `fetchMoviesAsync` thunk for handling movie search API calls.
    - Replace context API with Redux state management for movies, query, loading, error, and pagination.
    - Add `movieSearchSlice`and `movieSearchThunk` tests.
    - Implemented a loading spinner for better UX during data fetching.
    - Added an ErrorBoundary to catch and handle errors in the app.
    - Created an Error component to display user-friendly error messages.
    - Extracted movie search logic from SearchMoviesView into a new custom hook `useMovieSearchRedux`.
    - Simplified the component by delegating state management and data fetching to the custom hook.
    - Improved code readability and reusability by encapsulating logic.
    - Added project structure section to explain the organization of directories and files.
    - Provided descriptions for key directories such as `components`, `contexts`, `hooks`, `redux`, `services`, and `pages`.
    - Highlighted the modular and scalable approach to organizing the application.
    - Improved readability and navigation for reviewers by including relevant explanations for state management and key decisions.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant