Files
opencode-manager/frontend/src/components/message/MentionSuggestions.tsx
T
Chris Scott 617962f2dd feat: directory files upload system, deferred restart model, cache invalidation consolidation, and misc improvements (#281)
* 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
2026-06-20 00:40:36 -04:00

97 lines
3.0 KiB
TypeScript

import { useEffect, useRef } from 'react'
import { Bot, FileText } from 'lucide-react'
import { useTouchTapSelect } from '@/hooks/useTouchTapSelect'
export interface MentionItem {
type: 'file' | 'agent'
value: string
label: string
description?: string
}
interface MentionSuggestionsProps {
isOpen: boolean
items: MentionItem[]
onSelect: (item: MentionItem) => void
onClose: () => void
selectedIndex?: number
}
export function MentionSuggestions({
isOpen,
items,
onSelect,
onClose,
selectedIndex = 0
}: MentionSuggestionsProps) {
const listRef = useRef<HTMLDivElement>(null)
const touchTapSelect = useTouchTapSelect(onSelect)
useEffect(() => {
if (!isOpen) return
const handleClickOutside = (e: MouseEvent) => {
if (listRef.current && !listRef.current.contains(e.target as Node)) {
onClose()
}
}
document.addEventListener('mousedown', handleClickOutside)
return () => document.removeEventListener('mousedown', handleClickOutside)
}, [isOpen, onClose])
useEffect(() => {
if (!isOpen || !listRef.current) return
const selectedItem = listRef.current.children[selectedIndex] as HTMLElement
if (selectedItem) {
selectedItem.scrollIntoView({ block: 'nearest' })
}
}, [selectedIndex, isOpen])
if (!isOpen || items.length === 0) return null
const getFilename = (path: string) => path.split('/').pop() || path
const getDirectory = (path: string) => {
const parts = path.split('/')
return parts.slice(0, -1).join('/') || '.'
}
return (
<div
ref={listRef}
className="absolute bottom-full left-0 right-0 mb-2 z-50 bg-background border border-border rounded-lg shadow-xl max-h-48 md:max-h-[40vh] lg:max-h-[50vh] overflow-y-auto"
>
{items.map((item, idx) => (
<button
key={`${item.type}-${item.value}`}
onMouseDown={(e) => e.preventDefault()}
onTouchStart={touchTapSelect.onTouchStart}
onTouchMove={touchTapSelect.onTouchMove}
onTouchEnd={(e) => touchTapSelect.onTouchEnd(e, item)}
onClick={() => touchTapSelect.onClick(item)}
className={`w-full px-3 py-2 text-left transition-colors flex items-start gap-2 ${
idx === selectedIndex
? 'bg-primary text-primary-foreground'
: 'hover:bg-muted text-foreground'
}`}
>
{item.type === 'agent' ? (
<Bot className="w-4 h-4 mt-0.5 flex-shrink-0" />
) : (
<FileText className="w-4 h-4 mt-0.5 flex-shrink-0" />
)}
<div className="flex-1 min-w-0">
<div className="font-mono text-sm font-medium truncate">
{item.type === 'file' ? getFilename(item.value) : item.label}
</div>
<div className="text-xs opacity-70 mt-0.5 truncate">
{item.type === 'file' ? getDirectory(item.value) : item.description || 'Agent'}
</div>
</div>
</button>
))}
</div>
)
}