diff --git a/application/frontend/src/pages/chatbot/chatbot.scss b/application/frontend/src/pages/chatbot/chatbot.scss index efd733b3a..24934b06d 100644 --- a/application/frontend/src/pages/chatbot/chatbot.scss +++ b/application/frontend/src/pages/chatbot/chatbot.scss @@ -5,7 +5,7 @@ .chat-container { margin: 3rem auto; margin-top: 1.5rem; - max-width: 960px; + max-width: 700px; display: flex; flex-direction: column; position: relative; @@ -13,6 +13,8 @@ .chat-container.chat-active { height: calc(100vh - 179px); + max-width: 900px; + border-radius:18px; overflow: hidden; } @@ -178,7 +180,7 @@ h1.ui.header.chatbot-title { } .message-body { - font-size: 0.95rem; + font-size: 0.98rem; text-align: left; /* NEW: prevent horizontal overflow */ @@ -259,28 +261,119 @@ h1.ui.header.chatbot-title { color: #b71c1c; } -/* ========================= - Chat input - ========================= */ +/* =========== + Chat input + ===========*/ .chat-input { position: sticky; bottom: 0; z-index: 5; - margin-top: 1rem; - background-color: #daebdb; -/* background: transparent; */ - border: 1px solid rgb(190, 214, 232); - padding: 0.75rem; - border-radius: 12px; - box-shadow: 0 2px 6px rgba(0, 0, 0, 0.05); + + display: flex; + align-items: center; + gap: 0.5rem; + + background: #ffffff; + border: 1px solid rgba(0, 0, 0, 0.08); + border-radius: 14px; + padding: 0.55rem 0.55rem 0.55rem 1rem; + box-shadow: none; + transition: border-color 0.2s ease, box-shadow 0.2s ease; + + &:focus-within { + border-color: rgba(0, 0, 0, 0.15); + } +} + +.chat-container.chat-active .chat-input { + box-shadow: + 0 2px 4px rgba(0, 0, 0, 0.02), + 0 8px 24px rgba(0, 0, 0, 0.06); + + &:focus-within { + border-color: rgba(0, 0, 0, 0.16); + box-shadow: + 0 2px 6px rgba(0, 0, 0, 0.03), + 0 12px 28px rgba(0, 0, 0, 0.08); + } +} + +.chat-textarea { + flex: 1; + background: transparent; + border: none; + outline: none; + resize: none; + font-family: inherit; + font-size: 1.05rem; + line-height: 1.55; + color: #111; + min-height: 28px; + max-height: 200px; + overflow-y: auto; + scrollbar-width: thin; + padding: 2px 0; + + &:focus-visible { + outline: 2px solid #2185d0; + outline-offset: 2px; + border-radius: 4px; + } + + &::placeholder { + color: #6b7280; + transition: color 0.2s ease; + } + + &:focus::placeholder { + color: #4b5563; + } } -.chat-input .ui.input input { - height: 40px; - line-height: 40px; - border-radius: 10px !important; +.chat-send-btn { + flex-shrink: 0; + width: 32px; + height: 32px; + border-radius: 10px; + border: none; + cursor: pointer; + background: #2185d0; + color: #fff; + display: flex; + align-items: center; + justify-content: center; + transition: background 0.18s ease, transform 0.12s ease; + + svg { + width: 15px; + height: 15px; + } + + &:hover:not(:disabled) { + background: #1a6fad; + transform: translateY(-1px); + } + + &:focus { + outline: none; + } + + &:focus-visible:not(:disabled) { + outline: 2px solid #2185d0; + outline-offset: 2px; + } + + &:active:not(:disabled) { + transform: translateY(0); + } + + &:disabled { + background: #2185d0; + color: #fff; + cursor: not-allowed; + } } /* ========================= @@ -354,7 +447,7 @@ h1.ui.header.chatbot-title { .scroll-to-bottom { position: absolute; - bottom: 160px; + bottom: calc(var(--composer-height, 52px) + 1.75rem); left: 50%; transform: translateX(-50%); z-index: 10; @@ -390,23 +483,20 @@ h1.ui.header.chatbot-title { @media (max-width: 768px) { .scroll-to-bottom { - bottom: 160px; + bottom: calc(var(--composer-height, 52px) + 1.75rem); } } .chat-surface { + position: relative; display: flex; flex-direction: column; height: 100%; - - background: #fcfcfa; /* same palette as input */ + background: #fcfcfa; /* same palette as input */ backdrop-filter: blur(6px); - border-radius: 18px; border: 1px solid rgba(0, 0, 0, 0.05); - - box-shadow: 0 12px 40px rgba(0, 0, 0, 0.08), inset 0 1px 0 rgba(255, 255, 255, 0.4); - + box-shadow: 0 8px 20px rgba(0, 0, 0, 0.08), inset 0 1px 0 rgba(255, 255, 255, 0.4); padding: 1.25rem; } @@ -470,4 +560,4 @@ h1.ui.header.chatbot-title { opacity: 0.85; transform: translateX(-50%) translateY(0); } -} \ No newline at end of file +} diff --git a/application/frontend/src/pages/chatbot/chatbot.tsx b/application/frontend/src/pages/chatbot/chatbot.tsx index 79a175632..2b6f6f8f7 100644 --- a/application/frontend/src/pages/chatbot/chatbot.tsx +++ b/application/frontend/src/pages/chatbot/chatbot.tsx @@ -5,15 +5,15 @@ import { marked } from 'marked'; import React, { useEffect, useRef, useState } from 'react'; import { Prism as SyntaxHighlighter } from 'react-syntax-highlighter'; import { oneLight } from 'react-syntax-highlighter/dist/esm/styles/prism'; -import { Button, Container, Form, GridRow, Header, Icon } from 'semantic-ui-react'; +import { Container, Header, Icon } from 'semantic-ui-react'; import { Grid } from 'semantic-ui-react'; import { useEnvironment } from '../../hooks'; import { Document } from '../../types'; /** Render chatbot markdown safely for dangerouslySetInnerHTML. */ -export function renderChatMarkdown(markdown: string): string { - const parsed = marked.parse(markdown, { async: false }); +export function renderChatMarkdown(markdown: string, options?: { breaks?: boolean }): string { + const parsed = marked.parse(markdown, { async: false, breaks: options?.breaks ?? false }); return DOMPurify.sanitize(String(parsed), { USE_PROFILES: { html: true } }); } @@ -40,6 +40,40 @@ export const Chatbot = () => { const [chat, setChat] = useState(DEFAULT_CHAT_STATE); const [user, setUser] = useState(''); const [modelName, setModelName] = useState(''); + const textareaRef = useRef(null); + + function growTextarea() { + const el = textareaRef.current; + if (!el) return; + const container = messagesContainerRef.current; + const wasNearBottom = container + ? container.scrollHeight - container.scrollTop - container.clientHeight < 64 + : false; + + el.style.height = 'auto'; + const newHeight = Math.min(el.scrollHeight, 200); + el.style.height = `${newHeight}px`; + + const inputContainer = el.closest('.chat-input') as HTMLElement | null; + if (inputContainer) { + const surface = inputContainer.closest('.chat-surface') as HTMLElement | null; + if (surface) { + surface.style.setProperty('--composer-height', `${inputContainer.offsetHeight}px`); + } + } + + if (container) { + if (wasNearBottom) { + container.scrollTop = container.scrollHeight; + setShowScrollToBottom(false); + } else { + const threshold = 64; + const isNearBottom = + container.scrollHeight - container.scrollTop - container.clientHeight < threshold; + setShowScrollToBottom(!isNearBottom); + } + } + } function getModelDisplayName(modelName: string): string { if (!modelName) { @@ -99,7 +133,6 @@ export const Chatbot = () => { .catch((error) => { console.error('Error checking if user is logged in:', error); setError(error instanceof Error ? error.message : 'Network error checking login status'); - setLoading(false); }); } @@ -109,7 +142,7 @@ export const Chatbot = () => { } }, []); - function processResponse(response: string) { + function processResponse(response: string, isUser = false) { const responses = response.split('```'); const res: React.ReactElement[] = []; @@ -119,7 +152,7 @@ export const Chatbot = () => {

); @@ -136,12 +169,23 @@ export const Chatbot = () => { } async function onSubmit() { - if (!chat.term.trim()) return; + if (loading || !chat.term.trim()) return; shouldForceScrollRef.current = true; const currentTerm = chat.term; setChat({ ...chat, term: '' }); setLoading(true); + if (textareaRef.current) { + textareaRef.current.style.height = 'auto'; + const inputContainer = textareaRef.current.closest('.chat-input') as HTMLElement | null; + if (inputContainer) { + const surface = inputContainer.closest('.chat-surface') as HTMLElement | null; + if (surface) { + surface.style.setProperty('--composer-height', `${inputContainer.offsetHeight}px`); + } + } + textareaRef.current.focus(); + } setChatMessages((prev) => [ ...prev, @@ -253,7 +297,7 @@ export const Chatbot = () => { {m.timestamp} -

{processResponse(m.message)}
+
{processResponse(m.message, m.role === 'user')}
{m.data && m.data.length > 0 && (
@@ -300,17 +344,48 @@ export const Chatbot = () => { )} -
- +