feat(frontend): move the mobile add-repo action into the search row

The header ran out of room on narrow screens now that the server switcher is
always present. The Repo button is desktop-only and mobile gets a bordered
icon button beside the search input instead. The empty state carries its own
add button, since it renders no search row.
This commit is contained in:
Chris Scott committed 2026-10-22 09:20:24 -04:00
1 parent 80ef211a94
commit 739f4d3d5c
4 files changed
+107 -6

No files matched your search

+8 -2
View File
@@ -6,8 +6,9 @@ import { CSS } from "@dnd-kit/utilities"
import { listRepos, deleteRepo, updateRepoOrder, type DeleteBranchChoice } from "@/api/repos"
import { fetchReposGitStatus } from "@/api/git"
import { DeleteDialog } from "@/components/ui/delete-dialog"
import { Button } from "@/components/ui/button"
import { RadioOptionGroup, type RadioOption } from "@/components/ui/radio-option-group"
import { GitBranch, Search, GripVertical } from "lucide-react"
import { GitBranch, Search, GripVertical, Plus } from "lucide-react"
import type { Repo } from "@/api/types"
import type { GitStatusResponse } from "@/types/git"
import { RepoCard } from "./RepoCard"
@@ -135,7 +136,7 @@ function StaticRepoCard({
)
}
export function RepoList() {
export function RepoList({ onAddRepo }: { onAddRepo: () => void }) {
const queryClient = useQueryClient()
const isMobile = useMobile()
const { preferences, updateSettings } = useSettings()
@@ -341,6 +342,10 @@ export function RepoList() {
<p className="text-muted-foreground">
No repositories yet. Add one to get started.
</p>
<Button size="sm" className="mt-4" onClick={onAddRepo}>
<Plus className="w-4 h-4 mr-1" />
Add repository
</Button>
</div>
)
@@ -413,6 +418,7 @@ export function RepoList() {
hasClonedRepos={hasClonedRepos}
selectionMode={selectionMode}
onSelectionModeChange={handleSelectionModeChange}
onAddRepo={onAddRepo}
/>
<div className="mx-2 md:mx-0 flex-1 min-h-0">
@@ -0,0 +1,70 @@
import { beforeEach, describe, expect, it, vi } from 'vitest'
import { render, screen } from '@testing-library/react'
import userEvent from '@testing-library/user-event'
import { RepoListControls } from './RepoListControls'
const mocks = vi.hoisted(() => ({ mobile: { current: false } }))
vi.mock('@/hooks/useMobile', () => ({
isMobileViewport: () => mocks.mobile.current,
useMobile: () => mocks.mobile.current,
}))
function baseProps() {
return {
searchQuery: '',
onSearchChange: vi.fn(),
filterMode: 'recent' as const,
onFilterModeChange: vi.fn(),
sortMode: 'recent' as const,
onSortModeChange: vi.fn(),
filteredCount: 3,
attentionCount: 0,
selectedCount: 0,
allVisibleSelected: false,
onSelectAll: vi.fn(),
onClearSelection: vi.fn(),
onDelete: vi.fn(),
hasLocalRepos: false,
hasClonedRepos: false,
selectionMode: false,
onSelectionModeChange: vi.fn(),
onAddRepo: vi.fn(),
}
}
describe('RepoListControls', () => {
beforeEach(() => {
mocks.mobile.current = false
})
it('renders the add repository button after the search input on mobile', () => {
mocks.mobile.current = true
render(<RepoListControls {...baseProps()} />)
const search = screen.getByRole('textbox')
const addButton = screen.getByRole('button', { name: 'Add repository' })
expect(
search.compareDocumentPosition(addButton) & Node.DOCUMENT_POSITION_FOLLOWING,
).toBeTruthy()
})
it('calls onAddRepo once when the mobile button is clicked', async () => {
mocks.mobile.current = true
const props = baseProps()
const user = userEvent.setup()
render(<RepoListControls {...props} />)
await user.click(screen.getByRole('button', { name: 'Add repository' }))
expect(props.onAddRepo).toHaveBeenCalledTimes(1)
})
it('does not render the add repository button on desktop', () => {
render(<RepoListControls {...baseProps()} />)
expect(screen.queryByRole('button', { name: 'Add repository' })).not.toBeInTheDocument()
})
})
@@ -1,5 +1,5 @@
import { useState } from "react";
import { SlidersHorizontal, Trash2, X } from "lucide-react";
import { Plus, SlidersHorizontal, Trash2, X } from "lucide-react";
import { Button } from "@/components/ui/button";
import { RepoSearchInput } from "./RepoSearchInput";
import {
@@ -31,6 +31,7 @@ interface RepoListControlsProps {
hasClonedRepos: boolean;
selectionMode: boolean;
onSelectionModeChange: (enabled: boolean) => void;
onAddRepo: () => void;
}
const FILTER_OPTIONS: { value: RepoFilterMode; label: string }[] = [
@@ -65,6 +66,7 @@ export function RepoListControls({
hasClonedRepos,
selectionMode,
onSelectionModeChange,
onAddRepo,
}: RepoListControlsProps) {
const isMobile = useMobile();
const [showMenu, setShowMenu] = useState(false);
@@ -122,10 +124,29 @@ export function RepoListControls({
<div className="flex items-center gap-2">
<RepoSearchInput value={searchQuery} onValueChange={onSearchChange} />
{isMobile && (
<Button
variant="outline"
size="icon"
aria-label="Add repository"
title="Add repository"
className="h-9 w-9 shrink-0"
onClick={onAddRepo}
>
<Plus className="h-4 w-4" />
</Button>
)}
{isMobile ? (
<DropdownMenu open={showMenu} onOpenChange={setShowMenu}>
<DropdownMenuTrigger asChild>
<Button variant="outline" size="sm">
<Button
variant="outline"
size="icon"
aria-label="Filter and sort repositories"
title="Filter and sort repositories"
className="h-9 w-9 shrink-0"
>
<SlidersHorizontal className="w-4 h-4" />
</Button>
</DropdownMenuTrigger>
+6 -2
View File
@@ -62,7 +62,11 @@ export function Repos() {
All Schedules
</Button>
{isLocalServer ? (
<Button onClick={() => setAddRepoOpen(true)} size="sm">
<Button
onClick={() => setAddRepoOpen(true)}
size="sm"
className="hidden md:inline-flex"
>
<Plus className="w-4 h-4 mr-1" />
Repo
</Button>
@@ -73,7 +77,7 @@ export function Repos() {
</Header.Actions>
</Header>
<div className="container mx-auto flex-1 pt-2 px-2 min-h-0 overflow-auto pb-[calc(env(safe-area-inset-bottom)+60px)] sm:pb-0">
{isLocalServer ? <RepoList /> : <RemoteProjectList serverId={selectedServerId} />}
{isLocalServer ? <RepoList onAddRepo={() => setAddRepoOpen(true)} /> : <RemoteProjectList serverId={selectedServerId} />}
</div>
{isLocalServer ? (
<AddRepoDialog open={addRepoOpen} onOpenChange={setAddRepoOpen} />