"use client"; import { Member, Message, Profile } from "@prisma/client"; import { ChatWelcome } from "./chat-welcome"; import { useChatQuery } from "@/hooks/use-chat-query"; import { Loader2, ServerCrash } from "lucide-react"; import { Fragment } from "react"; type MessageWithMemberWithProfile = Message & { member: Member & { profile: Profile } } interface ChatMessagesProps { name: string; member: Member; chatId: string; apiUrl: string; socketUrl: string; socketQuery: Record; paramKey: "channelId" | "conversationId"; paramValue: string; type: "channel" | "conversation"; } export const ChatMessages = ({ name, member, chatId, apiUrl, socketUrl, socketQuery, paramKey, paramValue, type, }: ChatMessagesProps) => { const queryKey = `chat:${chatId}`; const { data, fetchNextPage, hasNextPage, isFetchingNextPage, status, } = useChatQuery({ queryKey, apiUrl, paramKey, paramValue, }) if (status === "pending") { return (

Loading Messages...

) } if (status === "error") { return (

Something went wrong!

) } return (
{data?.pages.map((group, i) => ( {group.items.map((message: MessageWithMemberWithProfile) => (
{message.content}
))}
))}
) }