Frontend School

Build a Simple Chat Message Display

Machine Coding
easy

Build a Simple Chat Message Display

Easy
React
Frontend
UI
Chat

Overview

At Airbnb, clear and efficient communication between guests and hosts is paramount. Our messaging system is a core component of the booking experience, ensuring all details are ironed out before, during, and after a stay. This problem focuses on building a fundamental piece of that system: displaying a list of chat messages.

Your task is to implement a basic chat message list UI, rendering a series of messages and visually distinguishing between messages sent by the current user and messages sent by another party. This exercise will test your ability to render dynamic lists, apply conditional styling, and manage basic UI layout in React.

What you need to do / Task

Your primary goal is to render the provided mock chat messages in a user-friendly list. Specifically, you must:

  1. Display all messages: Iterate through the MOCK_MESSAGES array and render each message.
  2. Show sender and content: For each message, clearly display the senderName and the content.
  3. Distinguish sender: Visually differentiate messages sent by the CURRENT_USER_ID from those sent by other participants. For example, messages from the current user could be right-aligned with a distinct background color, while others are left-aligned with a different background.
  4. Maintain chronological order: Messages should appear in the order they are provided in the MOCK_MESSAGES array (which is already chronological).

UI/UX expectations

  • Layout: Messages should stack vertically within a chat container.
  • Message Bubble: Each message should appear within its own 'bubble' or container.
  • Alignment: Messages from the current user should be aligned to one side (e.g., right), and messages from others to the opposite side (e.g., left).
  • Coloring: Use distinct background colors for messages from the current user versus messages from others to enhance visual separation.
  • Readability: Ensure sender names and message content are easily readable.

Acceptance criteria

  • The application successfully renders a list of messages from the MOCK_MESSAGES data.
  • Each message displays its senderName and content.
  • Messages from CURRENT_USER_ID are visually distinct (e.g., different background color, alignment) from messages sent by others.
  • Messages are ordered chronologically as provided in the mock data.
  • The UI is responsive and usable within the provided container.

Constraints

Constraints & assumptions

  • No backend integration: All data is provided via MOCK_MESSAGES in App.tsx. You do not need to fetch data.
  • Static data: The messages are static. You do not need to implement functionality for sending new messages, editing, or deleting existing ones.
  • Styling: Basic CSS styling is expected to achieve the UI/UX goals. You can modify styles.css.
  • React environment: You should use React for this implementation.

Out of scope

  • Real-time updates or websockets.
  • Infinite scrolling or pagination.
  • Complex message types (e.g., images, attachments).
  • User avatars or detailed timestamps.
  • Message input field or sending functionality.

What interviewers evaluate

  • Ability to render dynamic lists from data.
  • Effective use of conditional rendering and styling based on data properties.
  • Basic understanding of CSS for layout and visual distinction.
  • Clean code organization and component structure.

Loading editor...