2024-04-11 04:24:36 -04:00
|
|
|
"use client"
|
|
|
|
|
|
|
|
import Image from "next/image"
|
|
|
|
import { getIconForFile } from "vscode-icons-js"
|
|
|
|
import { TFile } from "./types"
|
2024-04-26 00:10:53 -04:00
|
|
|
import { useEffect, useState } from "react"
|
|
|
|
|
|
|
|
export default function SidebarFile({
|
|
|
|
data,
|
|
|
|
selectFile,
|
|
|
|
}: {
|
|
|
|
data: TFile
|
|
|
|
selectFile: (file: TFile) => void
|
|
|
|
}) {
|
|
|
|
const [imgSrc, setImgSrc] = useState(`/icons/${getIconForFile(data.name)}`)
|
2024-04-11 04:24:36 -04:00
|
|
|
|
|
|
|
return (
|
2024-04-26 00:10:53 -04:00
|
|
|
<button
|
|
|
|
onClick={() => selectFile(data)}
|
|
|
|
className="w-full flex items-center h-7 px-1 hover:bg-secondary rounded-sm cursor-pointer transition-colors focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-ring"
|
|
|
|
>
|
2024-04-11 04:24:36 -04:00
|
|
|
<Image
|
2024-04-26 00:10:53 -04:00
|
|
|
src={imgSrc}
|
2024-04-11 04:24:36 -04:00
|
|
|
alt="File Icon"
|
|
|
|
width={18}
|
|
|
|
height={18}
|
|
|
|
className="mr-2"
|
2024-04-26 00:10:53 -04:00
|
|
|
onError={() => setImgSrc("/icons/default_file.svg")}
|
2024-04-11 04:24:36 -04:00
|
|
|
/>
|
|
|
|
{data.name}
|
2024-04-26 00:10:53 -04:00
|
|
|
</button>
|
2024-04-11 04:24:36 -04:00
|
|
|
)
|
|
|
|
}
|