-
- {/* Mobile Sidebar Overlay */}
- {isSidebarVisible && (
-
-
-
-
-
-
- {chat ? (
-
- {chat.name}
-
- ) : (
-
- )}
-
-
-
-
- {chat ? (
-
- ) : (
-
- )}
-
-
-
-
- {/* Mobile Sidebar Overlay */}
- {isSidebarVisible && (
-
- {/* Backdrop - only covers the area not occupied by the sidebar */}
-
setIsSidebarVisible(false)}
- />
-
- {/* Sidebar */}
-
-
{}}
- onClose={() => setIsSidebarVisible(false)}
- />
-
-
- )}
-
-
- {chat && (
-
- )}
-
-
- );
- }
-
- // Desktop layout
- return (
-
- {/* Fixed Sidebar */}
- {isSidebarVisible && (
-
-
{}}
- className="h-screen sticky top-0"
- onToggleSidebar={() => setIsSidebarVisible(false)}
- />
-
- )}
-
- {/* Main Content Area */}
-
-
-
-
- {!isSidebarVisible && (
-
- )}
-
- {chat ? (
-
- {chat.name}
-
- ) : (
-
- )}
-
-
-
-
- {chat ? (
-
- ) : (
-
- )}
-
-
-
-
-
- {chat && (
-
- )}
-
-
-
- );
-}
diff --git a/src/pages/Index.tsx b/src/pages/Index.tsx
index 0571cd98..ea6f731c 100644
--- a/src/pages/Index.tsx
+++ b/src/pages/Index.tsx
@@ -2,15 +2,12 @@ import { useState, useEffect } from 'react';
import { useNavigate, useLocation } from 'react-router-dom';
import { useTranslation } from 'react-i18next';
import { useProjectsManager } from '@/hooks/useProjectsManager';
-import { useChatsManager } from '@/hooks/useChatsManager';
import { useGenerateProjectInfo } from '@/hooks/useGenerateProjectInfo';
import { useFS } from '@/hooks/useFS';
import { useLocalStorage } from '@/hooks/useLocalStorage';
import { useIsMobile } from '@/hooks/useIsMobile';
import { useAISettings } from '@/hooks/useAISettings';
import { useAppContext } from '@/hooks/useAppContext';
-import { ChatsManager } from '@/lib/ChatsManager';
-import { useQueryClient } from '@tanstack/react-query';
import { AppLayout } from '@/components/AppLayout';
import { OnboardingDialog } from '@/components/OnboardingDialog';
import { Act1Dialog } from '@/components/Act1Dialog';
@@ -42,9 +39,7 @@ export default function Index() {
const [giftCardCode, setGiftCardCode] = useState('');
const navigate = useNavigate();
const location = useLocation();
- const queryClient = useQueryClient();
const projectsManager = useProjectsManager();
- const chatsManager = useChatsManager();
const { fs } = useFS();
const { generateProjectInfo, isLoading: isGeneratingInfo } = useGenerateProjectInfo();
const { settings, addRecentlyUsedModel } = useAISettings();
@@ -223,96 +218,64 @@ export default function Index() {
const handleCreateProject = async () => {
if (!prompt.trim() || !providerModel.trim()) return;
- // Clear stored prompt when creating project/chat
+ // Clear stored prompt when creating project
setStoredPrompt('');
setIsCreating(true);
try {
- // Use AI to determine whether to create a project or start a chat
- const result = await generateProjectInfo(providerModel, prompt.trim());
+ // Use AI to generate project ID and select template
+ const { projectId, template } = await generateProjectInfo(providerModel, prompt.trim());
- // Add model to recently used
+ // Add model to recently used when creating project with AI
addRecentlyUsedModel(providerModel.trim());
- if (result.type === 'chat') {
- // Create a chat
- const { chatId } = result.info;
+ // Create project with AI-generated ID and selected template
+ const project = await projectsManager.createProject(
+ prompt.trim(),
+ template.url,
+ projectId,
+ () => {
+ // Show a toast if template update fails (non-critical)
+ toast({
+ title: t('templateUpdateFailed'),
+ description: t('templateUpdateFailedDescription'),
+ variant: 'default',
+ });
+ },
+ { name: template.name, description: template.description }
+ );
- // Generate unique chat ID with timestamp if needed
- let finalChatId = chatId;
- const existingChat = await chatsManager.getChat(chatId);
- if (existingChat !== null) {
- // Chat exists, generate unique ID with timestamp
- finalChatId = ChatsManager.generateChatId();
- }
+ // Build message content from input and attached files
+ // Images are converted to base64-encoded data URLs
+ const messageContent = await buildMessageContent(
+ prompt.trim(),
+ attachedFiles,
+ fs,
+ undefined
+ );
- // Create chat with initial message
- await chatsManager.createChat(finalChatId, prompt.trim());
+ // Store the initial message in chat history using DotAI
+ const dotAI = new DotAI(fs, `${config.fsPathProjects}/${project.id}`);
+ const sessionName = DotAI.generateSessionName();
- // Invalidate chats query to update sidebar
- queryClient.invalidateQueries({ queryKey: ['chats'] });
+ const initialMessage: AIMessage = {
+ role: 'user',
+ content: messageContent
+ };
+ await dotAI.setHistory(sessionName, [initialMessage]);
- // Clear attached files after successful creation
- setAttachedFiles([]);
+ // Clear attached files after successful creation
+ setAttachedFiles([]);
- // Navigate to the chat with autostart parameter and model
- const searchParams = new URLSearchParams({
- autostart: 'true',
- ...(providerModel.trim() && { model: providerModel.trim() })
- });
- navigate(`/chat/${finalChatId}?${searchParams.toString()}`);
- } else {
- // Create a project
- const { projectId, template } = result.info;
-
- // Create project with AI-generated ID and selected template
- const project = await projectsManager.createProject(
- prompt.trim(),
- template.url,
- projectId,
- () => {
- // Show a toast if template update fails (non-critical)
- toast({
- title: t('templateUpdateFailed'),
- description: t('templateUpdateFailedDescription'),
- variant: 'default',
- });
- },
- { name: template.name, description: template.description }
- );
-
- // Build message content from input and attached files
- // Images are converted to base64-encoded data URLs
- const messageContent = await buildMessageContent(
- prompt.trim(),
- attachedFiles,
- fs,
- undefined
- );
-
- // Store the initial message in chat history using DotAI
- const dotAI = new DotAI(fs, `${config.fsPathProjects}/${project.id}`);
- const sessionName = DotAI.generateSessionName();
-
- const initialMessage: AIMessage = {
- role: 'user',
- content: messageContent
- };
- await dotAI.setHistory(sessionName, [initialMessage]);
-
- // Clear attached files after successful creation
- setAttachedFiles([]);
-
- // Navigate to the project with autostart parameter and model
- const searchParams = new URLSearchParams({
- autostart: 'true',
- build: 'true',
- ...(providerModel.trim() && { model: providerModel.trim() })
- });
- navigate(`/project/${project.id}?${searchParams.toString()}`);
- }
+ // Navigate to the project with autostart parameter and model
+ const searchParams = new URLSearchParams({
+ autostart: 'true',
+ build: 'true',
+ ...(providerModel.trim() && { model: providerModel.trim() })
+ });
+ navigate(`/project/${project.id}?${searchParams.toString()}`);
} catch (error) {
- console.error('Failed to create project/chat:', error);
+ console.error('Failed to create project:', error);
setQuillyError(error instanceof Error ? error : new Error("An unexpected error occurred"));
} finally {
setIsCreating(false);
diff --git a/src/test/TestApp.tsx b/src/test/TestApp.tsx
index 32acc0be..660418e4 100644
--- a/src/test/TestApp.tsx
+++ b/src/test/TestApp.tsx
@@ -55,7 +55,6 @@ export function TestApp({ children }: TestAppProps) {
fsPathTmp: '/tmp',
fsPathPlugins: '/plugins',
fsPathTemplates: '/templates',
- fsPathChats: '/chats',
sentryDsn: '',
sentryEnabled: false,
};