Frontend School

Performant Infinite Scroll Image Gallery with Filtering

Machine Coding
hard

Performant Infinite Scroll Image Gallery with Filtering

Hard
React
Frontend
UI
Image Gallery
Infinite Scroll
Lazy Loading
Filtering

Overview

Delhivery's internal asset management system needs a highly performant and user-friendly way to browse a vast collection of product and delivery proof images. The existing gallery is slow, especially with thousands of images, and lacks essential features for efficient navigation. Your task is to develop a modern ImageGallery component that addresses these performance bottlenecks and enhances user experience through infinite scrolling, lazy loading, and category-based filtering.

What you need to do / Task

  1. Develop an ImageGallery React Component: Create a functional React component that displays a grid of images.
  2. Implement Infinite Scrolling: As the user scrolls towards the bottom of the gallery, new images should automatically load and append to the existing list. This should be a smooth and continuous experience.
  3. Implement Lazy Loading for Images: Images should only be fetched and rendered when they are about to enter or are within the user's viewport, optimizing initial load times and resource usage.
  4. Add Category Filtering: Provide a mechanism (e.g., a dropdown or buttons) to filter images by their assigned categories. When a filter is applied, the gallery should display only images from the selected category, resetting the pagination and scroll position.
  5. Display Image Details on Hover: When a user hovers over an image card, an overlay should appear, displaying the full title and category of the image.

UI/UX expectations

  • Layout: Images should be displayed in a responsive grid layout, adapting to different screen sizes.
  • Filtering: A clear filter control (e.g., a <select> dropdown) should be positioned at the top of the gallery, allowing users to easily choose a category or view all images.
  • Image Cards: Each image should be presented in a card-like structure, showing a thumbnail and a truncated title below it.
  • Hover Interaction: On hover, a semi-transparent overlay should smoothly appear over the image, revealing its full title and category in a readable format.
  • Loading Feedback: A clear loading indicator (e.g., a spinner or text) must be visible at the bottom of the gallery when more images are being fetched via infinite scroll or after a filter change.
  • Error Handling: If an image fails to load, a fallback placeholder (e.g., a grey box with 'Error loading image') should be displayed instead of a broken image icon.

Acceptance criteria

  • The gallery initially loads and displays the first batch of images.
  • Scrolling down triggers the loading of subsequent batches of images, which are appended to the current display.
  • Images outside the current viewport are not loaded/rendered until they are scrolled into view (lazy loading).
  • Selecting a category from the filter updates the displayed images to show only those matching the selected category, and the scroll position is reset to the top.
  • Hovering over any image card reveals its complete title and category in an overlay.
  • A loading indicator is visibly present while new images are being fetched (both for infinite scroll and filter changes).
  • Images that fail to load display a graceful fallback placeholder.
  • The gallery handles scenarios where no images are found for a selected filter or in the entire dataset.

Constraints

Constraints & assumptions

  • You must use React functional components and hooks.
  • Mock data for images and categories will be provided in /App.tsx. Assume this data simulates an API endpoint that returns paginated results.
  • The "API" simulation should return a fixed number of images per "page" (e.g., 20 images).
  • Assume a total dataset size of up to 200-500 images for testing purposes.
  • No external state management libraries (e.g., Redux, Zustand) are required. Manage state using React's built-in hooks.
  • Focus on functionality and performance; extensive styling or pixel-perfect UI is not the primary concern, but a clean, readable layout is expected.
  • Ensure efficient rendering, especially when dealing with a potentially large number of images.

Out of scope

  • Full-text search functionality.
  • Image upload, editing, or deletion features.
  • Deep backend integration beyond the provided mock data simulation.
  • Advanced accessibility features (e.g., comprehensive keyboard navigation for all elements).
  • Complex animations beyond basic hover effects.

What interviewers evaluate

  • Correctness and Efficiency: Accurate implementation of infinite scroll, lazy loading, and filtering, demonstrating an understanding of performance considerations for large lists.
  • State Management: Effective and clean management of component state (e.g., images, pagination, filters, loading status).
  • React Best Practices: Usage of appropriate React hooks (useState, useEffect, useRef, useCallback) and component composition.
  • User Experience: Thoughtful handling of loading states, error conditions, and responsive UI elements.
  • Code Quality: Readability, modularity, and maintainability of the codebase.

Loading editor...