Allow folders in file picker and use them as search filters
- Remove directory filtering from file picker - When folder selected, insert folder path into input (not as attachment) - Folder path becomes search query to filter files in that folder - Files still create attachments as before - User can navigate folder structure using @ mentions
This commit is contained in:
@@ -48,14 +48,12 @@ const FilePicker: Component<FilePickerProps> = (props) => {
|
|||||||
console.log(`[FilePicker] Git files response received in ${elapsed}ms:`, gitResponse)
|
console.log(`[FilePicker] Git files response received in ${elapsed}ms:`, gitResponse)
|
||||||
|
|
||||||
if (gitResponse?.data && gitResponse.data.length > 0) {
|
if (gitResponse?.data && gitResponse.data.length > 0) {
|
||||||
const gitFiles: FileItem[] = gitResponse.data
|
const gitFiles: FileItem[] = gitResponse.data.map((file: any) => ({
|
||||||
.filter((file: any) => !file.path.endsWith("/"))
|
path: file.path,
|
||||||
.map((file: any) => ({
|
added: file.added,
|
||||||
path: file.path,
|
removed: file.removed,
|
||||||
added: file.added,
|
isGitFile: true,
|
||||||
removed: file.removed,
|
}))
|
||||||
isGitFile: true,
|
|
||||||
}))
|
|
||||||
console.log(`[FilePicker] Cached ${gitFiles.length} git files`)
|
console.log(`[FilePicker] Cached ${gitFiles.length} git files`)
|
||||||
setCachedGitFiles(gitFiles)
|
setCachedGitFiles(gitFiles)
|
||||||
} else {
|
} else {
|
||||||
@@ -93,23 +91,21 @@ const FilePicker: Component<FilePickerProps> = (props) => {
|
|||||||
console.log(`[FilePicker] Search response received in ${elapsed}ms:`, searchResponse)
|
console.log(`[FilePicker] Search response received in ${elapsed}ms:`, searchResponse)
|
||||||
|
|
||||||
searchFiles = (searchResponse?.data || [])
|
searchFiles = (searchResponse?.data || [])
|
||||||
.filter((path: string) => !path.endsWith("/"))
|
|
||||||
.filter((path: string) => !gitFiles.some((gf) => gf.path === path))
|
.filter((path: string) => !gitFiles.some((gf) => gf.path === path))
|
||||||
.map((path: string) => ({
|
.map((path: string) => ({
|
||||||
path,
|
path,
|
||||||
isGitFile: false,
|
isGitFile: false,
|
||||||
}))
|
}))
|
||||||
} else {
|
} else {
|
||||||
console.log(`[FilePicker] Empty query, fetching all files with wildcard`)
|
console.log(`[FilePicker] Empty query, fetching all files`)
|
||||||
const searchResponse = await props.instanceClient.find.files({
|
const searchResponse = await props.instanceClient.find.files({
|
||||||
query: { query: "." },
|
query: { query: "" },
|
||||||
})
|
})
|
||||||
const elapsed = Date.now() - startTime
|
const elapsed = Date.now() - startTime
|
||||||
|
|
||||||
console.log(`[FilePicker] All files response received in ${elapsed}ms:`, searchResponse)
|
console.log(`[FilePicker] All files response received in ${elapsed}ms:`, searchResponse)
|
||||||
|
|
||||||
searchFiles = (searchResponse?.data || [])
|
searchFiles = (searchResponse?.data || [])
|
||||||
.filter((path: string) => !path.endsWith("/"))
|
|
||||||
.filter((path: string) => !gitFiles.some((gf) => gf.path === path))
|
.filter((path: string) => !gitFiles.some((gf) => gf.path === path))
|
||||||
.map((path: string) => ({
|
.map((path: string) => ({
|
||||||
path,
|
path,
|
||||||
|
|||||||
@@ -317,8 +317,36 @@ export default function PromptInput(props: PromptInputProps) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function handleFileSelect(path: string) {
|
function handleFileSelect(path: string) {
|
||||||
|
const isFolder = path.endsWith("/")
|
||||||
const filename = path.split("/").pop() || path
|
const filename = path.split("/").pop() || path
|
||||||
|
|
||||||
|
if (isFolder) {
|
||||||
|
const currentPrompt = prompt()
|
||||||
|
const pos = atPosition()
|
||||||
|
const cursorPos = textareaRef?.selectionStart || 0
|
||||||
|
|
||||||
|
if (pos !== null) {
|
||||||
|
const before = currentPrompt.substring(0, pos + 1)
|
||||||
|
const after = currentPrompt.substring(cursorPos)
|
||||||
|
const folderPath = path.slice(0, -1)
|
||||||
|
const newPrompt = before + folderPath + after
|
||||||
|
setPrompt(newPrompt)
|
||||||
|
setFileSearchQuery(folderPath)
|
||||||
|
|
||||||
|
setTimeout(() => {
|
||||||
|
if (textareaRef) {
|
||||||
|
const newCursorPos = pos + 1 + folderPath.length
|
||||||
|
textareaRef.setSelectionRange(newCursorPos, newCursorPos)
|
||||||
|
textareaRef.style.height = "auto"
|
||||||
|
textareaRef.style.height = Math.min(textareaRef.scrollHeight, 200) + "px"
|
||||||
|
textareaRef.focus()
|
||||||
|
}
|
||||||
|
}, 0)
|
||||||
|
}
|
||||||
|
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
const existingAttachments = attachments()
|
const existingAttachments = attachments()
|
||||||
const alreadyAttached = existingAttachments.some((att) => att.source.type === "file" && att.source.path === path)
|
const alreadyAttached = existingAttachments.some((att) => att.source.type === "file" && att.source.path === path)
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user