/** * @file components/chat/ChatMessages.tsx * @description Message history container component displaying initial channel greeting, date separators, and a list of individual chat messages. */ "use client"; import { ChatItem, type MessageWithMember } from "./ChatItem"; /** * Properties for the ChatMessages component. * * @interface ChatMessagesProps * @property {string} channelName - The name of the active chat channel to display in the header greeting. * @property {MessageWithMember[]} messages - Array of message objects, each containing message details and associated member information. * @property {string} [currentUserId] - The unique identifier of the currently logged-in user. */ interface ChatMessagesProps { channelName: string; messages: MessageWithMember[]; currentUserId?: string; } /** * Formats a given date string or object into a human-readable label ("Today", "Yesterday", or a localized date string). * * @function formatDateLabel * @param {string | Date} dateString - The date value to format. * @returns {string} The formatted date label. */ function formatDateLabel(dateString: string | Date): string { const date = new Date(dateString); const now = new Date(); const isToday = date.getDate() === now.getDate() && date.getMonth() === now.getMonth() && date.getFullYear() === now.getFullYear(); const yesterday = new Date(now); yesterday.setDate(now.getDate() - 1); const isYesterday = date.getDate() === yesterday.getDate() && date.getMonth() === yesterday.getMonth() && date.getFullYear() === yesterday.getFullYear(); if (isToday) return "Today"; if (isYesterday) return "Yesterday"; return date.toLocaleDateString("de-DE", { day: "numeric", month: "long", year: "numeric", }); } /** * Renders the scrollable message list along with a welcoming channel header and dynamic date separators. * * @param {ChatMessagesProps} props - The component props. * @param {string} props.channelName - The name of the active chat channel to display in the header greeting. * @param {MessageWithMember[]} props.messages - Array of message objects, each containing message details and associated member information. * @param {string} [props.currentUserId] - The unique identifier of the currently logged-in user. * @returns {JSX.Element} The rendered chat messages container. */ export function ChatMessages({ channelName, messages, currentUserId, }: ChatMessagesProps) { return (
This is the beginning of the channel #{channelName}.