Frontend School

Interactive Chat UI with Message Grouping and Reactions

Machine Coding
hard

Interactive Chat UI with Message Grouping and Reactions

Hard
React
Frontend
UI
Chat
Machine Coding

Overview

Zomato's customer support relies on efficient and intuitive communication tools. We are developing a new internal chat interface for our support agents to interact with customers. This problem focuses on building a performant and interactive chat message list, which is crucial for agent productivity and a seamless support experience.

What you need to do / Task

Your task is to build a React component that displays a list of chat messages with the following features:

  1. Message Rendering: Display individual chat messages, showing sender name, message text, and associated reactions.
  2. Message Grouping: Implement logic to group consecutive messages from the same sender within a short timeframe (e.g., 5 minutes) into a single visual block. Only the first message in a group should display the sender's avatar/name.
  3. Interactive Reactions: Each message can have multiple reactions (emojis) from different users. Display these reactions below the message. Allow the current user (currentUserId) to toggle (add/remove) their own reactions on any message.
  4. Message Input & Sending: Provide a text input field and a 'Send' button to allow the currentUserId to send new messages. These messages should appear immediately in the chat list.

UI/UX expectations

  • Layout: The chat interface should be a fixed-height container with messages scrolling from bottom to top. A message input area should be present at the bottom.
  • Message Grouping Visuals: When messages are grouped, subsequent messages from the same sender should appear without repeating the sender's avatar/name, and ideally, be slightly indented or styled to indicate they are part of a group.
  • Reactions Display: Reactions should be displayed as small buttons or badges below each message. If multiple users react with the same emoji, display a count. The current user's active reactions should be visually distinct (e.g., highlighted).
  • Scroll Behavior: The chat window should automatically scroll to the bottom on initial load and whenever the currentUserId sends a new message. If the user has manually scrolled up, new messages (from any sender) should not force a scroll to the bottom until the user scrolls near the bottom again.

Acceptance criteria

  • Messages are rendered correctly, displaying sender name, text, and timestamp (optional for display, but for grouping logic).
  • Consecutive messages from the same sender within a 5-minute window are visually grouped as specified.
  • New messages sent via the input field are added to the chat list and displayed correctly.
  • Reactions are displayed below each message, showing counts for each emoji.
  • Clicking a reaction emoji toggles its presence for the currentUserId on that specific message.
  • The chat container scrolls to the bottom on initial load.
  • The chat container scrolls to the bottom when the currentUserId sends a message.
  • The chat container does not auto-scroll to the bottom if the user has manually scrolled up, unless the currentUserId sends a message. (This implies a check for user's scroll position).
  • Basic styling makes the chat interface usable and readable, distinguishing between sent/received messages.

Constraints

Constraints & assumptions

  • The currentUserId is fixed and provided (agent123).
  • Initial messages are provided as a static array. All new messages are simulated client-side; no backend integration is required.
  • Reaction data is simple: an array of emoji strings and user IDs for each message.
  • Performance: The solution should efficiently render and update a list of up to 100-200 messages without noticeable UI jank.
  • Styling: Focus on functional clarity and responsiveness rather than pixel-perfect design. Basic CSS is sufficient.

Out of scope

  • Real-time WebSocket or API integration.
  • User authentication or authorization.
  • Full accessibility beyond basic click interactions.
  • Support for complex message types (e.g., images, videos, attachments).
  • Pagination or infinite scrolling for historical messages (assume all messages are loaded initially).

What interviewers evaluate

  • Architectural Design: Effective state management, component composition, and data flow in React.
  • Code Quality & Readability: Clean, maintainable, and well-structured code with appropriate use of hooks and types.
  • UI/UX Implementation: Correct and intuitive rendering of grouped messages, interactive reactions, and robust scroll behavior.
  • Problem Solving: Ability to break down complex UI requirements, handle dynamic updates, and consider edge cases for a polished user experience.

Loading editor...