feat: allow file drop on path breadcrumb

This commit is contained in:
2025-09-20 23:54:27 +00:00
parent 0f5b1f79ff
commit 7eefe2b96e
5 changed files with 98 additions and 35 deletions

View File

@@ -5,6 +5,7 @@ import type {
} from "../functions"
import * as Err from "./error"
import type { FilePath, ReverseFilePath } from "./filesystem"
import { newDirectoryHandle } from "./filesystem"
type Directory = {
kind: "directory"
@@ -42,12 +43,20 @@ export async function fetch(
)
}
const path: ReverseFilePath = [{ id: directoryId, name: directory.name }]
const path: ReverseFilePath = [
{
handle: newDirectoryHandle(directoryId),
name: directory.name,
},
]
let parentDirId = directory.parentId
while (parentDirId) {
const parentDir = await ctx.db.get(parentDirId)
if (parentDir) {
path.push({ id: parentDir._id, name: parentDir.name })
path.push({
handle: newDirectoryHandle(parentDir._id),
name: parentDir.name,
})
parentDirId = parentDir.parentId
} else {
throw Err.create(Err.Code.Internal)

View File

@@ -1,12 +1,12 @@
import type { Id } from "../_generated/dataModel"
export type DirectoryPathComponent = {
id: Id<"directories">
handle: DirectoryHandle
name: string
}
export type FilePathComponent = {
id: Id<"files">
handle: FileHandle
name: string
}
@@ -15,3 +15,23 @@ export type PathComponent = FilePathComponent | DirectoryPathComponent
export type FilePath = [...DirectoryPathComponent[], PathComponent]
export type ReverseFilePath = [PathComponent, ...DirectoryPathComponent[]]
export type FileHandle = {
kind: "file"
id: Id<"files">
}
export type DirectoryHandle = {
kind: "directory"
id: Id<"directories">
}
export type FileSystemHandle = DirectoryHandle | FileHandle
export function newDirectoryHandle(id: Id<"directories">): DirectoryHandle {
return { kind: "directory", id }
}
export function newFileHandle(id: Id<"files">): FileHandle {
return { kind: "file", id }
}