Fix file path format and initialization issues
- Remove leading slash from file paths (use relative paths from workspace) - Server expects relative paths like 'file.md' not '/file.md' - Convert isInitialized from let to signal to persist across renders - Fix file picker not showing files on first open - Paths from find.files() are already relative to workspace
This commit is contained in:
@@ -22,6 +22,7 @@ const FilePicker: Component<FilePickerProps> = (props) => {
|
|||||||
const [selectedIndex, setSelectedIndex] = createSignal(0)
|
const [selectedIndex, setSelectedIndex] = createSignal(0)
|
||||||
const [loading, setLoading] = createSignal(false)
|
const [loading, setLoading] = createSignal(false)
|
||||||
const [cachedGitFiles, setCachedGitFiles] = createSignal<FileItem[]>([])
|
const [cachedGitFiles, setCachedGitFiles] = createSignal<FileItem[]>([])
|
||||||
|
const [isInitialized, setIsInitialized] = createSignal(false)
|
||||||
|
|
||||||
let containerRef: HTMLDivElement | undefined
|
let containerRef: HTMLDivElement | undefined
|
||||||
let gitFilesFetched = false
|
let gitFilesFetched = false
|
||||||
@@ -113,15 +114,14 @@ const FilePicker: Component<FilePickerProps> = (props) => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
let lastQuery = ""
|
let lastQuery = ""
|
||||||
let isInitialized = false
|
|
||||||
|
|
||||||
createEffect(() => {
|
createEffect(() => {
|
||||||
console.log(
|
console.log(
|
||||||
`[FilePicker] Effect triggered - open: ${props.open}, query: "${props.searchQuery}", gitFilesFetched: ${gitFilesFetched}, isInitialized: ${isInitialized}`,
|
`[FilePicker] Effect triggered - open: ${props.open}, query: "${props.searchQuery}", gitFilesFetched: ${gitFilesFetched}, isInitialized: ${isInitialized()}`,
|
||||||
)
|
)
|
||||||
|
|
||||||
if (props.open && !isInitialized) {
|
if (props.open && !isInitialized()) {
|
||||||
isInitialized = true
|
setIsInitialized(true)
|
||||||
console.log("[FilePicker] First open - fetching git files and initial files")
|
console.log("[FilePicker] First open - fetching git files and initial files")
|
||||||
fetchGitFiles()
|
fetchGitFiles()
|
||||||
fetchFiles(props.searchQuery)
|
fetchFiles(props.searchQuery)
|
||||||
|
|||||||
@@ -53,17 +53,16 @@ export function createFileAttachment(
|
|||||||
mime: string = "text/plain",
|
mime: string = "text/plain",
|
||||||
data?: Uint8Array,
|
data?: Uint8Array,
|
||||||
): Attachment {
|
): Attachment {
|
||||||
const absolutePath = path.startsWith("/") ? path : `/${path}`
|
|
||||||
return {
|
return {
|
||||||
id: crypto.randomUUID(),
|
id: crypto.randomUUID(),
|
||||||
type: "file",
|
type: "file",
|
||||||
display: `@${filename}`,
|
display: `@${filename}`,
|
||||||
url: `file://${absolutePath}`,
|
url: path,
|
||||||
filename,
|
filename,
|
||||||
mediaType: mime,
|
mediaType: mime,
|
||||||
source: {
|
source: {
|
||||||
type: "file",
|
type: "file",
|
||||||
path: absolutePath,
|
path: path,
|
||||||
mime,
|
mime,
|
||||||
data,
|
data,
|
||||||
},
|
},
|
||||||
|
|||||||
Reference in New Issue
Block a user