This project is an SPA that implements a photo gallery built with React and TypeScript, featuring a responsive, optimized, and virtualized masonry grid, detailed photo view, and a search functionality.
- Node.js (v14 or later recommended)
- npm (comes with Node.js)
-
Clone the repository:
git clone git@github.com:gs25087/Virtualized-Masonry-Grid.git
-
Navigate to the project directory:
cd Virtualized-Masonry-Grid
-
Install dependencies:
npm install
To start the development server, run:
npm start
Open http://localhost:5174/ to view it in the browser.
To create a production build, run:
npm run build
This builds the app for production to the build
folder.
-
Component Structure: The application is divided into reusable components (App, AppContent, MasonryGrid, PhotoDetails, Form) to promote modularity and maintainability.
-
Custom Hooks: I've implemented several custom hooks (usePhotoFetching, useContainerSize, useColumnCalculations, etc.) to encapsulate and reuse complex logic.
-
Masonry Grid Layout: A custom masonry grid layout was implemented for an aesthetically pleasing photo display that efficiently uses space.
-
Infinite Scrolling: Instead of pagination, I use infinite scrolling to provide a seamless browsing experience.
-
Responsive Design: The application adjusts the number of columns based on the container width, ensuring a good user experience across different device sizes.
-
Search Functionality: A search feature allows users to find specific photos based on keywords.
-
React Router: Used for navigation between the photo grid and individual photo views, enabling a smooth single-page application experience.
-
Virtual Scrolling: Only photos that are currently visible (plus a small overscan area) are rendered, significantly reducing the number of DOM elements.
-
Memoization: React's
useMemo
hook is used to memoize expensive calculations, preventing unnecessary re-computations. -
Debouncing: Implemented for the resize event listener to prevent excessive calculations during window resizing.
-
Lazy Loading: Images are lazy-loaded as they come into view, reducing initial load time and bandwidth usage.
-
Optimized Re-renders: Careful management of component props and state minimizes unnecessary re-renders.
-
Scroll Position Preservation: The scroll position is preserved when navigating between the grid and individual photos, enhancing the user experience.
-
Image Loading Placeholder: A placeholder is displayed while images are being fetched, providing visual feedback to the user.
-
Image Optimization: Images are fetched in the optimal size based on the container width, reducing load times and bandwidth usage.
-
Error Handling: Errors are gracefully handled, providing feedback to the user in case of network issues or API failures.
- React and TypeScript for building a robust and type-safe application
- React Router for handling navigation
- Custom hooks for logic encapsulation and reuse
- Unsplash API for fetching high-quality photos
- Implement caching to reduce API calls and improve load times for previously viewed photos.
- Add unit and integration tests to ensure reliability and ease of maintenance.
- Implement live search functionality to provide real-time results as the user types.
Contributions are welcome! Please feel free to submit a Pull Request.
This project is licensed under the MIT License.