interstellar_ai/app/page.tsx

126 lines
4.4 KiB
TypeScript
Raw Normal View History

2024-09-19 12:18:04 +02:00
"use client";
2024-09-18 09:47:23 +02:00
import React, { useState, useEffect, useRef } from 'react';
2024-09-20 10:34:16 +02:00
import Header from './components/Header';
import AI from './components/AI';
import FAQ from './components/Faq'; // Ensure the import path is correct
import Documentation from './components/Documentation'; // Ensure the import path is correct
import History from './components/History';
import Models from './components/Models';
import Credits from './components/Credits';
import {
applyIOMarketTheme,
applyWhiteTheme,
applyBlackTheme,
applyCustomTheme,
applyBasicCustomTheme
} from './components/settings/theme';
2024-09-18 11:17:34 +02:00
import './styles/master.css';
2024-09-18 09:47:23 +02:00
2024-09-18 10:03:36 +02:00
const LandingPage: React.FC = () => {
// State to control visibility of the left panels
2024-09-18 10:03:36 +02:00
const [showDivs, setShowDivs] = useState(true);
// State to track which view is currently displayed
const [view, setView] = useState<'AI' | 'FAQ' | 'Documentation' | 'Credits'>('AI');
2024-09-18 09:47:23 +02:00
const conversationRef = useRef<HTMLDivElement>(null);
// State for theme colors
const [primaryColor, setPrimaryColor] = useState("#fefefe");
const [secondaryColor, setSecondaryColor] = useState("#fefefe");
const [accentColor, setAccentColor] = useState("#fefefe");
const [basicBackgroundColor, setBasicBackgroundColor] = useState("#fefefe");
const [basicTextColor, setBasicTextColor] = useState("#fefefe");
2024-10-02 12:18:40 +02:00
// Synchronize theme colors with local storage on component mount
useEffect(() => {
2024-10-07 11:16:51 +02:00
if (typeof localStorage !== 'undefined') {
setPrimaryColor(localStorage.getItem("primaryColor") || "#fefefe");
setSecondaryColor(localStorage.getItem("secondaryColor") || "#fefefe");
setAccentColor(localStorage.getItem("accentColor") || "#fefefe");
setBasicBackgroundColor(localStorage.getItem("basicBackgroundColor") || "#fefefe");
setBasicTextColor(localStorage.getItem("basicTextColor") || "#fefefe");
}
}, [primaryColor, secondaryColor, accentColor, basicBackgroundColor, basicTextColor]);
2024-10-02 12:18:40 +02:00
// Toggle visibility of the left panels
2024-09-18 09:47:23 +02:00
const toggleDivs = () => {
setShowDivs(prevState => !prevState);
};
// Change the current view based on user selection
const handleViewChange = (view: 'AI' | 'FAQ' | 'Documentation' | 'Credits') => {
2024-09-19 09:54:00 +02:00
setView(view);
// Hide left panels if the selected view is not 'AI'
2024-09-19 09:54:00 +02:00
if (view !== 'AI') {
setShowDivs(false);
}
};
// Apply the selected theme and color settings based on local storage
useEffect(() => {
2024-10-07 11:16:51 +02:00
if (typeof localStorage !== 'undefined') {
const savedTheme = localStorage.getItem('selectedTheme');
if (savedTheme) {
switch (savedTheme) {
case 'IOMARKET':
applyIOMarketTheme();
break;
case 'WHITE':
applyWhiteTheme();
2024-10-07 11:16:51 +02:00
break;
case 'BLACK':
applyBlackTheme();
break;
case 'CUSTOM':
applyCustomTheme();
break;
case 'BASIC-CUSTOM':
applyBasicCustomTheme(
2024-10-07 11:16:51 +02:00
primaryColor,
secondaryColor,
accentColor,
basicBackgroundColor,
basicTextColor
);
break;
default:
applyIOMarketTheme(); // Fallback theme
2024-10-07 11:16:51 +02:00
break;
}
}
}
}, [primaryColor, secondaryColor, accentColor, basicBackgroundColor, basicTextColor]); // Apply themes whenever color states change
2024-09-30 16:07:01 +02:00
2024-09-18 09:47:23 +02:00
return (
2024-10-11 10:46:05 +02:00
<div>
{/* Header component with props for toggling and view change */}
<Header
toggleDivs={toggleDivs}
showDivs={showDivs}
onViewChange={handleViewChange}
showHistoryModelsToggle={true}
showToggle={view === 'AI'}
/>
2024-09-27 16:48:17 +02:00
<div className="container">
<div className={`left-panel ${showDivs ? 'visible' : 'hidden'}`}>
{showDivs && (
<div className="history-models">
{/* Show History and Models components if left panels are visible */}
2024-10-09 14:01:48 +02:00
<History />
<Models />
</div>
)}
</div>
<div className={`conversation-container ${showDivs ? 'collapsed' : 'expanded'}`} ref={conversationRef}>
{/* Render the selected view based on the current state */}
2024-10-09 14:01:48 +02:00
{view === 'AI' && <AI />}
{view === 'FAQ' && <FAQ />}
{view === 'Documentation' && <Documentation />}
{view === 'Credits' && <Credits />}
</div>
2024-09-19 12:18:04 +02:00
</div>
2024-10-11 10:46:05 +02:00
</div>
2024-09-18 09:47:23 +02:00
);
};
2024-09-18 10:03:36 +02:00
export default LandingPage;