Skip to content
Source
Sign inSign up

WorkspaceEntryIcon.tsx

39 lines1.1 KB

1import type { EnvironmentId } from "@t3tools/contracts";
2import { formatAttachmentSize } from "@t3tools/client-runtime/state/attachments";
3​
4import { useFileMetadata } from "../../hooks/useFileMetadata";
5import { PierreEntryIcon } from "./PierreEntryIcon";
6​
7export function WorkspaceEntryIcon(props: {
8 path: string;
9 environmentId?: EnvironmentId | null | undefined;
10 cwd?: string | undefined;
11 theme: "light" | "dark";
12}) {
13 const metadata = useFileMetadata(props.environmentId, props.path, props.cwd);
14 return (
15 <PierreEntryIcon
16 pathValue={props.path}
17 kind={metadata?.kind === "directory" ? "directory" : "file"}
18 mimeType={metadata?.mimeType}
19 theme={props.theme}
20 />
21 );
23​
24export function WorkspaceEntryTooltip(props: {
25 path: string;
26 label?: string;
27 environmentId?: EnvironmentId | null | undefined;
28 cwd?: string | undefined;
29}) {
30 const metadata = useFileMetadata(props.environmentId, props.path, props.cwd);
31 return (
32 <>
33 {props.label ?? props.path}
34 {metadata?.byteLength === undefined
35 ? null
36 : ` · ${formatAttachmentSize(metadata.byteLength)}`}
37 </>
38 );