mirror of
https://gitlab.com/soapbox-pub/shakespeare.git
synced 2026-12-05 08:23:34 +00:00
Don't use flexible sidebar in ChatView
This commit is contained in:
2 files changed
+97
-620
No files matched your search
@@ -1,514 +0,0 @@
|
||||
import { describe, it, expect, vi, beforeEach } from 'vitest';
|
||||
import { renderHook, waitFor } from '@testing-library/react';
|
||||
import { useGenerateProjectInfo } from './useGenerateProjectInfo';
|
||||
import { useAISettings } from './useAISettings';
|
||||
import { useCurrentUser } from './useCurrentUser';
|
||||
import { useAppContext } from './useAppContext';
|
||||
import { useProjectsManager } from './useProjectsManager';
|
||||
import { createAIClient } from '@/lib/ai-client';
|
||||
import { parseProviderModel } from '@/lib/parseProviderModel';
|
||||
import type { ProjectsManager } from '@/lib/ProjectsManager';
|
||||
import type { ProjectTemplate } from '@/contexts/AppContext';
|
||||
|
||||
// Mock the hooks and dependencies
|
||||
vi.mock('./useAISettings');
|
||||
vi.mock('./useCurrentUser');
|
||||
vi.mock('./useAppContext');
|
||||
vi.mock('./useProjectsManager');
|
||||
vi.mock('@/lib/ai-client');
|
||||
vi.mock('@/lib/parseProviderModel');
|
||||
|
||||
describe('useGenerateProjectInfo', () => {
|
||||
const mockUseAISettings = vi.mocked(useAISettings);
|
||||
const mockUseCurrentUser = vi.mocked(useCurrentUser);
|
||||
const mockUseAppContext = vi.mocked(useAppContext);
|
||||
const mockUseProjectsManager = vi.mocked(useProjectsManager);
|
||||
const mockCreateAIClient = vi.mocked(createAIClient);
|
||||
const mockParseProviderModel = vi.mocked(parseProviderModel);
|
||||
|
||||
const defaultTemplates: ProjectTemplate[] = [
|
||||
{
|
||||
name: "MKStack",
|
||||
description: "Build Nostr clients with React.",
|
||||
url: "https://gitlab.com/soapbox-pub/mkstack.git"
|
||||
},
|
||||
{
|
||||
name: "VanillaJS",
|
||||
description: "Simple vanilla JavaScript template.",
|
||||
url: "https://github.com/example/vanilla-template.git"
|
||||
}
|
||||
];
|
||||
|
||||
let mockGetProject: ReturnType<typeof vi.fn>;
|
||||
|
||||
beforeEach(() => {
|
||||
vi.clearAllMocks();
|
||||
|
||||
// Mock fetch globally
|
||||
global.fetch = vi.fn();
|
||||
|
||||
// Mock useCurrentUser to return undefined user by default
|
||||
mockUseCurrentUser.mockReturnValue({
|
||||
user: undefined,
|
||||
users: [],
|
||||
});
|
||||
|
||||
// Mock useAppContext
|
||||
const config = {
|
||||
theme: 'dark' as const,
|
||||
relayMetadata: {
|
||||
relays: [{ url: 'wss://relay.damus.io', read: true, write: true }],
|
||||
updatedAt: 0,
|
||||
},
|
||||
templates: defaultTemplates,
|
||||
esmUrl: 'https://esm.sh',
|
||||
corsProxy: 'https://proxy.example.com/{href}',
|
||||
faviconUrl: 'https://external-content.duckduckgo.com/ip3/{hostname}.ico',
|
||||
previewDomain: 'local-shakespeare.dev',
|
||||
showcaseEnabled: true,
|
||||
showcaseModerator: 'npub1jvnpg4c6ljadf5t6ry0w9q0rnm4mksde87kglkrc993z46c39axsgq89sc',
|
||||
ngitServers: ['git.shakespeare.diy', 'relay.ngit.dev'],
|
||||
fsPathProjects: '/projects',
|
||||
fsPathConfig: '/config',
|
||||
fsPathTmp: '/tmp',
|
||||
fsPathPlugins: '/plugins',
|
||||
fsPathTemplates: '/templates',
|
||||
fsPathChats: '/chats',
|
||||
sentryDsn: '',
|
||||
sentryEnabled: false,
|
||||
};
|
||||
mockUseAppContext.mockReturnValue({
|
||||
config,
|
||||
defaultConfig: config,
|
||||
updateConfig: vi.fn(),
|
||||
});
|
||||
|
||||
// Mock useProjectsManager
|
||||
mockGetProject = vi.fn().mockResolvedValue(null);
|
||||
const mockProjectsManager = {
|
||||
getProject: mockGetProject,
|
||||
} as unknown as ProjectsManager;
|
||||
mockUseProjectsManager.mockReturnValue(mockProjectsManager);
|
||||
|
||||
// Mock parseProviderModel
|
||||
mockParseProviderModel.mockReturnValue({
|
||||
provider: { id: 'openai', name: 'OpenAI', apiKey: 'test-key', baseURL: 'https://api.openai.com/v1' },
|
||||
model: 'gpt-4',
|
||||
});
|
||||
|
||||
// Mock createAIClient
|
||||
const mockCompletion = {
|
||||
choices: [{
|
||||
message: {
|
||||
tool_calls: [{
|
||||
type: 'function' as const,
|
||||
function: {
|
||||
name: 'create_project',
|
||||
arguments: JSON.stringify({
|
||||
project_name: 'test-project-name',
|
||||
template_url: 'https://gitlab.com/soapbox-pub/mkstack.git'
|
||||
})
|
||||
}
|
||||
}]
|
||||
}
|
||||
}]
|
||||
};
|
||||
const mockOpenAI = {
|
||||
chat: {
|
||||
completions: {
|
||||
create: vi.fn().mockResolvedValue(mockCompletion)
|
||||
}
|
||||
}
|
||||
} as unknown as ReturnType<typeof createAIClient>;
|
||||
mockCreateAIClient.mockReturnValue(mockOpenAI);
|
||||
});
|
||||
|
||||
it('should return not configured when AI settings are not configured', () => {
|
||||
mockUseAISettings.mockReturnValue({
|
||||
settings: { providers: [], recentlyUsedModels: [], mcpServers: {} },
|
||||
isConfigured: false,
|
||||
updateSettings: vi.fn(),
|
||||
setProvider: vi.fn(),
|
||||
removeProvider: vi.fn(),
|
||||
setProviders: vi.fn(),
|
||||
addRecentlyUsedModel: vi.fn(),
|
||||
setMCPServer: vi.fn(),
|
||||
removeMCPServer: vi.fn(),
|
||||
});
|
||||
|
||||
const { result } = renderHook(() => useGenerateProjectInfo());
|
||||
|
||||
expect(result.current.isConfigured).toBe(false);
|
||||
expect(result.current.isLoading).toBe(false);
|
||||
});
|
||||
|
||||
it('should throw error when trying to generate without configuration', async () => {
|
||||
mockUseAISettings.mockReturnValue({
|
||||
settings: { providers: [], recentlyUsedModels: [], mcpServers: {} },
|
||||
isConfigured: false,
|
||||
updateSettings: vi.fn(),
|
||||
setProvider: vi.fn(),
|
||||
removeProvider: vi.fn(),
|
||||
setProviders: vi.fn(),
|
||||
addRecentlyUsedModel: vi.fn(),
|
||||
setMCPServer: vi.fn(),
|
||||
removeMCPServer: vi.fn(),
|
||||
});
|
||||
|
||||
const { result } = renderHook(() => useGenerateProjectInfo());
|
||||
|
||||
await expect(result.current.generateProjectInfo('openai/gpt-4', 'test prompt')).rejects.toThrow(
|
||||
'AI settings not configured'
|
||||
);
|
||||
});
|
||||
|
||||
it('should throw error when prompt is empty', async () => {
|
||||
mockUseAISettings.mockReturnValue({
|
||||
settings: {
|
||||
providers: [
|
||||
{ id: 'openai', name: 'OpenAI', apiKey: 'test-key', baseURL: 'https://api.openai.com/v1' }
|
||||
],
|
||||
recentlyUsedModels: [],
|
||||
mcpServers: {}
|
||||
},
|
||||
isConfigured: true,
|
||||
updateSettings: vi.fn(),
|
||||
setProvider: vi.fn(),
|
||||
removeProvider: vi.fn(),
|
||||
setProviders: vi.fn(),
|
||||
addRecentlyUsedModel: vi.fn(),
|
||||
setMCPServer: vi.fn(),
|
||||
removeMCPServer: vi.fn(),
|
||||
});
|
||||
|
||||
const { result } = renderHook(() => useGenerateProjectInfo());
|
||||
|
||||
await expect(result.current.generateProjectInfo('openai/gpt-4', '')).rejects.toThrow(
|
||||
'Prompt cannot be empty'
|
||||
);
|
||||
});
|
||||
|
||||
it('should throw error when no templates are configured', async () => {
|
||||
mockUseAISettings.mockReturnValue({
|
||||
settings: {
|
||||
providers: [
|
||||
{ id: 'openai', name: 'OpenAI', apiKey: 'test-key', baseURL: 'https://api.openai.com/v1' }
|
||||
],
|
||||
recentlyUsedModels: [],
|
||||
mcpServers: {}
|
||||
},
|
||||
isConfigured: true,
|
||||
updateSettings: vi.fn(),
|
||||
setProvider: vi.fn(),
|
||||
removeProvider: vi.fn(),
|
||||
setProviders: vi.fn(),
|
||||
addRecentlyUsedModel: vi.fn(),
|
||||
setMCPServer: vi.fn(),
|
||||
removeMCPServer: vi.fn(),
|
||||
});
|
||||
|
||||
// Mock config with no templates
|
||||
const config = {
|
||||
theme: 'dark' as const,
|
||||
relayMetadata: {
|
||||
relays: [{ url: 'wss://relay.damus.io', read: true, write: true }],
|
||||
updatedAt: 0,
|
||||
},
|
||||
templates: [],
|
||||
esmUrl: 'https://esm.sh',
|
||||
corsProxy: 'https://proxy.example.com/{href}',
|
||||
faviconUrl: 'https://external-content.duckduckgo.com/ip3/{hostname}.ico',
|
||||
previewDomain: 'local-shakespeare.dev',
|
||||
showcaseEnabled: true,
|
||||
showcaseModerator: 'npub1jvnpg4c6ljadf5t6ry0w9q0rnm4mksde87kglkrc993z46c39axsgq89sc',
|
||||
ngitServers: ['git.shakespeare.diy', 'relay.ngit.dev'],
|
||||
fsPathProjects: '/projects',
|
||||
fsPathConfig: '/config',
|
||||
fsPathTmp: '/tmp',
|
||||
fsPathPlugins: '/plugins',
|
||||
fsPathTemplates: '/templates',
|
||||
fsPathChats: '/chats',
|
||||
sentryDsn: '',
|
||||
sentryEnabled: false,
|
||||
};
|
||||
mockUseAppContext.mockReturnValue({
|
||||
config,
|
||||
defaultConfig: config,
|
||||
updateConfig: vi.fn(),
|
||||
});
|
||||
|
||||
const { result } = renderHook(() => useGenerateProjectInfo());
|
||||
|
||||
await expect(result.current.generateProjectInfo('openai/gpt-4', 'test prompt')).rejects.toThrow(
|
||||
'No templates configured'
|
||||
);
|
||||
});
|
||||
|
||||
it('should successfully generate project info with template selection', async () => {
|
||||
mockUseAISettings.mockReturnValue({
|
||||
settings: {
|
||||
providers: [
|
||||
{ id: 'openai', name: 'OpenAI', apiKey: 'test-key', baseURL: 'https://api.openai.com/v1' }
|
||||
],
|
||||
recentlyUsedModels: [],
|
||||
mcpServers: {}
|
||||
},
|
||||
isConfigured: true,
|
||||
updateSettings: vi.fn(),
|
||||
setProvider: vi.fn(),
|
||||
removeProvider: vi.fn(),
|
||||
setProviders: vi.fn(),
|
||||
addRecentlyUsedModel: vi.fn(),
|
||||
setMCPServer: vi.fn(),
|
||||
removeMCPServer: vi.fn(),
|
||||
});
|
||||
|
||||
const { result } = renderHook(() => useGenerateProjectInfo());
|
||||
|
||||
const projectInfo = await result.current.generateProjectInfo('openai/gpt-4', 'A social media app for developers');
|
||||
|
||||
expect(projectInfo).toEqual({
|
||||
projectId: 'test-project-name',
|
||||
template: {
|
||||
name: 'MKStack',
|
||||
description: 'Build Nostr clients with React.',
|
||||
url: 'https://gitlab.com/soapbox-pub/mkstack.git'
|
||||
}
|
||||
});
|
||||
expect(mockParseProviderModel).toHaveBeenCalledWith('openai/gpt-4', [
|
||||
{ id: 'openai', name: 'OpenAI', apiKey: 'test-key', baseURL: 'https://api.openai.com/v1' }
|
||||
]);
|
||||
expect(mockCreateAIClient).toHaveBeenCalledWith(
|
||||
{ id: 'openai', name: 'OpenAI', apiKey: 'test-key', baseURL: 'https://api.openai.com/v1' },
|
||||
undefined,
|
||||
'https://proxy.example.com/{href}'
|
||||
);
|
||||
});
|
||||
|
||||
it('should fallback to first template when AI selects invalid template URL', async () => {
|
||||
mockUseAISettings.mockReturnValue({
|
||||
settings: {
|
||||
providers: [
|
||||
{ id: 'openai', name: 'OpenAI', apiKey: 'test-key', baseURL: 'https://api.openai.com/v1' }
|
||||
],
|
||||
recentlyUsedModels: [],
|
||||
mcpServers: {}
|
||||
},
|
||||
isConfigured: true,
|
||||
updateSettings: vi.fn(),
|
||||
setProvider: vi.fn(),
|
||||
removeProvider: vi.fn(),
|
||||
setProviders: vi.fn(),
|
||||
addRecentlyUsedModel: vi.fn(),
|
||||
setMCPServer: vi.fn(),
|
||||
removeMCPServer: vi.fn(),
|
||||
});
|
||||
|
||||
// Mock AI to return invalid template URL
|
||||
const mockCompletion = {
|
||||
choices: [{
|
||||
message: {
|
||||
tool_calls: [{
|
||||
type: 'function' as const,
|
||||
function: {
|
||||
name: 'create_project',
|
||||
arguments: JSON.stringify({
|
||||
project_name: 'test-project',
|
||||
template_url: 'https://invalid-url.com/template.git'
|
||||
})
|
||||
}
|
||||
}]
|
||||
}
|
||||
}]
|
||||
};
|
||||
const mockOpenAI = {
|
||||
chat: {
|
||||
completions: {
|
||||
create: vi.fn().mockResolvedValue(mockCompletion)
|
||||
}
|
||||
}
|
||||
} as unknown as ReturnType<typeof createAIClient>;
|
||||
mockCreateAIClient.mockReturnValue(mockOpenAI);
|
||||
|
||||
const { result } = renderHook(() => useGenerateProjectInfo());
|
||||
|
||||
const generatedInfo = await result.current.generateProjectInfo('openai/gpt-4', 'test prompt');
|
||||
|
||||
expect(generatedInfo.type).toBe('project');
|
||||
if (generatedInfo.type === 'project') {
|
||||
expect(generatedInfo.info.template.url).toBe('https://gitlab.com/soapbox-pub/mkstack.git');
|
||||
expect(generatedInfo.info.projectId).toBe('untitled');
|
||||
}
|
||||
});
|
||||
|
||||
it('should increment AI-generated ID when project already exists', async () => {
|
||||
mockUseAISettings.mockReturnValue({
|
||||
settings: {
|
||||
providers: [
|
||||
{ id: 'openai', name: 'OpenAI', apiKey: 'test-key', baseURL: 'https://api.openai.com/v1' }
|
||||
],
|
||||
recentlyUsedModels: [],
|
||||
mcpServers: {}
|
||||
},
|
||||
isConfigured: true,
|
||||
updateSettings: vi.fn(),
|
||||
setProvider: vi.fn(),
|
||||
removeProvider: vi.fn(),
|
||||
setProviders: vi.fn(),
|
||||
addRecentlyUsedModel: vi.fn(),
|
||||
setMCPServer: vi.fn(),
|
||||
removeMCPServer: vi.fn(),
|
||||
});
|
||||
|
||||
// Reset and override the mock to return project on first call, null on second
|
||||
mockGetProject.mockReset();
|
||||
mockGetProject
|
||||
.mockResolvedValueOnce({ id: 'test-project-name', name: 'Test Project', path: '/projects/test-project-name', lastModified: new Date() })
|
||||
.mockResolvedValue(null);
|
||||
|
||||
const { result } = renderHook(() => useGenerateProjectInfo());
|
||||
|
||||
const generatedInfo = await result.current.generateProjectInfo('openai/gpt-4', 'test prompt');
|
||||
|
||||
expect(generatedInfo.type).toBe('project');
|
||||
if (generatedInfo.type === 'project') {
|
||||
expect(generatedInfo.info.projectId).toBe('test-project-name-1');
|
||||
expect(generatedInfo.info.template.url).toBe('https://gitlab.com/soapbox-pub/mkstack.git');
|
||||
}
|
||||
expect(mockGetProject).toHaveBeenCalledTimes(2);
|
||||
expect(mockGetProject).toHaveBeenNthCalledWith(1, 'test-project-name');
|
||||
expect(mockGetProject).toHaveBeenNthCalledWith(2, 'test-project-name-1');
|
||||
});
|
||||
|
||||
it('should increment multiple times when necessary', async () => {
|
||||
mockUseAISettings.mockReturnValue({
|
||||
settings: {
|
||||
providers: [
|
||||
{ id: 'openai', name: 'OpenAI', apiKey: 'test-key', baseURL: 'https://api.openai.com/v1' }
|
||||
],
|
||||
recentlyUsedModels: [],
|
||||
mcpServers: {}
|
||||
},
|
||||
isConfigured: true,
|
||||
updateSettings: vi.fn(),
|
||||
setProvider: vi.fn(),
|
||||
removeProvider: vi.fn(),
|
||||
setProviders: vi.fn(),
|
||||
addRecentlyUsedModel: vi.fn(),
|
||||
setMCPServer: vi.fn(),
|
||||
removeMCPServer: vi.fn(),
|
||||
});
|
||||
|
||||
// Reset and override the mock - base and -1 exist, -2 is available
|
||||
mockGetProject.mockReset();
|
||||
mockGetProject
|
||||
.mockResolvedValueOnce({ id: 'test-project-name', name: 'Test Project', path: '/projects/test-project-name', lastModified: new Date() })
|
||||
.mockResolvedValueOnce({ id: 'test-project-name-1', name: 'Test Project 1', path: '/projects/test-project-name-1', lastModified: new Date() })
|
||||
.mockResolvedValue(null);
|
||||
|
||||
const { result } = renderHook(() => useGenerateProjectInfo());
|
||||
|
||||
const generatedInfo = await result.current.generateProjectInfo('openai/gpt-4', 'test prompt');
|
||||
|
||||
expect(generatedInfo.type).toBe('project');
|
||||
if (generatedInfo.type === 'project') {
|
||||
expect(generatedInfo.info.projectId).toBe('test-project-name-2');
|
||||
expect(generatedInfo.info.template.url).toBe('https://gitlab.com/soapbox-pub/mkstack.git');
|
||||
}
|
||||
expect(mockGetProject).toHaveBeenCalledTimes(3);
|
||||
expect(mockGetProject).toHaveBeenNthCalledWith(1, 'test-project-name');
|
||||
expect(mockGetProject).toHaveBeenNthCalledWith(2, 'test-project-name-1');
|
||||
expect(mockGetProject).toHaveBeenNthCalledWith(3, 'test-project-name-2');
|
||||
});
|
||||
|
||||
it('should handle loading state correctly', async () => {
|
||||
mockUseAISettings.mockReturnValue({
|
||||
settings: {
|
||||
providers: [
|
||||
{ id: 'openai', name: 'OpenAI', apiKey: 'test-key', baseURL: 'https://api.openai.com/v1' }
|
||||
],
|
||||
recentlyUsedModels: [],
|
||||
mcpServers: {}
|
||||
},
|
||||
isConfigured: true,
|
||||
updateSettings: vi.fn(),
|
||||
setProvider: vi.fn(),
|
||||
removeProvider: vi.fn(),
|
||||
setProviders: vi.fn(),
|
||||
addRecentlyUsedModel: vi.fn(),
|
||||
setMCPServer: vi.fn(),
|
||||
removeMCPServer: vi.fn(),
|
||||
});
|
||||
|
||||
const { result } = renderHook(() => useGenerateProjectInfo());
|
||||
|
||||
expect(result.current.isLoading).toBe(false);
|
||||
|
||||
const promise = result.current.generateProjectInfo('openai/gpt-4', 'Test prompt');
|
||||
|
||||
await waitFor(() => {
|
||||
expect(result.current.isLoading).toBe(false); // Should be false after completion
|
||||
});
|
||||
|
||||
await promise;
|
||||
});
|
||||
|
||||
it('should select second template when AI chooses it', async () => {
|
||||
mockUseAISettings.mockReturnValue({
|
||||
settings: {
|
||||
providers: [
|
||||
{ id: 'openai', name: 'OpenAI', apiKey: 'test-key', baseURL: 'https://api.openai.com/v1' }
|
||||
],
|
||||
recentlyUsedModels: [],
|
||||
mcpServers: {}
|
||||
},
|
||||
isConfigured: true,
|
||||
updateSettings: vi.fn(),
|
||||
setProvider: vi.fn(),
|
||||
removeProvider: vi.fn(),
|
||||
setProviders: vi.fn(),
|
||||
addRecentlyUsedModel: vi.fn(),
|
||||
setMCPServer: vi.fn(),
|
||||
removeMCPServer: vi.fn(),
|
||||
});
|
||||
|
||||
// Mock AI to select the second template
|
||||
const mockCompletion = {
|
||||
choices: [{
|
||||
message: {
|
||||
tool_calls: [{
|
||||
type: 'function' as const,
|
||||
function: {
|
||||
name: 'create_project',
|
||||
arguments: JSON.stringify({
|
||||
project_name: 'vanilla-app',
|
||||
template_url: 'https://github.com/example/vanilla-template.git'
|
||||
})
|
||||
}
|
||||
}]
|
||||
}
|
||||
}]
|
||||
};
|
||||
const mockOpenAI = {
|
||||
chat: {
|
||||
completions: {
|
||||
create: vi.fn().mockResolvedValue(mockCompletion)
|
||||
}
|
||||
}
|
||||
} as unknown as ReturnType<typeof createAIClient>;
|
||||
mockCreateAIClient.mockReturnValue(mockOpenAI);
|
||||
|
||||
const { result } = renderHook(() => useGenerateProjectInfo());
|
||||
|
||||
const projectInfo = await result.current.generateProjectInfo('openai/gpt-4', 'A simple vanilla JS app');
|
||||
|
||||
expect(projectInfo).toEqual({
|
||||
projectId: 'vanilla-app',
|
||||
template: {
|
||||
name: 'VanillaJS',
|
||||
description: 'Simple vanilla JavaScript template.',
|
||||
url: 'https://github.com/example/vanilla-template.git'
|
||||
}
|
||||
});
|
||||
});
|
||||
});
|
||||
+97
-106
@@ -4,7 +4,6 @@ import { type Chat } from '@/lib/ChatsManager';
|
||||
import { useChatsManager } from '@/hooks/useChatsManager';
|
||||
import { ChatPane, type ChatPaneRef } from '@/components/Shakespeare/ChatPane';
|
||||
import { ProjectSidebar } from '@/components/ProjectSidebar';
|
||||
import { ResizablePanelGroup, ResizablePanel, ResizableHandle } from '@/components/ui/resizable';
|
||||
import { Button } from '@/components/ui/button';
|
||||
import { Skeleton } from '@/components/ui/skeleton';
|
||||
import { ArrowLeft, Menu } from 'lucide-react';
|
||||
@@ -115,51 +114,47 @@ export function ChatView() {
|
||||
|
||||
// Desktop layout for not found
|
||||
return (
|
||||
<div className="h-screen flex flex-col bg-background">
|
||||
<ResizablePanelGroup direction="horizontal">
|
||||
{isSidebarVisible && (
|
||||
<>
|
||||
<ResizablePanel defaultSize={20} minSize={15} maxSize={30}>
|
||||
<ProjectSidebar
|
||||
selectedProject={null}
|
||||
onSelectProject={() => {}}
|
||||
onToggleSidebar={() => setIsSidebarVisible(false)}
|
||||
/>
|
||||
</ResizablePanel>
|
||||
<ResizableHandle withHandle />
|
||||
</>
|
||||
)}
|
||||
<div className="h-screen flex bg-background">
|
||||
{/* Fixed Sidebar */}
|
||||
{isSidebarVisible && (
|
||||
<div className="w-72 border-r bg-sidebar">
|
||||
<ProjectSidebar
|
||||
selectedProject={null}
|
||||
onSelectProject={() => {}}
|
||||
className="h-screen sticky top-0"
|
||||
onToggleSidebar={() => setIsSidebarVisible(false)}
|
||||
/>
|
||||
</div>
|
||||
)}
|
||||
|
||||
<ResizablePanel defaultSize={isSidebarVisible ? 80 : 100}>
|
||||
<div className="h-screen flex flex-col">
|
||||
<div className="flex-1 flex items-center justify-center p-4">
|
||||
{/* Menu button when sidebar is collapsed */}
|
||||
{!isSidebarVisible && (
|
||||
<div className="absolute top-4 left-4">
|
||||
<Button
|
||||
variant="ghost"
|
||||
size="sm"
|
||||
onClick={() => setIsSidebarVisible(true)}
|
||||
>
|
||||
<Menu className="h-4 w-4" />
|
||||
</Button>
|
||||
</div>
|
||||
)}
|
||||
|
||||
<div className="text-center">
|
||||
<h1 className="text-2xl font-bold mb-2">Chat Not Found</h1>
|
||||
<p className="text-muted-foreground mb-4">
|
||||
This chat may have been deleted or doesn't exist.
|
||||
</p>
|
||||
<Button onClick={() => navigate('/')} variant="outline">
|
||||
<ArrowLeft className="mr-2 h-4 w-4" />
|
||||
Back to Home
|
||||
</Button>
|
||||
</div>
|
||||
{/* Main Content Area */}
|
||||
<div className="flex-1 flex flex-col">
|
||||
<div className="flex-1 flex items-center justify-center p-4 relative">
|
||||
{/* Menu button when sidebar is collapsed */}
|
||||
{!isSidebarVisible && (
|
||||
<div className="absolute top-4 left-4">
|
||||
<Button
|
||||
variant="ghost"
|
||||
size="sm"
|
||||
onClick={() => setIsSidebarVisible(true)}
|
||||
>
|
||||
<Menu className="h-4 w-4" />
|
||||
</Button>
|
||||
</div>
|
||||
)}
|
||||
|
||||
<div className="text-center">
|
||||
<h1 className="text-2xl font-bold mb-2">Chat Not Found</h1>
|
||||
<p className="text-muted-foreground mb-4">
|
||||
This chat may have been deleted or doesn't exist.
|
||||
</p>
|
||||
<Button onClick={() => navigate('/')} variant="outline">
|
||||
<ArrowLeft className="mr-2 h-4 w-4" />
|
||||
Back to Home
|
||||
</Button>
|
||||
</div>
|
||||
</ResizablePanel>
|
||||
</ResizablePanelGroup>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
@@ -246,81 +241,77 @@ export function ChatView() {
|
||||
|
||||
// Desktop layout
|
||||
return (
|
||||
<div className="h-screen flex flex-col bg-background">
|
||||
<ResizablePanelGroup direction="horizontal">
|
||||
{isSidebarVisible && (
|
||||
<>
|
||||
<ResizablePanel defaultSize={20} minSize={15} maxSize={30}>
|
||||
<ProjectSidebar
|
||||
selectedProject={null}
|
||||
onSelectProject={() => {}}
|
||||
onToggleSidebar={() => setIsSidebarVisible(false)}
|
||||
/>
|
||||
</ResizablePanel>
|
||||
<ResizableHandle withHandle />
|
||||
</>
|
||||
)}
|
||||
<div className="h-screen flex bg-background">
|
||||
{/* Fixed Sidebar */}
|
||||
{isSidebarVisible && (
|
||||
<div className="w-72 border-r bg-sidebar">
|
||||
<ProjectSidebar
|
||||
selectedProject={null}
|
||||
onSelectProject={() => {}}
|
||||
className="h-screen sticky top-0"
|
||||
onToggleSidebar={() => setIsSidebarVisible(false)}
|
||||
/>
|
||||
</div>
|
||||
)}
|
||||
|
||||
<ResizablePanel defaultSize={isSidebarVisible ? 80 : 100}>
|
||||
<div className="h-screen flex flex-col">
|
||||
<header className="pt-safe bg-gradient-to-r from-primary/10 via-accent/5 to-primary/10 backdrop-blur">
|
||||
<div className="h-12 border-b px-4 py-3 flex items-center justify-between">
|
||||
<div className="flex items-center space-x-2 overflow-hidden">
|
||||
{!isSidebarVisible && (
|
||||
<Button
|
||||
variant="ghost"
|
||||
size="sm"
|
||||
onClick={() => setIsSidebarVisible(true)}
|
||||
>
|
||||
<Menu className="h-4 w-4" />
|
||||
</Button>
|
||||
)}
|
||||
<div className="flex min-w-0 flex-1">
|
||||
{chat ? (
|
||||
<div className="text-sm font-semibold truncate">
|
||||
{chat.name}
|
||||
</div>
|
||||
) : (
|
||||
<Skeleton className="h-5 w-32" />
|
||||
)}
|
||||
{/* Main Content Area */}
|
||||
<div className="flex-1 flex flex-col">
|
||||
<header className="pt-safe bg-gradient-to-r from-primary/10 via-accent/5 to-primary/10 backdrop-blur">
|
||||
<div className="h-12 border-b px-4 py-3 flex items-center justify-between">
|
||||
<div className="flex items-center space-x-2 overflow-hidden">
|
||||
{!isSidebarVisible && (
|
||||
<Button
|
||||
variant="ghost"
|
||||
size="sm"
|
||||
onClick={() => setIsSidebarVisible(true)}
|
||||
>
|
||||
<Menu className="h-4 w-4" />
|
||||
</Button>
|
||||
)}
|
||||
<div className="flex min-w-0 flex-1">
|
||||
{chat ? (
|
||||
<div className="text-sm font-semibold truncate">
|
||||
{chat.name}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div className="flex items-center gap-2">
|
||||
{chat ? (
|
||||
<ActionsMenu
|
||||
projectId={chat.id}
|
||||
projectName={chat.name}
|
||||
onNewChat={handleNewChat}
|
||||
isLoading={isAILoading}
|
||||
isBuildLoading={false}
|
||||
onFirstInteraction={handleFirstInteraction}
|
||||
isChat={true}
|
||||
onChatDeleted={handleChatDeleted}
|
||||
/>
|
||||
) : (
|
||||
<Skeleton className="h-8 w-8 rounded" />
|
||||
)}
|
||||
</div>
|
||||
) : (
|
||||
<Skeleton className="h-5 w-32" />
|
||||
)}
|
||||
</div>
|
||||
</header>
|
||||
</div>
|
||||
|
||||
<div className="flex-1 overflow-hidden">
|
||||
{chat && (
|
||||
<ChatPane
|
||||
ref={chatPaneRef}
|
||||
<div className="flex items-center gap-2">
|
||||
{chat ? (
|
||||
<ActionsMenu
|
||||
projectId={chat.id}
|
||||
projectName={chat.name}
|
||||
onNewChat={handleNewChat}
|
||||
onFirstInteraction={handleFirstInteraction}
|
||||
onLoadingChange={handleAILoadingChange}
|
||||
isLoading={isAILoading}
|
||||
isBuildLoading={false}
|
||||
onFirstInteraction={handleFirstInteraction}
|
||||
isChat={true}
|
||||
onChatDeleted={handleChatDeleted}
|
||||
/>
|
||||
) : (
|
||||
<Skeleton className="h-8 w-8 rounded" />
|
||||
)}
|
||||
</div>
|
||||
</div>
|
||||
</ResizablePanel>
|
||||
</ResizablePanelGroup>
|
||||
</header>
|
||||
|
||||
<div className="flex-1 overflow-hidden">
|
||||
{chat && (
|
||||
<ChatPane
|
||||
ref={chatPaneRef}
|
||||
projectId={chat.id}
|
||||
onNewChat={handleNewChat}
|
||||
onFirstInteraction={handleFirstInteraction}
|
||||
onLoadingChange={handleAILoadingChange}
|
||||
isLoading={isAILoading}
|
||||
isChat={true}
|
||||
/>
|
||||
)}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
Reference in new issue
Block a user