diff --git a/src/frontend/components/layout/main.tsx b/src/frontend/components/layout/main.tsx index 44b5555..0617162 100644 --- a/src/frontend/components/layout/main.tsx +++ b/src/frontend/components/layout/main.tsx @@ -38,11 +38,13 @@ const Main = { display: flex; width: 100%; height: ${(props) => props.theme.layout.topBarHeight}px; + flex-shrink: 0; `, MainWrapper: Styled.div` display: flex; width: 80%; height: 70%; + flex-grow: 1; border-radius: 30px; border: 5px solid ${(props) => props.theme.colors.hunter}; padding: 10px; @@ -50,6 +52,7 @@ const Main = { BottomWrapper: Styled.div` display: flex; width: 100%; - height: 20%; + height: ${(props) => props.theme.layout.bottomBarHeight}px; + flex-shrink: 0; `, }; diff --git a/src/frontend/theme/theme.ts b/src/frontend/theme/theme.ts index 38c931b..0f0feb2 100644 --- a/src/frontend/theme/theme.ts +++ b/src/frontend/theme/theme.ts @@ -8,6 +8,7 @@ export interface ITheme { }; layout: { topBarHeight: number; + bottomBarHeight: number; }; fonts: { family: { @@ -38,8 +39,8 @@ const common = { balance: '#FFFFFF', }, layout: { - leftBarWidth: 200, topBarHeight: 130, + bottomBarHeight: 130, }, fonts: { size: { diff --git a/src/frontend/views/chat.tsx b/src/frontend/views/chat.tsx index 9c92be5..bd259da 100644 --- a/src/frontend/views/chat.tsx +++ b/src/frontend/views/chat.tsx @@ -1,5 +1,5 @@ // libs -import React, { FormEvent, useEffect, useState } from 'react'; +import React, { FormEvent, useEffect, useState, useRef } from 'react'; import Styled from 'styled-components'; import { useSDK } from '@metamask/sdk-react'; import { ThreeDots } from 'react-loader-spinner'; @@ -28,6 +28,9 @@ const ChatView = (): JSX.Element => { const ethInWei = '1000000000000000000'; const [selectedNetwork, setSelectedNetwork] = useState(''); + const chatMainRef = useRef(null); + const chatInputRef = useRef(null); + useEffect(() => { window.backendBridge.ollama.onAnswer((response) => { setDialogueEntries([ @@ -43,6 +46,32 @@ const ChatView = (): JSX.Element => { }; }); + // Scroll to bottom of chat when user adds new dialogue + useEffect(() => { + const observer = new MutationObserver((mutations) => { + for (const mutation of mutations) { + if (chatMainRef.current && mutation.type === 'childList') { + chatMainRef.current.scrollTop = chatMainRef.current.scrollHeight; + } + } + }); + + if (chatMainRef.current) { + observer.observe(chatMainRef?.current, { + childList: true, // observe direct children + }); + } + + return () => observer.disconnect(); + }, []); + + // Refocus onto input field once new dialogue entry is added + useEffect(() => { + if (chatInputRef.current) { + chatInputRef.current.focus(); + } + }, [dialogueEntries]); + //Function to update dialogue entries const updateDialogueEntries = (question: string, message: string) => { setCurrentQuestion(undefined); @@ -211,7 +240,7 @@ const ChatView = (): JSX.Element => { - + {dialogueEntries.map((entry, index) => { return ( { >