mirror of
https://gitlab.com/soapbox-pub/shakespeare.git
synced 2026-12-05 16:23:36 +00:00
move sidebar collapse button into the sidebar
This commit is contained in:
1 parent
69c38b489a
commit
b73bb3971e
3 files changed
+130
-8
No files matched your search
@@ -4,7 +4,7 @@ import { type Project } from '@/lib/ProjectsManager';
|
||||
import { useProjectsManager } from '@/hooks/useProjectsManager';
|
||||
import { ProjectSidebar } from '@/components/ProjectSidebar';
|
||||
import { Button } from '@/components/ui/button';
|
||||
import { Menu, Columns2 } from 'lucide-react';
|
||||
import { Menu } from 'lucide-react';
|
||||
import { useIsMobile } from '@/hooks/useIsMobile';
|
||||
|
||||
interface AppLayoutProps {
|
||||
@@ -129,6 +129,7 @@ export function AppLayout({
|
||||
selectedProject={selectedProject}
|
||||
onSelectProject={handleProjectSelect}
|
||||
className="h-screen sticky top-0"
|
||||
onToggleSidebar={() => setIsSidebarVisible(false)}
|
||||
/>
|
||||
</div>
|
||||
)}
|
||||
@@ -136,16 +137,16 @@ export function AppLayout({
|
||||
{/* Main Content Area */}
|
||||
<div className="flex-1 flex flex-col bg-background">
|
||||
<div className="min-h-screen bg-gradient-to-br from-primary/5 to-accent/5 relative">
|
||||
{/* Toggle Button - positioned absolutely in top-left corner */}
|
||||
{showSidebar && (
|
||||
{/* Show open button when sidebar is collapsed */}
|
||||
{showSidebar && !isSidebarVisible && (
|
||||
<Button
|
||||
variant="ghost"
|
||||
size="sm"
|
||||
onClick={() => setIsSidebarVisible(!isSidebarVisible)}
|
||||
onClick={() => setIsSidebarVisible(true)}
|
||||
className="absolute top-2 left-4 h-8 w-8 p-0 z-10 bg-transparent backdrop-blur-sm hover:bg-transparent text-foreground/70 hover:text-foreground"
|
||||
aria-label="Toggle sidebar"
|
||||
aria-label="Open sidebar"
|
||||
>
|
||||
{isSidebarVisible ? <Columns2 className="h-4 w-4" /> : <Menu className="h-4 w-4" />}
|
||||
<Menu className="h-4 w-4" />
|
||||
</Button>
|
||||
)}
|
||||
|
||||
|
||||
@@ -0,0 +1,105 @@
|
||||
import { render, screen, fireEvent } from '@testing-library/react';
|
||||
import { describe, it, expect, vi, beforeEach } from 'vitest';
|
||||
import { ProjectSidebar } from './ProjectSidebar';
|
||||
import { useProjects } from '@/hooks/useProjects';
|
||||
import { useLocalStorage } from '@/hooks/useLocalStorage';
|
||||
|
||||
// Mock the hooks
|
||||
vi.mock('@/hooks/useProjects');
|
||||
vi.mock('@/hooks/useLocalStorage');
|
||||
vi.mock('@/hooks/useProjectSessionStatus', () => ({
|
||||
useProjectSessionStatus: () => ({ hasRunningSessions: false })
|
||||
}));
|
||||
vi.mock('react-router-dom', () => ({
|
||||
useNavigate: () => vi.fn()
|
||||
}));
|
||||
vi.mock('@tanstack/react-query', () => ({
|
||||
useQueryClient: () => ({
|
||||
invalidateQueries: vi.fn()
|
||||
})
|
||||
}));
|
||||
|
||||
// Mock the LoginArea component
|
||||
vi.mock('@/components/auth/LoginArea', () => ({
|
||||
LoginArea: ({ className }: { className?: string }) => (
|
||||
<div data-testid="login-area" className={className}>Login Area</div>
|
||||
)
|
||||
}));
|
||||
|
||||
const mockUseProjects = vi.mocked(useProjects);
|
||||
const mockUseLocalStorage = vi.mocked(useLocalStorage);
|
||||
|
||||
describe('ProjectSidebar', () => {
|
||||
beforeEach(() => {
|
||||
mockUseProjects.mockReturnValue({
|
||||
data: [],
|
||||
isLoading: false,
|
||||
error: null
|
||||
} as unknown as ReturnType<typeof useProjects>);
|
||||
|
||||
mockUseLocalStorage.mockReturnValue([[], vi.fn()]);
|
||||
});
|
||||
|
||||
it('renders sidebar header with logo', () => {
|
||||
render(
|
||||
<ProjectSidebar
|
||||
selectedProject={null}
|
||||
onSelectProject={vi.fn()}
|
||||
/>
|
||||
);
|
||||
|
||||
expect(screen.getByText('🎭')).toBeInTheDocument();
|
||||
expect(screen.getByText('Shakespeare')).toBeInTheDocument();
|
||||
});
|
||||
|
||||
it('shows collapse button when onToggleSidebar is provided', () => {
|
||||
const mockToggle = vi.fn();
|
||||
|
||||
render(
|
||||
<ProjectSidebar
|
||||
selectedProject={null}
|
||||
onSelectProject={vi.fn()}
|
||||
onToggleSidebar={mockToggle}
|
||||
/>
|
||||
);
|
||||
|
||||
const collapseButton = screen.getByLabelText('Collapse sidebar');
|
||||
expect(collapseButton).toBeInTheDocument();
|
||||
|
||||
fireEvent.click(collapseButton);
|
||||
expect(mockToggle).toHaveBeenCalledTimes(1);
|
||||
});
|
||||
|
||||
it('does not show collapse button when onToggleSidebar is not provided', () => {
|
||||
render(
|
||||
<ProjectSidebar
|
||||
selectedProject={null}
|
||||
onSelectProject={vi.fn()}
|
||||
/>
|
||||
);
|
||||
|
||||
expect(screen.queryByLabelText('Collapse sidebar')).not.toBeInTheDocument();
|
||||
});
|
||||
|
||||
it('renders login area at the bottom', () => {
|
||||
render(
|
||||
<ProjectSidebar
|
||||
selectedProject={null}
|
||||
onSelectProject={vi.fn()}
|
||||
/>
|
||||
);
|
||||
|
||||
expect(screen.getByTestId('login-area')).toBeInTheDocument();
|
||||
});
|
||||
|
||||
it('shows new project button', () => {
|
||||
render(
|
||||
<ProjectSidebar
|
||||
selectedProject={null}
|
||||
onSelectProject={vi.fn()}
|
||||
/>
|
||||
);
|
||||
|
||||
expect(screen.getByText('New Project')).toBeInTheDocument();
|
||||
});
|
||||
});
|
||||
@@ -1,6 +1,7 @@
|
||||
import React, { useEffect } from 'react';
|
||||
import { useNavigate } from 'react-router-dom';
|
||||
import { Plus, Folder, GitBranch, Loader2, ChevronDown, Star } from 'lucide-react';
|
||||
import { Plus, Folder, GitBranch, Loader2, ChevronDown, Star, Columns2 } from 'lucide-react';
|
||||
import { Button } from '@/components/ui/button';
|
||||
import { Skeleton } from '@/components/ui/skeleton';
|
||||
import { DropdownMenu, DropdownMenuContent, DropdownMenuItem, DropdownMenuTrigger } from '@/components/ui/dropdown-menu';
|
||||
import { LoginArea } from '@/components/auth/LoginArea';
|
||||
@@ -75,12 +76,14 @@ interface ProjectSidebarProps {
|
||||
selectedProject: Project | null;
|
||||
onSelectProject: (project: Project | null) => void;
|
||||
className?: string;
|
||||
onToggleSidebar?: () => void;
|
||||
}
|
||||
|
||||
export function ProjectSidebar({
|
||||
selectedProject,
|
||||
onSelectProject,
|
||||
className
|
||||
className,
|
||||
onToggleSidebar
|
||||
}: ProjectSidebarProps) {
|
||||
const queryClient = useQueryClient();
|
||||
const { data: projects = [], isLoading, error } = useProjects();
|
||||
@@ -115,6 +118,19 @@ export function ProjectSidebar({
|
||||
Shakespeare
|
||||
</h1>
|
||||
</button>
|
||||
{onToggleSidebar && (
|
||||
<div className="flex items-center gap-1">
|
||||
<Button
|
||||
variant="ghost"
|
||||
size="sm"
|
||||
className="h-8 w-8 p-0 hover:bg-primary/10 -mr-2"
|
||||
onClick={onToggleSidebar}
|
||||
aria-label="Collapse sidebar"
|
||||
>
|
||||
<Columns2 className="h-4 w-4 text-primary/60 hover:text-primary" />
|
||||
</Button>
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
|
||||
Reference in new issue
Block a user