From d5dd3a9f097a46b4847a49c04a8a1abb2d8a7197 Mon Sep 17 00:00:00 2001 From: Evandro Fonseca Junior Date: Tue, 28 Oct 2025 14:40:34 -0300 Subject: [PATCH] feat(chat): add conversation selection and enhance message rendering - Add currentConversationId prop to ChatContainer for loading selected conversations - Implement logic to load messages when conversation is selected and clear when deselected - Improve user message rendering with proper whitespace handling - Enhance MarkdownRenderer with content normalization and adjusted spacing for better readability - Add paragraph styling to markdown output for improved layout This enables users to switch between conversations seamlessly and provides cleaner message display. --- components/ClientHome.tsx | 1 + components/chat/ChatContainer.tsx | 13 ++++++++ components/chat/ChatMessage.tsx | 4 +-- components/message/MarkdownRenderer.tsx | 42 +++++++++++++++++++----- database/ollahub-preferences.db-shm | Bin 32768 -> 32768 bytes database/ollahub-preferences.db-wal | Bin 144232 -> 177192 bytes database/ollahub.db-shm | Bin 32768 -> 32768 bytes database/ollahub.db-wal | Bin 420272 -> 700432 bytes lib/ollama.ts | 4 ++- scripts/init-db.ts | 2 +- test-markdown.tsx | 1 + 11 files changed, 54 insertions(+), 13 deletions(-) create mode 100644 test-markdown.tsx diff --git a/components/ClientHome.tsx b/components/ClientHome.tsx index c16c185..0e6b80c 100644 --- a/components/ClientHome.tsx +++ b/components/ClientHome.tsx @@ -62,6 +62,7 @@ export function ClientHome({ offline, models }: ClientHomeProps) { models={models} offline={offline} onConversationCreated={handleConversationCreated} + currentConversationId={currentConversationId} /> diff --git a/components/chat/ChatContainer.tsx b/components/chat/ChatContainer.tsx index 7c00e2a..ce6a595 100644 --- a/components/chat/ChatContainer.tsx +++ b/components/chat/ChatContainer.tsx @@ -15,12 +15,14 @@ interface ChatContainerProps { models: ModelInfo[]; offline: boolean; onConversationCreated?: () => void; + currentConversationId?: string | null; } export function ChatContainer({ models, offline, onConversationCreated, + currentConversationId: propCurrentConversationId, }: ChatContainerProps) { const { prefs, ready, update } = useUserPrefs(); const [messages, setMessages] = useState([]); @@ -42,6 +44,17 @@ export function ChatContainer({ } }, [ready, prefs.selectedModel]); + // Carregar mensagens quando uma conversa é selecionada + useEffect(() => { + if (propCurrentConversationId) { + loadConversation(propCurrentConversationId); + } else { + // Limpar mensagens quando nenhuma conversa está selecionada + setMessages([]); + setConversationId(null); + } + }, [propCurrentConversationId]); + // Salvar modelo quando selecionado const handleModelChange = (modelName: string) => { setSelectedModel(modelName); diff --git a/components/chat/ChatMessage.tsx b/components/chat/ChatMessage.tsx index 0027a95..61c92d1 100644 --- a/components/chat/ChatMessage.tsx +++ b/components/chat/ChatMessage.tsx @@ -34,9 +34,9 @@ export function ChatMessage({ : "bg-[var(--surface)] text-[var(--foreground)]" }`} > -
+
{isUser ? ( - message.content +
{message.content}
) : ( )} diff --git a/components/message/MarkdownRenderer.tsx b/components/message/MarkdownRenderer.tsx index 5ba4494..f94f193 100644 --- a/components/message/MarkdownRenderer.tsx +++ b/components/message/MarkdownRenderer.tsx @@ -12,6 +12,12 @@ type MarkdownRendererProps = { }; export function MarkdownRenderer({ content }: MarkdownRendererProps) { + // Normalizar quebras de linha e espaços + const normalizedContent = content + .replace(/\n{3,}/g, "\n\n") // Máximo 2 quebras consecutivas + .replace(/[ \t]+$/gm, "") // Remover espaços no final das linhas + .trim(); + return ( +