2024-04-26 00:10:53 -04:00
|
|
|
"use client"
|
|
|
|
|
2024-04-26 22:34:56 -04:00
|
|
|
import { FilePlus, FolderPlus, Loader2, Search } from "lucide-react"
|
2024-04-11 04:24:36 -04:00
|
|
|
import SidebarFile from "./file"
|
|
|
|
import SidebarFolder from "./folder"
|
2024-04-27 11:08:19 -04:00
|
|
|
import { TFile, TFolder, TTab } from "./types"
|
2024-04-11 04:24:36 -04:00
|
|
|
|
2024-04-26 00:10:53 -04:00
|
|
|
export default function Sidebar({
|
|
|
|
files,
|
|
|
|
selectFile,
|
2024-04-27 14:23:09 -04:00
|
|
|
handleRename,
|
2024-04-26 00:10:53 -04:00
|
|
|
}: {
|
|
|
|
files: (TFile | TFolder)[]
|
2024-04-27 11:08:19 -04:00
|
|
|
selectFile: (tab: TTab) => void
|
2024-04-27 14:23:09 -04:00
|
|
|
handleRename: (
|
|
|
|
id: string,
|
|
|
|
newName: string,
|
|
|
|
oldName: string,
|
|
|
|
type: "file" | "folder"
|
|
|
|
) => boolean
|
2024-04-26 00:10:53 -04:00
|
|
|
}) {
|
2024-04-11 04:24:36 -04:00
|
|
|
return (
|
2024-04-11 05:14:10 -04:00
|
|
|
<div className="h-full w-56 select-none flex flex-col text-sm items-start p-2">
|
2024-04-11 04:24:36 -04:00
|
|
|
<div className="flex w-full items-center justify-between h-8 mb-1 ">
|
2024-04-26 00:10:53 -04:00
|
|
|
<div className="text-muted-foreground">Explorer</div>
|
2024-04-11 04:24:36 -04:00
|
|
|
<div className="flex space-x-1">
|
|
|
|
<div className="h-6 w-6 text-muted-foreground ml-0.5 flex items-center justify-center translate-x-1 transition-colors bg-transparent hover:bg-muted-foreground/25 cursor-pointer rounded-sm">
|
|
|
|
<FilePlus className="w-4 h-4" />
|
|
|
|
</div>
|
|
|
|
<div className="h-6 w-6 text-muted-foreground ml-0.5 flex items-center justify-center translate-x-1 transition-colors bg-transparent hover:bg-muted-foreground/25 cursor-pointer rounded-sm">
|
|
|
|
<FolderPlus className="w-4 h-4" />
|
|
|
|
</div>
|
|
|
|
<div className="h-6 w-6 text-muted-foreground ml-0.5 flex items-center justify-center translate-x-1 transition-colors bg-transparent hover:bg-muted-foreground/25 cursor-pointer rounded-sm">
|
|
|
|
<Search className="w-4 h-4" />
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
<div className="w-full mt-1 flex flex-col">
|
2024-04-26 22:34:56 -04:00
|
|
|
{files.length === 0 ? (
|
|
|
|
<div className="w-full flex justify-center">
|
|
|
|
<Loader2 className="w-4 h-4 animate-spin" />
|
|
|
|
</div>
|
|
|
|
) : (
|
|
|
|
files.map((child) =>
|
|
|
|
child.type === "file" ? (
|
|
|
|
<SidebarFile
|
|
|
|
key={child.id}
|
|
|
|
data={child}
|
|
|
|
selectFile={selectFile}
|
2024-04-27 14:23:09 -04:00
|
|
|
handleRename={handleRename}
|
2024-04-26 22:34:56 -04:00
|
|
|
/>
|
|
|
|
) : (
|
|
|
|
<SidebarFolder
|
|
|
|
key={child.id}
|
|
|
|
data={child}
|
|
|
|
selectFile={selectFile}
|
2024-04-27 14:23:09 -04:00
|
|
|
handleRename={handleRename}
|
2024-04-26 22:34:56 -04:00
|
|
|
/>
|
|
|
|
)
|
2024-04-11 04:24:36 -04:00
|
|
|
)
|
|
|
|
)}
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
)
|
|
|
|
}
|