mirror of
https://github.com/chriswritescode-dev/opencode-manager.git
synced 2026-12-06 12:54:20 +01:00
fix: centralize iOS safe area and refactor list components (#47)
* fix: add iOS safe-area-inset-top support for fullscreen overlays - Add pt-safe CSS utility class for safe-area-inset-top - Create FullscreenSheet component with built-in safe-area support - Add fullscreen prop to DialogContent for fullscreen dialogs - Update FileBrowserSheet to use FullscreenSheet - Update MobileFilePreviewModal to use FullscreenSheet - Add pt-safe to SettingsDialog mobile view Fixes status bar overlap on iOS devices with notch/Dynamic Island * fix: add pt-safe to main page headers - Header.tsx (main repos page) - SessionDetailHeader.tsx (session page) * docs: add TDD refactoring plan for iOS safe area * remove plan file from repo * refactor: centralize iOS safe area handling with PageHeader component - Add PageHeader component with pt-safe, sticky, z-10, border-b styling - Add TDD test infrastructure (vitest config, testing-library, jsdom) - Refactor Header, SessionDetailHeader, RepoDetailHeader, Workspace to use PageHeader - Fix missing pt-safe on RepoDetailHeader and Workspace pages - All header safe area styling now has single fix point * fix: add pt-safe to remaining fullscreen dialogs and sheets - GitChangesSheet, FilePreviewDialog: add fullscreen prop - ModelSelectDialog, RepoMcpDialog: add pt-safe class - EditSessionTitleDialog: add pt-safe on mobile * fix: use mobile-first positioning for large dialogs Dialogs need top-0 positioning on mobile for pt-safe to work. Centered dialogs don't benefit from safe area padding. * fix: add mobileFullscreen prop to DialogContent - Fullscreen on mobile with pt-safe, centered on desktop - Simplifies large dialog styling * fix: use inline styles for iOS safe area to fix CSS cascade issues - Convert pt-safe/pb-safe to @utility directives with iOS 11 fallback - Use inline styles on DialogContent for reliable safe-area padding - Position close button with calc(env(safe-area-inset-top) + 1rem) - Add 10 tests for DialogContent safe-area behavior * refactor: extract ListToolbar and Header components for reuse - Add ListToolbar component for search/select all/delete UI - Add Header compound component (Header.Root, Header.Title, etc.) - Update SessionList and RepoList to use ListToolbar - Mobile delete: deletes selected or all if none selected - Cancel delete now clears selection - Remove unused layout components --------- Co-authored-by: Chris Scott <99081550+chriswritescode-dev@users.noreply.github.com>
This commit is contained in:
1 parent
72bb20a4fa
commit
cd9a552bf8
34 files changed
+1627
-986
No files matched your search
@@ -2,10 +2,8 @@ import { useState } from "react";
|
||||
import { useQuery, useMutation, useQueryClient } from "@tanstack/react-query";
|
||||
import { listRepos, deleteRepo } from "@/api/repos";
|
||||
import { DeleteDialog } from "@/components/ui/delete-dialog";
|
||||
import { Input } from "@/components/ui/input";
|
||||
import { Button } from "@/components/ui/button";
|
||||
import { DropdownMenu, DropdownMenuContent, DropdownMenuItem, DropdownMenuTrigger } from "@/components/ui/dropdown-menu";
|
||||
import { Loader2, GitBranch, Search, Trash2, MoreVertical } from "lucide-react";
|
||||
import { ListToolbar } from "@/components/ui/list-toolbar";
|
||||
import { Loader2, GitBranch, Search } from "lucide-react";
|
||||
import { RepoCard } from "./RepoCard";
|
||||
|
||||
export function RepoList() {
|
||||
@@ -127,73 +125,34 @@ export function RepoList() {
|
||||
}
|
||||
};
|
||||
|
||||
const handleDeleteAll = () => {
|
||||
if (filteredRepos.length === 0) return;
|
||||
setSelectedRepos(new Set(filteredRepos.map((r) => r.id)));
|
||||
setDeleteDialogOpen(true);
|
||||
};
|
||||
|
||||
|
||||
return (
|
||||
<>
|
||||
<div className="px-0 py-2 md:p-4">
|
||||
<div className="flex items-center gap-3 mb-4 md:mb-6 px-2 md:px-0">
|
||||
<div className="relative flex-1">
|
||||
<Search className="absolute left-3 top-1/2 -translate-y-1/2 w-4 h-4 text-zinc-400" />
|
||||
<Input
|
||||
placeholder="Search"
|
||||
value={searchQuery}
|
||||
onChange={(e) => setSearchQuery(e.target.value)}
|
||||
className="pl-10"
|
||||
/>
|
||||
</div>
|
||||
{filteredRepos.length > 0 && (
|
||||
<Button
|
||||
onClick={handleSelectAll}
|
||||
variant={selectedRepos.size > 0 ? "default" : "outline"}
|
||||
className="whitespace-nowrap hidden md:flex"
|
||||
>
|
||||
{filteredRepos.every((repo) => selectedRepos.has(repo.id))
|
||||
? "Deselect All"
|
||||
: "Select All"}
|
||||
</Button>
|
||||
)}
|
||||
<Button
|
||||
onClick={handleBatchDelete}
|
||||
variant="destructive"
|
||||
disabled={selectedRepos.size === 0}
|
||||
className="hidden md:flex whitespace-nowrap"
|
||||
>
|
||||
<Trash2 className="w-4 h-4 mr-2" />
|
||||
Delete ({selectedRepos.size})
|
||||
</Button>
|
||||
<DropdownMenu>
|
||||
<DropdownMenuTrigger asChild>
|
||||
<Button
|
||||
variant="outline"
|
||||
size="icon"
|
||||
className="md:hidden"
|
||||
disabled={filteredRepos.length === 0}
|
||||
>
|
||||
<MoreVertical className="w-4 h-4" />
|
||||
</Button>
|
||||
</DropdownMenuTrigger>
|
||||
<DropdownMenuContent align="end">
|
||||
{filteredRepos.length > 0 && (
|
||||
<DropdownMenuItem onClick={handleSelectAll}>
|
||||
{filteredRepos.every((repo) => selectedRepos.has(repo.id))
|
||||
? "Deselect All"
|
||||
: "Select All"}
|
||||
</DropdownMenuItem>
|
||||
)}
|
||||
<DropdownMenuItem
|
||||
onClick={handleBatchDelete}
|
||||
disabled={selectedRepos.size === 0}
|
||||
className="text-destructive focus:text-destructive"
|
||||
>
|
||||
<Trash2 className="w-4 h-4 mr-2" />
|
||||
Delete ({selectedRepos.size})
|
||||
</DropdownMenuItem>
|
||||
</DropdownMenuContent>
|
||||
</DropdownMenu>
|
||||
<div className="px-0 md:p-4 h-full flex flex-col">
|
||||
<div className="mb-4 md:mb-6 px-2 md:px-0">
|
||||
<ListToolbar
|
||||
searchQuery={searchQuery}
|
||||
onSearchChange={setSearchQuery}
|
||||
selectedCount={selectedRepos.size}
|
||||
totalCount={filteredRepos.length}
|
||||
allSelected={
|
||||
filteredRepos.length > 0 &&
|
||||
filteredRepos.every((repo) => selectedRepos.has(repo.id))
|
||||
}
|
||||
onToggleSelectAll={handleSelectAll}
|
||||
onDelete={handleBatchDelete}
|
||||
onDeleteAll={handleDeleteAll}
|
||||
/>
|
||||
</div>
|
||||
|
||||
<div className="mx-2 md:mx-0">
|
||||
<div className="h-[calc(100dvh-140px)] md:h-[calc(100vh-160px)] overflow-y-auto py-2 md:py-0">
|
||||
<div className="mx-2 md:mx-0 flex-1 min-h-0">
|
||||
<div className="h-full overflow-y-auto py-2 md:py-0">
|
||||
{filteredRepos.length === 0 ? (
|
||||
<div className="text-center p-12">
|
||||
<Search className="w-12 h-12 mx-auto mb-4 text-zinc-600" />
|
||||
@@ -237,6 +196,7 @@ export function RepoList() {
|
||||
onCancel={() => {
|
||||
setDeleteDialogOpen(false);
|
||||
setRepoToDelete(null);
|
||||
setSelectedRepos(new Set());
|
||||
}}
|
||||
title={
|
||||
selectedRepos.size > 0
|
||||
|
||||
@@ -1,9 +1,8 @@
|
||||
import { useState, useEffect, useCallback, useRef } from 'react'
|
||||
import { Dialog, DialogContent, DialogHeader, DialogTitle } from '@/components/ui/dialog'
|
||||
import { useState, useEffect, useCallback } from 'react'
|
||||
import { Dialog, DialogContent, DialogHeader, DialogTitle, DialogDescription } from '@/components/ui/dialog'
|
||||
import { Switch } from '@/components/ui/switch'
|
||||
import { Badge } from '@/components/ui/badge'
|
||||
import { Input } from '@/components/ui/input'
|
||||
import { Loader2, Plug, XCircle, AlertCircle, Search } from 'lucide-react'
|
||||
import { Loader2, XCircle, AlertCircle, Plug } from 'lucide-react'
|
||||
import { mcpApi, type McpStatus } from '@/api/mcp'
|
||||
import { useMutation } from '@tanstack/react-query'
|
||||
import { showToast } from '@/lib/toast'
|
||||
@@ -26,71 +25,12 @@ interface RepoMcpDialogProps {
|
||||
directory: string | undefined
|
||||
}
|
||||
|
||||
function getServerDisplayName(serverId: string): string {
|
||||
const name = serverId.replace(/[-_]/g, ' ')
|
||||
return name.charAt(0).toUpperCase() + name.slice(1)
|
||||
}
|
||||
|
||||
function getServerDescription(serverConfig: McpServerConfig): string {
|
||||
if (serverConfig.type === 'local' && serverConfig.command) {
|
||||
const command = serverConfig.command.join(' ')
|
||||
if (command.includes('filesystem')) return 'File system access'
|
||||
if (command.includes('git')) return 'Git repository operations'
|
||||
if (command.includes('sqlite')) return 'SQLite database access'
|
||||
if (command.includes('postgres')) return 'PostgreSQL database access'
|
||||
if (command.includes('brave-search')) return 'Web search via Brave'
|
||||
if (command.includes('github')) return 'GitHub repository access'
|
||||
if (command.includes('slack')) return 'Slack integration'
|
||||
if (command.includes('puppeteer')) return 'Web automation'
|
||||
if (command.includes('fetch')) return 'HTTP requests'
|
||||
if (command.includes('memory')) return 'Persistent memory'
|
||||
return `Local: ${command}`
|
||||
} else if (serverConfig.type === 'remote' && serverConfig.url) {
|
||||
return `${serverConfig.url}`
|
||||
}
|
||||
return 'MCP server'
|
||||
}
|
||||
|
||||
function getStatusBadge(status?: McpStatus) {
|
||||
if (!status) return null
|
||||
|
||||
switch (status.status) {
|
||||
case 'connected':
|
||||
return <Badge variant="default" className="text-xs bg-green-600">Connected</Badge>
|
||||
case 'disabled':
|
||||
return <Badge className="text-xs bg-gray-700 text-gray-300 border-gray-600 dark:bg-gray-700 dark:text-gray-300 dark:border-gray-600">Disabled</Badge>
|
||||
case 'failed':
|
||||
return (
|
||||
<Badge variant="destructive" className="text-xs flex items-center gap-1">
|
||||
<AlertCircle className="h-3 w-3" />
|
||||
Failed
|
||||
</Badge>
|
||||
)
|
||||
case 'needs_auth':
|
||||
return (
|
||||
<Badge variant="outline" className="text-xs border-yellow-500 text-yellow-600">
|
||||
Needs Auth
|
||||
</Badge>
|
||||
)
|
||||
default:
|
||||
return <Badge variant="outline" className="text-xs">Unknown</Badge>
|
||||
}
|
||||
}
|
||||
|
||||
export function RepoMcpDialog({ open, onOpenChange, config, directory }: RepoMcpDialogProps) {
|
||||
const [localStatus, setLocalStatus] = useState<Record<string, McpStatus>>({})
|
||||
const [isLoadingStatus, setIsLoadingStatus] = useState(false)
|
||||
const [searchQuery, setSearchQuery] = useState('')
|
||||
const searchInputRef = useRef<HTMLInputElement>(null)
|
||||
|
||||
const mcpServers = config?.content?.mcp as Record<string, McpServerConfig> | undefined || {}
|
||||
const serverIds = Object.keys(mcpServers)
|
||||
const filteredServerIds = serverIds.filter((serverId) => {
|
||||
const displayName = getServerDisplayName(serverId).toLowerCase()
|
||||
const description = getServerDescription(mcpServers[serverId]).toLowerCase()
|
||||
const query = searchQuery.toLowerCase()
|
||||
return displayName.includes(query) || description.includes(query)
|
||||
})
|
||||
|
||||
const fetchStatus = useCallback(async () => {
|
||||
if (!directory || serverIds.length === 0) return
|
||||
@@ -99,8 +39,6 @@ export function RepoMcpDialog({ open, onOpenChange, config, directory }: RepoMcp
|
||||
try {
|
||||
const status = await mcpApi.getStatusFor(directory)
|
||||
setLocalStatus(status)
|
||||
} catch (error) {
|
||||
console.error('Failed to fetch MCP status:', error)
|
||||
} finally {
|
||||
setIsLoadingStatus(false)
|
||||
}
|
||||
@@ -134,66 +72,87 @@ export function RepoMcpDialog({ open, onOpenChange, config, directory }: RepoMcp
|
||||
useEffect(() => {
|
||||
if (open && directory) {
|
||||
fetchStatus()
|
||||
searchInputRef.current?.focus()
|
||||
}
|
||||
if (!open) {
|
||||
setSearchQuery('')
|
||||
}, [open, directory, fetchStatus])
|
||||
|
||||
const getDisplayName = (serverId: string): string => {
|
||||
const name = serverId.replace(/[-_]/g, ' ')
|
||||
return name.charAt(0).toUpperCase() + name.slice(1)
|
||||
}
|
||||
|
||||
const getDescription = (serverConfig: McpServerConfig): string => {
|
||||
if (serverConfig.type === 'local' && serverConfig.command) {
|
||||
const command = serverConfig.command.join(' ')
|
||||
if (command.includes('filesystem')) return 'File system access'
|
||||
if (command.includes('git')) return 'Git repository operations'
|
||||
if (command.includes('sqlite')) return 'SQLite database access'
|
||||
if (command.includes('postgres')) return 'PostgreSQL database access'
|
||||
if (command.includes('brave-search')) return 'Web search via Brave'
|
||||
if (command.includes('github')) return 'GitHub repository access'
|
||||
if (command.includes('slack')) return 'Slack integration'
|
||||
if (command.includes('puppeteer')) return 'Web automation'
|
||||
if (command.includes('fetch')) return 'HTTP requests'
|
||||
if (command.includes('memory')) return 'Persistent memory'
|
||||
return `Local: ${command}`
|
||||
} else if (serverConfig.type === 'remote' && serverConfig.url) {
|
||||
return serverConfig.url
|
||||
}
|
||||
}, [open, directory, serverIds.length, fetchStatus])
|
||||
return 'MCP server'
|
||||
}
|
||||
|
||||
const getStatusBadge = (status?: McpStatus) => {
|
||||
if (!status) return null
|
||||
|
||||
switch (status.status) {
|
||||
case 'connected':
|
||||
return <Badge variant="default" className="text-xs bg-green-600">Connected</Badge>
|
||||
case 'disabled':
|
||||
return <Badge className="text-xs bg-gray-700 text-gray-300 border-gray-600 dark:bg-gray-700 dark:text-gray-300 dark:border-gray-600">Disabled</Badge>
|
||||
case 'failed':
|
||||
return (
|
||||
<Badge variant="destructive" className="text-xs flex items-center gap-1">
|
||||
<AlertCircle className="h-3 w-3" />
|
||||
Failed
|
||||
</Badge>
|
||||
)
|
||||
case 'needs_auth':
|
||||
return (
|
||||
<Badge variant="outline" className="text-xs border-yellow-500 text-yellow-600">
|
||||
Needs Auth
|
||||
</Badge>
|
||||
)
|
||||
default:
|
||||
return <Badge variant="outline" className="text-xs">Unknown</Badge>
|
||||
}
|
||||
}
|
||||
|
||||
if (!directory) return null
|
||||
|
||||
return (
|
||||
<Dialog open={open} onOpenChange={onOpenChange}>
|
||||
<DialogContent className="max-w-[95%] sm:max-w-[500px] p-0 gap-0 h-[90vh] sm:h-[80vh] flex flex-col">
|
||||
<DialogHeader className="px-4 sm:px-6 pt-4 sm:pt-6 pb-2 sm:pb-3 shrink-0 border-b border-border">
|
||||
<div className="flex items-center gap-2">
|
||||
<Plug className="w-4 h-4 text-muted-foreground" />
|
||||
<DialogTitle className="text-base sm:text-lg">MCP for This Location</DialogTitle>
|
||||
</div>
|
||||
<p className="text-xs sm:text-sm text-muted-foreground mt-1">
|
||||
<DialogContent mobileFullscreen className="sm:max-w-[400px] sm:max-h-[80vh] flex flex-col gap-0 pb-safe">
|
||||
<DialogHeader className="px-4 sm:px-6 pt-4 sm:pt-6 pb-2 sm:pb-3 shrink-0 ">
|
||||
<DialogTitle>MCP for This Location</DialogTitle>
|
||||
<DialogDescription>
|
||||
Toggle MCP servers for this repository
|
||||
</p>
|
||||
</DialogDescription>
|
||||
</DialogHeader>
|
||||
|
||||
<div className="px-4 sm:px-6 py-3 border-b border-border shrink-0">
|
||||
<div className="relative">
|
||||
<Search className="absolute left-3 top-1/2 transform -translate-y-1/2 w-4 h-4 text-muted-foreground" />
|
||||
<Input
|
||||
ref={searchInputRef}
|
||||
placeholder="Search MCP servers..."
|
||||
value={searchQuery}
|
||||
onChange={(e) => setSearchQuery(e.target.value)}
|
||||
className="pl-9"
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
|
||||
<div className="px-4 sm:px-6 py-3 sm:py-4 flex-1 overflow-y-auto min-h-0">
|
||||
{serverIds.length === 0 ? (
|
||||
<div className="text-center py-6 sm:py-8">
|
||||
<Plug className="w-10 h-10 mx-auto text-muted-foreground mb-3 opacity-50" />
|
||||
<p className="text-sm text-muted-foreground">
|
||||
No MCP servers configured globally
|
||||
</p>
|
||||
<p className="text-xs text-muted-foreground mt-1">
|
||||
Add them in Settings first
|
||||
</p>
|
||||
<div className="text-center py-6 text-muted-foreground">
|
||||
<Plug className="w-10 h-10 mx-auto mb-3 opacity-50" />
|
||||
<p className="text-sm">No MCP servers configured globally</p>
|
||||
<p className="text-xs mt-1">Add them in Settings first</p>
|
||||
</div>
|
||||
) : filteredServerIds.length === 0 ? (
|
||||
<div className="text-center py-6 sm:py-8">
|
||||
<Search className="w-10 h-10 mx-auto text-muted-foreground mb-3 opacity-50" />
|
||||
<p className="text-sm text-muted-foreground">
|
||||
No MCP servers match "{searchQuery}"
|
||||
</p>
|
||||
</div>
|
||||
) : isLoadingStatus ? (
|
||||
) : isLoadingStatus ? (
|
||||
<div className="flex items-center justify-center py-8">
|
||||
<Loader2 className="w-6 h-6 animate-spin text-muted-foreground" />
|
||||
<Loader2 className="w-4 h-4 animate-spin text-blue-600 dark:text-blue-400" />
|
||||
<span className="ml-2 text-sm text-muted-foreground">Loading...</span>
|
||||
</div>
|
||||
) : (
|
||||
<div className="space-y-3">
|
||||
{filteredServerIds.map((serverId) => {
|
||||
{serverIds.map((serverId) => {
|
||||
const serverConfig = mcpServers[serverId]
|
||||
const status = localStatus[serverId]
|
||||
const isConnected = status?.status === 'connected'
|
||||
@@ -202,20 +161,20 @@ export function RepoMcpDialog({ open, onOpenChange, config, directory }: RepoMcp
|
||||
return (
|
||||
<div
|
||||
key={serverId}
|
||||
className="flex items-center justify-between gap-3 p-2 sm:p-3 rounded-lg border border-border bg-card"
|
||||
className="flex items-center justify-between gap-3 p-3 rounded-lg border border-border bg-card"
|
||||
>
|
||||
<div className="flex-1 min-w-0">
|
||||
<div className="flex items-center gap-2 mb-1">
|
||||
<p className="text-xs sm:text-sm font-medium truncate">
|
||||
{getServerDisplayName(serverId)}
|
||||
<p className="text-sm font-medium truncate">
|
||||
{getDisplayName(serverId)}
|
||||
</p>
|
||||
{getStatusBadge(status)}
|
||||
</div>
|
||||
<p className="text-[10px] sm:text-xs text-muted-foreground truncate">
|
||||
{getServerDescription(serverConfig)}
|
||||
<p className="text-xs text-muted-foreground truncate">
|
||||
{getDescription(serverConfig)}
|
||||
</p>
|
||||
{failed && status.status === 'failed' && (
|
||||
<div className="flex items-center gap-1 mt-1 text-[10px] text-red-500">
|
||||
<div className="flex items-center gap-1 mt-1 text-xs text-red-500">
|
||||
<XCircle className="w-3 h-3 flex-shrink-0" />
|
||||
<span className="truncate">{status.error}</span>
|
||||
</div>
|
||||
|
||||
Reference in new issue
Block a user