Overview
In Salesforce Service Cloud, agents often handle high volumes of customer interactions through chat. A key aspect of an efficient agent experience is the ability to quickly parse and understand chat history. This problem focuses on optimizing the display of chat messages by intelligently grouping consecutive messages from the same sender within a short time frame, mimicking a natural conversation flow and improving readability, especially during rapid exchanges.
What you need to do / Task
Your task is to build a React component that displays a stream of chat messages with specific grouping and loading behaviors.
- Initial Message Display: Render an initial set of chat messages (e.g., 20-30 messages) from the provided mock data. Messages should be displayed in chronological order (oldest at the top, newest at the bottom).
- Sender-Based Grouping: Implement logic to group consecutive messages from the same sender if they were sent within a defined time window (e.g., 5 minutes).
- A group should appear as a single "bubble" or block in the UI.
- The sender's avatar and name should be displayed once at the top of the group.
- All messages within that group should be rendered inside this single visual container.
- The timestamp displayed for the group should be the timestamp of the first message in that group.
- "Load More" Functionality: Implement an "Load More" button at the top of the chat stream.
- Clicking this button should prepend an additional chunk of older messages (e.g., 10-15 messages) to the existing list.
- The newly loaded messages should also be subject to the grouping logic.
- The UI should maintain scroll position as much as possible, preventing the user from losing their place when new content is added at the top.
- A loading indicator should be shown while new messages are being fetched.
UI/UX expectations
- Chat Container: A scrollable container for all messages.
- Message Group: Each group should visually stand out. The sender's avatar (e.g., a placeholder circle) and name should be clearly visible once per group. The messages within the group can be simple text lines.
- Timestamp: A clear timestamp (e.g., "HH:MM AM/PM" or "MM/DD HH:MM AM/PM") should be displayed for each grouped message block.
- "Load More" Button: A button at the top of the chat area, clearly labeled "Load More". It should be disabled or replaced by a loading spinner when new messages are being loaded.
- Responsiveness: The chat component should adapt reasonably to different widths (e.g., fill available width). Minimal styling is expected, focus on functional layout.
Acceptance criteria
- Initial set of messages renders correctly according to chronological order.
- Consecutive messages from the same sender within the 5-minute window are correctly grouped into a single visual block.
- Sender's avatar and name are displayed only once per grouped block.
- The timestamp for each grouped block corresponds to its first message.
- Clicking "Load More" prepends additional messages to the top of the chat stream.
- The "Load More" button displays a loading state during message fetching.
- The scroll position is generally maintained when new messages are loaded at the top.
- The overall UI layout is clean and functional.