interstellar_ai/app/page.tsx
2024-09-18 10:03:36 +02:00

66 lines
1.5 KiB
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

// LandingPage.tsx
"use client";
import React, { useState, useEffect, useRef } from 'react';
import Header from './Header';
import History from './History';
import Models from './Models';
import Conversation from './Conversation';
import InputForm from './InputForm';
import './styles.css';
const LandingPage: React.FC = () => {
const [showDivs, setShowDivs] = useState(true);
const conversationRef = useRef<HTMLDivElement>(null);
useEffect(() => {
const scrollToBottom = () => {
const conversation = conversationRef.current;
if (conversation) {
conversation.scrollTop = conversation.scrollHeight;
}
};
scrollToBottom();
const observer = new MutationObserver(scrollToBottom);
if (conversationRef.current) {
observer.observe(conversationRef.current, {
childList: true,
subtree: true,
});
}
return () => {
if (conversationRef.current) {
observer.disconnect();
}
};
}, []);
const toggleDivs = () => {
setShowDivs(prevState => !prevState);
};
// Example messages array
const messages = [
'User: Hello!',
'AI: Hi there!',
'User: How are you?',
'AI: Im good, thank you!'
];
return (
<div className="App">
<Header toggleDivs={toggleDivs} showDivs={showDivs} />
<div className="container">
{showDivs && <History />}
{showDivs && <Models />}
<Conversation ref={conversationRef} messages={messages} />
<InputForm />
</div>
</div>
);
};
export default LandingPage;