You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
tailchat/web/src/components/ChatBox/index.tsx

55 lines
1.7 KiB
TypeScript

import { Skeleton } from 'antd';
import React from 'react';
import { useConverseMessage } from 'pawchat-shared';
import { AlertErrorView } from '../AlertErrorView';
import { ChatInputBox } from './ChatInputBox';
const ChatBoxPlaceholder: React.FC = React.memo(() => {
return (
<div className="px-2 w-2/3">
<Skeleton className="mb-2" avatar={true} paragraph={{ rows: 1 }} />
<Skeleton className="mb-2" avatar={true} paragraph={{ rows: 1 }} />
<Skeleton className="mb-2" avatar={true} paragraph={{ rows: 1 }} />
<Skeleton className="mb-2" avatar={true} paragraph={{ rows: 1 }} />
<Skeleton className="mb-2" avatar={true} paragraph={{ rows: 1 }} />
<Skeleton className="mb-2" avatar={true} paragraph={{ rows: 1 }} />
<Skeleton className="mb-2" avatar={true} paragraph={{ rows: 1 }} />
<Skeleton className="mb-2" avatar={true} paragraph={{ rows: 1 }} />
<Skeleton className="mb-2" avatar={true} paragraph={{ rows: 1 }} />
<Skeleton className="mb-2" avatar={true} paragraph={{ rows: 1 }} />
</div>
);
});
ChatBoxPlaceholder.displayName = 'ChatBoxPlaceholder';
export const ChatBox: React.FC<{
converseId: string;
}> = React.memo((props) => {
const { messages, loading, error, handleSendMessage } = useConverseMessage(
props.converseId
);
if (loading) {
return <ChatBoxPlaceholder />;
}
if (error) {
return <AlertErrorView error={error} />;
}
return (
<div>
<div>: {JSON.stringify(messages)}</div>
<ChatInputBox
onSendMsg={(msg) =>
handleSendMessage({
converseId: props.converseId,
content: msg,
})
}
/>
</div>
);
});
ChatBox.displayName = 'ChatBox';