From 92c4a2d944b2b429ed8a528bef2823c5644bccc7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=B7=B1=E7=A9=BA?= <2793500992@qq.com> Date: Mon, 21 Apr 2025 23:03:18 -0400 Subject: [PATCH 1/8] Function; Add Image generation page --- src/App.tsx | 13 +- src/components/layout/MainLayout.tsx | 42 ++++--- src/components/layout/Sidebar.tsx | 44 ++++++- src/components/pages/ImageGenerationPage.tsx | 122 +++++++++++++++++++ src/services/message-helper.ts | 2 +- src/services/providers/openai-service.ts | 22 +++- src/services/settings-service.ts | 2 +- 7 files changed, 221 insertions(+), 26 deletions(-) create mode 100644 src/components/pages/ImageGenerationPage.tsx diff --git a/src/App.tsx b/src/App.tsx index 15404fe..7ecf492 100644 --- a/src/App.tsx +++ b/src/App.tsx @@ -1,9 +1,12 @@ -import { useEffect } from 'react'; +import { useEffect, useState } from 'react'; import { ChatPage } from './components/pages/ChatPage'; +import { ImageGenerationPage } from './components/pages/ImageGenerationPage'; import MainLayout from './components/layout/MainLayout'; import DatabaseInitializer from './components/core/DatabaseInitializer'; function App() { + const [activePage, setActivePage] = useState('chat'); + const [showSettings, setShowSettings] = useState(false); // Handle link clicks useEffect(() => { @@ -22,11 +25,15 @@ function App() { }; }, []); + const handlePageChange = (page: string) => { + setActivePage(page); + }; return ( - - + + {activePage === 'chat' && } + {activePage === 'image' && } ); diff --git a/src/components/layout/MainLayout.tsx b/src/components/layout/MainLayout.tsx index 1d82268..b579459 100644 --- a/src/components/layout/MainLayout.tsx +++ b/src/components/layout/MainLayout.tsx @@ -1,4 +1,4 @@ -import React, { ReactNode, useState } from 'react'; +import React, { ReactNode } from 'react'; import Sidebar from './Sidebar'; import SettingsPage from '../pages/SettingsPage'; import TopBar from './TopBar'; @@ -6,32 +6,42 @@ import { SettingsService } from '../../services/settings-service'; interface MainLayoutProps { children: ReactNode; + activePage: string; + onChangePage: (page: string) => void; + showSettings: boolean; + setShowSettings: (showSettings: boolean) => void; } -const MainLayout: React.FC = ({ children }) => { - const [activePage, setActivePage] = useState('chat'); - const [showSettings, setShowSettings] = useState(false); - - // Handle page changes - const handlePageChange = (page: string) => { - if(activePage === 'settings' && page !== activePage){ +const MainLayout: React.FC = ({ + children, + activePage, + onChangePage, + showSettings, + setShowSettings +}) => { + + // Handle settings dialog + const handleOpenSettingsDialog = () => { + if(activePage === 'settings' && activePage !== 'settings'){ // Save settings + SettingsService.getInstance().saveSettings(); } + setShowSettings(true); + onChangePage('settings'); + }; + + // Handle page changes + const handlePageChange = (page: string) => { if (page === 'settings') { setShowSettings(true); - setActivePage('settings'); + onChangePage('settings'); } else { setShowSettings(false); - setActivePage(page); + onChangePage(page); } }; - // Handle page changes - const handleOpenSettingsDialog = () => { - handlePageChange('settings'); - }; - // Handle selecting a model const handleSelectModel = (modelId: string, provider: string) => { SettingsService.getInstance().setSelectedModel(modelId); @@ -50,6 +60,8 @@ const MainLayout: React.FC = ({ children }) => {
diff --git a/src/components/layout/Sidebar.tsx b/src/components/layout/Sidebar.tsx index 76e5e8b..aefecaa 100644 --- a/src/components/layout/Sidebar.tsx +++ b/src/components/layout/Sidebar.tsx @@ -1,12 +1,34 @@ import React from 'react'; -import { MessageSquare, Settings } from 'lucide-react'; +import { MessageSquare, Settings, Image } from 'lucide-react'; interface SidebarProps { activePage: string; onChangePage: (page: string) => void; + showSettings: boolean; + setShowSettings: (showSettings: boolean) => void; } -export const Sidebar: React.FC = ({ activePage, onChangePage }) => { +export const Sidebar: React.FC = ({ + activePage, + onChangePage, + showSettings, + setShowSettings +}) => { + + const getActivePage = () => { + if(showSettings){ + return 'settings'; + } + else if(activePage === 'chat'){ + return 'chat'; + } + else if(activePage === 'image'){ + return 'image'; + } + + return ''; + } + return (
@@ -14,7 +36,7 @@ export const Sidebar: React.FC = ({ activePage, onChangePage }) =>
+ + {/* Add more navigation buttons here as needed */}
@@ -31,11 +65,11 @@ export const Sidebar: React.FC = ({ activePage, onChangePage }) =>