interstellar_ai/app/page.tsx

67 lines
1.5 KiB
TypeScript
Raw Normal View History

2024-09-18 10:03:36 +02:00
// LandingPage.tsx
"use client";
2024-09-18 09:47:23 +02:00
import React, { useState, useEffect, useRef } from 'react';
2024-09-18 10:03:36 +02:00
import Header from './Header';
import History from './History';
import Models from './Models';
import Conversation from './Conversation';
import InputForm from './InputForm';
import './styles.css';
2024-09-18 09:47:23 +02:00
2024-09-18 10:03:36 +02:00
const LandingPage: React.FC = () => {
const [showDivs, setShowDivs] = useState(true);
2024-09-18 09:47:23 +02:00
const conversationRef = useRef<HTMLDivElement>(null);
useEffect(() => {
const scrollToBottom = () => {
const conversation = conversationRef.current;
if (conversation) {
conversation.scrollTop = conversation.scrollHeight;
}
};
2024-09-18 10:03:36 +02:00
scrollToBottom();
2024-09-18 09:47:23 +02:00
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);
};
2024-09-18 10:03:36 +02:00
// Example messages array
const messages = [
'User: Hello!',
'AI: Hi there!',
'User: How are you?',
'AI: Im good, thank you!'
];
2024-09-18 09:47:23 +02:00
return (
<div className="App">
2024-09-18 10:03:36 +02:00
<Header toggleDivs={toggleDivs} showDivs={showDivs} />
2024-09-18 09:47:23 +02:00
<div className="container">
2024-09-18 10:03:36 +02:00
{showDivs && <History />}
{showDivs && <Models />}
<Conversation ref={conversationRef} messages={messages} />
<InputForm />
2024-09-18 09:47:23 +02:00
</div>
</div>
);
};
2024-09-18 10:03:36 +02:00
export default LandingPage;