Frontend School

Simple Chat Message Display

Machine Coding
easy

Simple Chat Message Display

Easy
UI
React
Frontend
Chat

Overview

In the PhonePe app, seamless communication is key. This problem focuses on building a fundamental component of any messaging feature: displaying chat messages. You will implement a basic chat window that renders a list of messages, distinguishing between those sent by the current user and others, mirroring a common chat UI pattern.

What you need to do / Task

Your task is to build a React functional component named ChatWindow that displays a list of chat messages.

  1. Render Messages: Display each message from the provided messages array.
  2. Display Details: For each message, show the sender's name and the message content.
  3. Differentiate Senders: Visually distinguish messages sent by the currentUserId from messages sent by other users.
  4. Order: Messages should appear in the order they are provided in the messages array (which is chronological).

UI/UX expectations

  • Message Alignment:
    • Messages sent by the currentUserId should be aligned to the right side of the chat window.
    • Messages sent by other users should be aligned to the left side of the chat window.
  • Visual Distinction: Use different background colors or styles to clearly indicate who sent the message. For example, current user messages could have a green background, and others a grey background.
  • Readability: Ensure sender names and message content are clearly readable within their respective message bubbles.
  • Simple Layout: The overall chat window should be clean and easy to follow.

Acceptance criteria

  • [ ] All messages from the mockMessages array are rendered in the ChatWindow component.
  • [ ] Each rendered message clearly displays the sender's name and the content.
  • [ ] Messages sent by the currentUserId are visually distinct and aligned to the right.
  • [ ] Messages sent by other users are visually distinct and aligned to the left.
  • [ ] The component should be scrollable if the message list exceeds the viewport height, allowing all messages to be viewed.

Constraints

Constraints & assumptions

  • You must use React for building the UI.
  • The messages data will be an array of objects, each containing id, senderId, senderName, and content.
  • A currentUserId will be provided to identify the active user.
  • The messages array is already sorted chronologically.
  • No real-time message fetching or input functionality is required. Focus solely on rendering existing messages.
  • You may use basic CSS for styling. No CSS-in-JS libraries or complex styling frameworks are allowed.

Out of scope

  • Implementing a message input field or send button.
  • Handling real-time updates or web sockets for new messages.
  • Implementing advanced chat features like read receipts, attachments, or message editing.
  • Complex state management beyond what's necessary for this display component.

What interviewers evaluate

  • Component Structure: How effectively you break down the UI into reusable and manageable React components.
  • Conditional Rendering: Your ability to apply conditional logic to render different UI elements based on data (e.g., sender ID).
  • Styling & Layout: Proficiency in using CSS to achieve the specified UI/UX requirements, including alignment and visual distinction.
  • Code Quality: Readability, maintainability, and adherence to best practices for React development.

Loading editor...