mirror of
https://github.com/chriswritescode-dev/opencode-manager.git
synced 2026-12-05 20:34:18 +01:00
* feat: show variant label on model picker and add folder upload for agents/commands
- Replace three-dot variant menu trigger with selected variant label
- Add POST /api/settings/opencode-directory-files/install endpoint
- Upload agents/commands markdown folders into .config/opencode/{agents,commands}/
- Reload OpenCode server after upload so files are picked up
* fix: revalidate branch/git caches when mobile sheet opens and on vcs.branch.updated SSE
- add shared invalidateRepoGitCaches() helper for consistent invalidation
- revalidate repo list when mobile repo quick-switch sheet opens
- revalidate current repo when mobile More drawer opens
- revalidate repo/git caches when Source Control dialog opens
- handle vcs.branch.updated SSE event with optimistic cache update
- use helper in branch create/switch mutations in useGit and BranchesTab
* style: make variant selector look more like a button with chevron and compact sizing
* refactor: consolidate settings editors, add folder upload support, and clean up unused code
* refactor: consolidate settings editors, add folder upload support, and clean up unused code
* feat: add opencode-directory-files listing service and consolidate settings editors
* fix: distinguish scroll from tap in suggestion popups on touch devices
* refactor: consolidate settings editors and add DirectoryFilesList component
* refactor: target repo status cache updates only to affected batch entries
* refactor: streamline settings, git hooks, and query invalidation logic
113 lines
3.4 KiB
TypeScript
113 lines
3.4 KiB
TypeScript
import { useRef, useState } from 'react'
|
|
import { Upload, FileUp, FolderUp, ChevronDown } from 'lucide-react'
|
|
import { useQueryClient } from '@tanstack/react-query'
|
|
import { toast } from 'sonner'
|
|
import { Button } from '@/components/ui/button'
|
|
import {
|
|
DropdownMenu,
|
|
DropdownMenuContent,
|
|
DropdownMenuItem,
|
|
DropdownMenuTrigger,
|
|
} from '@/components/ui/dropdown-menu'
|
|
import { settingsApi } from '@/api/settings'
|
|
import { invalidateConfigCaches } from '@/lib/queryInvalidation'
|
|
|
|
const KIND_NOUN: Record<'agents' | 'commands', string> = {
|
|
agents: 'agent',
|
|
commands: 'command',
|
|
}
|
|
|
|
const DIRECTORY_INPUT_PROPS = {
|
|
webkitdirectory: '',
|
|
directory: '',
|
|
mozdirectory: '',
|
|
} as React.InputHTMLAttributes<HTMLInputElement>
|
|
|
|
function isMarkdownFile(file: File): boolean {
|
|
return (file.webkitRelativePath || file.name).toLowerCase().endsWith('.md')
|
|
}
|
|
|
|
interface UploadFolderButtonProps {
|
|
kind: 'agents' | 'commands'
|
|
}
|
|
|
|
export function UploadFolderButton({ kind }: UploadFolderButtonProps) {
|
|
const queryClient = useQueryClient()
|
|
const [isUploading, setIsUploading] = useState(false)
|
|
const fileInputRef = useRef<HTMLInputElement>(null)
|
|
const folderInputRef = useRef<HTMLInputElement>(null)
|
|
const noun = KIND_NOUN[kind]
|
|
|
|
const openPicker = (inputRef: React.RefObject<HTMLInputElement | null>) => {
|
|
requestAnimationFrame(() => inputRef.current?.click())
|
|
}
|
|
|
|
const handleChange = async (event: React.ChangeEvent<HTMLInputElement>) => {
|
|
const selectedFiles = Array.from(event.target.files ?? [])
|
|
event.target.value = ''
|
|
if (selectedFiles.length === 0) {
|
|
return
|
|
}
|
|
|
|
const files = selectedFiles.filter(isMarkdownFile)
|
|
if (files.length === 0) {
|
|
toast.error(`No markdown ${kind} files found`)
|
|
return
|
|
}
|
|
|
|
try {
|
|
setIsUploading(true)
|
|
const result = await settingsApi.installOpenCodeDirectoryFiles({ kind, files })
|
|
invalidateConfigCaches(queryClient)
|
|
toast.success(`Uploaded ${result.filesInstalled.length} ${noun} file${result.filesInstalled.length === 1 ? '' : 's'}`)
|
|
} catch (error) {
|
|
toast.error(error instanceof Error ? error.message : `Failed to upload ${kind}`)
|
|
} finally {
|
|
setIsUploading(false)
|
|
}
|
|
}
|
|
|
|
return (
|
|
<>
|
|
<DropdownMenu>
|
|
<DropdownMenuTrigger asChild>
|
|
<Button size="sm" variant="outline" disabled={isUploading}>
|
|
<Upload className="h-4 w-4 mr-1" />
|
|
{isUploading ? 'Uploading...' : 'Upload'}
|
|
<ChevronDown className="h-4 w-4 ml-1" />
|
|
</Button>
|
|
</DropdownMenuTrigger>
|
|
<DropdownMenuContent align="end">
|
|
<DropdownMenuItem onSelect={() => openPicker(fileInputRef)}>
|
|
<FileUp className="h-4 w-4 mr-2" />
|
|
Upload File
|
|
</DropdownMenuItem>
|
|
<DropdownMenuItem onSelect={() => openPicker(folderInputRef)}>
|
|
<FolderUp className="h-4 w-4 mr-2" />
|
|
Upload Folder
|
|
</DropdownMenuItem>
|
|
</DropdownMenuContent>
|
|
</DropdownMenu>
|
|
<input
|
|
ref={fileInputRef}
|
|
type="file"
|
|
accept=".md,text/markdown"
|
|
className="sr-only"
|
|
multiple
|
|
disabled={isUploading}
|
|
onChange={handleChange}
|
|
/>
|
|
<input
|
|
ref={folderInputRef}
|
|
type="file"
|
|
accept=".md,text/markdown"
|
|
className="sr-only"
|
|
multiple
|
|
disabled={isUploading}
|
|
{...DIRECTORY_INPUT_PROPS}
|
|
onChange={handleChange}
|
|
/>
|
|
</>
|
|
)
|
|
}
|