Frontend School

Build a Dynamic Notification Center

Machine Coding
hard

Build a Dynamic Notification Center

Hard
React
TypeScript
Frontend
State Management
UI/UX

Overview

Many modern applications rely on a centralized notification system to keep users informed about important updates, activities, and system alerts. This problem challenges you to build a functional Notification Center component, demonstrating your ability to manage complex UI state, handle user interactions, and render dynamic data efficiently. You will implement features crucial for a seamless user experience, such as filtering, read/unread status management, and dynamic loading of notifications.

What you need to do / Task

Your goal is to implement a NotificationCenter React component that displays a list of notifications and provides interaction capabilities.

  1. Display Notifications: Render a list of notifications. Each notification item should display its type (e.g., info, warning), a descriptive message, a relative timestamp (e.g., "5 minutes ago"), and its current read/unread status.
  2. Toggle Read Status:
    • Allow users to individually mark a notification as read or unread.
    • Implement a "Mark all as read" button that changes the status of all currently displayed unread notifications to read.
  3. Dismiss Notifications:
    • Allow users to dismiss (remove) individual notifications from the list.
    • Implement a "Clear all read" button that removes all notifications currently marked as read from the list.
  4. Filter Notifications: Provide controls to filter the displayed notifications:
    • "All": Shows all notifications.
    • "Unread": Shows only unread notifications.
  5. Load More Notifications: Implement a "Load More" button at the bottom of the notification list. Clicking this button should append additional mock notifications to the existing list.
  6. Notification Counts: Display the total number of notifications and the count of unread notifications prominently within the header of the notification center.

UI/UX expectations

  • Toggle: The notification center should be toggled open/closed by clicking a "Bell" icon (or similar) button. When closed, only the bell icon and potentially an unread count badge should be visible.
  • Layout: When open, the notification center should appear as a distinct panel. It should have a header displaying counts and actions (e.g., "Mark all as read", filter controls), followed by the scrollable list of notifications, and finally the "Load More" button.
  • Notification Item: Each notification should be visually distinct based on its type (e.g., different background color or icon for warning vs. info). Read notifications should be visually distinguishable from unread ones (e.g., subtle background change, lighter text).
  • Interactions: All buttons and interactive elements should be clearly clickable. Dismissal should be smooth.

Acceptance criteria

  • Clicking the bell icon toggles the visibility of the notification center.
  • The notification center header displays accurate total and unread notification counts.
  • Each notification displays its message, type, relative time, and read status.
  • Clicking a notification item (or a dedicated button on it) toggles its read/unread status.
  • Clicking "Mark all as read" updates all unread notifications to read.
  • Clicking the dismiss button on an individual notification removes it from the list.
  • Clicking "Clear all read" removes all read notifications from the list.
  • Selecting "Unread" filter correctly displays only unread notifications.
  • Selecting "All" filter correctly displays all notifications.
  • Clicking "Load More" appends new notifications to the list.
  • The UI remains responsive and functional during all interactions.

Constraints

Constraints & assumptions

  • You are building a client-side React component. No backend integration is required; all data will be client-side mock data.
  • Notifications should be displayed in reverse chronological order (newest first).
  • The initial set of notifications will be provided as mock data. An additional set of mock data should be used for the "Load More" functionality.
  • You may use basic CSS for styling. No advanced styling libraries (e.g., Tailwind, Styled Components) are required unless explicitly chosen by you and justified. Focus on functionality.
  • Performance for a small number of notifications (up to ~50-100) is expected to be reasonable. No advanced virtualization is needed.

Out of scope

  • Real-time push notifications (e.g., WebSockets).
  • Persistent storage of notifications (e.g., localStorage, IndexedDB).
  • Accessibility beyond basic semantic HTML elements.
  • Complex animations or transitions.

What interviewers evaluate

  • Correctness and Completeness: Does the solution meet all functional requirements and acceptance criteria?
  • Code Structure and Readability: Is the code well-organized, easy to understand, and maintainable? Are appropriate React patterns and hooks used?
  • State Management: Is application state managed effectively and efficiently, avoiding unnecessary re-renders?
  • Event Handling: Are user interactions handled robustly and correctly?
  • UI/UX Implementation: Does the UI provide a clear and intuitive user experience as specified?

Loading editor...