import {Bot} from 'lucide-react'; import React, {useContext, useEffect, useState} from 'react'; import {SessionContext, SessionContextProps} from "@/context/SessionContext"; import {ConversationProps} from "@/lib/types/quillsense"; import {apiGet} from '@/lib/api/client'; import {BookContext, BookContextProps} from "@/context/BookContext"; import {LangContext, LangContextProps} from "@/context/LangContext"; import {AlertContext, AlertContextProps} from "@/context/AlertContext"; import {useTranslations} from '@/lib/i18n'; import Badge from "@/components/ui/Badge"; interface QuillListProps { handleSelectConversation: (itemId: string) => void; } export default function QuillList({handleSelectConversation}: QuillListProps): React.JSX.Element { const t = useTranslations(); const {session}: SessionContextProps = useContext(SessionContext); const {book}: BookContextProps = useContext(BookContext); const {lang}: LangContextProps = useContext(LangContext); const {errorMessage}: AlertContextProps = useContext(AlertContext); const [conversations, setConversations] = useState([]); useEffect((): void => { getConversations().then(); }, []); async function getConversations(): Promise { try { const response: ConversationProps[] = await apiGet( `quillsense/conversations`, session.accessToken, lang, { id: book?.bookId, } ); if (response.length > 0) { setConversations(response); } } catch (e: unknown) { if (e instanceof Error) { errorMessage(e.message); } else { errorMessage(t('quillList.error.unknown')); } } } function getStatusColorClass(status: number): string { switch (status) { case 1: return 'bg-muted'; case 2: return 'bg-accent-blue'; case 3: return 'bg-primary'; case 4: return 'bg-error'; default: return 'bg-muted'; } } return (
{conversations.map((conversation: ConversationProps): React.JSX.Element => (
handleSelectConversation(conversation.id)} >
{conversation.title || t('quillList.untitled')} {conversation.startDate && (

{conversation.startDate}

)}
{conversation.mode && ( {conversation.mode} )}
))}
); }