2024-05-21 01:08:45 +02:00
|
|
|
// Copyright 2024, Command Line Inc.
|
|
|
|
// SPDX-License-Identifier: Apache-2.0
|
|
|
|
|
2024-06-25 22:53:55 +02:00
|
|
|
import * as services from "@/store/services";
|
2024-06-22 09:41:49 +02:00
|
|
|
import * as util from "@/util/util";
|
2024-06-25 21:37:58 +02:00
|
|
|
import {
|
|
|
|
Table,
|
|
|
|
createColumnHelper,
|
|
|
|
flexRender,
|
|
|
|
getCoreRowModel,
|
|
|
|
getSortedRowModel,
|
|
|
|
useReactTable,
|
|
|
|
} from "@tanstack/react-table";
|
2024-06-04 03:22:26 +02:00
|
|
|
import clsx from "clsx";
|
2024-05-29 09:00:36 +02:00
|
|
|
import * as jotai from "jotai";
|
2024-05-28 21:12:28 +02:00
|
|
|
import React from "react";
|
2024-06-25 21:37:58 +02:00
|
|
|
import { ContextMenuModel } from "../store/contextmenu";
|
2024-06-26 21:14:59 +02:00
|
|
|
import { atoms, createBlock, getApi } from "../store/global";
|
2024-05-21 01:08:45 +02:00
|
|
|
|
2024-05-29 09:00:36 +02:00
|
|
|
import "./directorypreview.less";
|
2024-05-21 01:08:45 +02:00
|
|
|
|
|
|
|
interface DirectoryTableProps {
|
|
|
|
data: FileInfo[];
|
2024-06-03 22:24:20 +02:00
|
|
|
cwd: string;
|
2024-06-27 01:59:45 +02:00
|
|
|
focusIndex: number;
|
|
|
|
enter: boolean;
|
|
|
|
setFocusIndex: (_: number) => void;
|
2024-05-29 09:00:36 +02:00
|
|
|
setFileName: (_: string) => void;
|
2024-05-21 01:08:45 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
const columnHelper = createColumnHelper<FileInfo>();
|
|
|
|
|
2024-06-22 09:41:49 +02:00
|
|
|
const displaySuffixes = {
|
|
|
|
B: "b",
|
|
|
|
kB: "k",
|
|
|
|
MB: "m",
|
|
|
|
GB: "g",
|
|
|
|
TB: "t",
|
|
|
|
KiB: "k",
|
|
|
|
MiB: "m",
|
|
|
|
GiB: "g",
|
|
|
|
TiB: "t",
|
|
|
|
};
|
|
|
|
|
|
|
|
function getBestUnit(bytes: number, si: boolean = false, sigfig: number = 3): string {
|
|
|
|
if (bytes < 0) {
|
2024-06-25 21:37:58 +02:00
|
|
|
return "-";
|
2024-06-22 09:41:49 +02:00
|
|
|
}
|
|
|
|
const units = si ? ["kB", "MB", "GB", "TB"] : ["KiB", "MiB", "GiB", "TiB"];
|
|
|
|
const divisor = si ? 1000 : 1024;
|
|
|
|
|
|
|
|
let currentUnit = "B";
|
|
|
|
let currentValue = bytes;
|
|
|
|
let idx = 0;
|
|
|
|
while (currentValue > divisor && idx < units.length - 1) {
|
|
|
|
currentUnit = units[idx];
|
|
|
|
currentValue /= divisor;
|
2024-06-26 21:14:59 +02:00
|
|
|
idx += 1;
|
2024-06-22 09:41:49 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
return `${parseFloat(currentValue.toPrecision(sigfig))}${displaySuffixes[currentUnit]}`;
|
|
|
|
}
|
|
|
|
|
|
|
|
function getSpecificUnit(bytes: number, suffix: string): string {
|
|
|
|
if (bytes < 0) {
|
2024-06-25 21:37:58 +02:00
|
|
|
return "-";
|
2024-06-22 09:41:49 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
const divisors = new Map([
|
|
|
|
["B", 1],
|
|
|
|
["kB", 1e3],
|
|
|
|
["MB", 1e6],
|
|
|
|
["GB", 1e9],
|
|
|
|
["TB", 1e12],
|
|
|
|
["KiB", 0x400],
|
|
|
|
["MiB", 0x400 ** 2],
|
|
|
|
["GiB", 0x400 ** 3],
|
|
|
|
["TiB", 0x400 ** 4],
|
|
|
|
]);
|
|
|
|
const divisor: number = divisors[suffix] ?? 1;
|
|
|
|
|
|
|
|
return `${bytes / divisor} ${displaySuffixes[suffix]}`;
|
|
|
|
}
|
|
|
|
|
|
|
|
function getLastModifiedTime(
|
|
|
|
unixMillis: number,
|
|
|
|
locale: Intl.LocalesArgument,
|
|
|
|
options: DateTimeFormatConfigType
|
|
|
|
): string {
|
|
|
|
if (locale === "C") {
|
|
|
|
locale = "lookup";
|
|
|
|
}
|
|
|
|
return new Date(unixMillis).toLocaleString(locale, options); //todo use config
|
|
|
|
}
|
|
|
|
|
|
|
|
const iconRegex = /^[a-z0-9- ]+$/;
|
|
|
|
|
|
|
|
function isIconValid(icon: string): boolean {
|
|
|
|
if (util.isBlank(icon)) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
return icon.match(iconRegex) != null;
|
|
|
|
}
|
|
|
|
|
|
|
|
function getIconClass(icon: string): string {
|
|
|
|
if (!isIconValid(icon)) {
|
|
|
|
return "fa fa-solid fa-question fa-fw";
|
|
|
|
}
|
|
|
|
return `fa fa-solid fa-${icon} fa-fw`;
|
|
|
|
}
|
2024-05-21 01:08:45 +02:00
|
|
|
|
2024-06-25 21:37:58 +02:00
|
|
|
function getSortIcon(sortType: string | boolean): React.ReactNode {
|
|
|
|
switch (sortType) {
|
|
|
|
case "asc":
|
|
|
|
return <i className="fa-solid fa-chevron-up dir-table-head-direction"></i>;
|
|
|
|
case "desc":
|
|
|
|
return <i className="fa-solid fa-chevron-down dir-table-head-direction"></i>;
|
|
|
|
default:
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function handleFileContextMenu(e: React.MouseEvent<HTMLDivElement>, path: string) {
|
|
|
|
e.preventDefault();
|
|
|
|
e.stopPropagation();
|
|
|
|
let menu: ContextMenuItem[] = [];
|
|
|
|
menu.push({
|
|
|
|
label: "Open in New Block",
|
2024-06-25 22:53:55 +02:00
|
|
|
click: async () => {
|
|
|
|
const blockDef = {
|
|
|
|
view: "preview",
|
|
|
|
meta: { file: path },
|
|
|
|
};
|
|
|
|
await createBlock(blockDef);
|
2024-06-25 21:37:58 +02:00
|
|
|
},
|
|
|
|
});
|
|
|
|
menu.push({
|
|
|
|
label: "Delete File",
|
2024-06-25 22:53:55 +02:00
|
|
|
click: async () => {
|
|
|
|
await services.FileService.DeleteFile(path).catch((e) => console.log(e)); //todo these errors need a popup
|
2024-06-25 21:37:58 +02:00
|
|
|
},
|
|
|
|
});
|
2024-06-26 21:14:59 +02:00
|
|
|
menu.push({
|
|
|
|
label: "Download File",
|
|
|
|
click: async () => {
|
|
|
|
getApi().downloadFile(path);
|
|
|
|
},
|
|
|
|
});
|
2024-06-25 21:37:58 +02:00
|
|
|
ContextMenuModel.showContextMenu(menu, e);
|
|
|
|
}
|
|
|
|
|
2024-06-26 21:14:59 +02:00
|
|
|
function cleanMimetype(input: string): string {
|
|
|
|
const truncated = input.split(";")[0];
|
|
|
|
return truncated.trim();
|
|
|
|
}
|
|
|
|
|
2024-06-27 01:59:45 +02:00
|
|
|
function DirectoryTable({ data, cwd, focusIndex, enter, setFocusIndex, setFileName }: DirectoryTableProps) {
|
2024-06-22 09:41:49 +02:00
|
|
|
let settings = jotai.useAtomValue(atoms.settingsConfigAtom);
|
|
|
|
const getIconFromMimeType = React.useCallback(
|
|
|
|
(mimeType: string): string => {
|
|
|
|
while (mimeType.length > 0) {
|
|
|
|
let icon = settings.mimetypes[mimeType]?.icon ?? null;
|
|
|
|
if (isIconValid(icon)) {
|
|
|
|
return `fa fa-solid fa-${icon} fa-fw`;
|
|
|
|
}
|
|
|
|
mimeType = mimeType.slice(0, -1);
|
|
|
|
}
|
2024-06-25 21:37:58 +02:00
|
|
|
return "fa fa-solid fa-file fa-fw";
|
2024-06-22 09:41:49 +02:00
|
|
|
},
|
|
|
|
[settings.mimetypes]
|
|
|
|
);
|
2024-06-26 21:14:59 +02:00
|
|
|
const getIconColor = React.useCallback(
|
|
|
|
(mimeType: string): string => {
|
|
|
|
let iconColor = settings.mimetypes[mimeType]?.color ?? "inherit";
|
|
|
|
return iconColor;
|
|
|
|
},
|
|
|
|
[settings.mimetypes]
|
|
|
|
);
|
2024-06-22 09:41:49 +02:00
|
|
|
const columns = React.useMemo(
|
|
|
|
() => [
|
|
|
|
columnHelper.accessor("mimetype", {
|
2024-06-26 21:14:59 +02:00
|
|
|
cell: (info) => (
|
|
|
|
<i
|
|
|
|
className={getIconFromMimeType(info.getValue() ?? "")}
|
|
|
|
style={{ color: getIconColor(info.getValue() ?? "") }}
|
|
|
|
></i>
|
|
|
|
),
|
|
|
|
header: () => <span></span>,
|
2024-06-22 09:41:49 +02:00
|
|
|
id: "logo",
|
|
|
|
size: 25,
|
2024-06-25 21:37:58 +02:00
|
|
|
enableSorting: false,
|
2024-06-22 09:41:49 +02:00
|
|
|
}),
|
|
|
|
columnHelper.accessor("path", {
|
2024-06-26 18:31:43 +02:00
|
|
|
cell: (info) => <span className="dir-table-path">{info.getValue()}</span>,
|
2024-06-22 09:41:49 +02:00
|
|
|
header: () => <span>Name</span>,
|
2024-06-25 21:37:58 +02:00
|
|
|
sortingFn: "alphanumeric",
|
2024-06-22 09:41:49 +02:00
|
|
|
}),
|
|
|
|
columnHelper.accessor("modestr", {
|
2024-06-26 18:31:43 +02:00
|
|
|
cell: (info) => <span className="dir-table-modestr">{info.getValue()}</span>,
|
2024-06-22 09:41:49 +02:00
|
|
|
header: () => <span>Permissions</span>,
|
|
|
|
size: 91,
|
2024-06-25 21:37:58 +02:00
|
|
|
sortingFn: "alphanumeric",
|
2024-06-22 09:41:49 +02:00
|
|
|
}),
|
|
|
|
columnHelper.accessor("modtime", {
|
2024-06-26 18:31:43 +02:00
|
|
|
cell: (info) => (
|
|
|
|
<span className="dir-table-lastmod">
|
|
|
|
{getLastModifiedTime(info.getValue(), settings.datetime.locale, settings.datetime.format)}
|
|
|
|
</span>
|
|
|
|
),
|
2024-06-22 09:41:49 +02:00
|
|
|
header: () => <span>Last Modified</span>,
|
|
|
|
size: 185,
|
2024-06-25 21:37:58 +02:00
|
|
|
sortingFn: "datetime",
|
2024-06-22 09:41:49 +02:00
|
|
|
}),
|
|
|
|
columnHelper.accessor("size", {
|
2024-06-26 18:31:43 +02:00
|
|
|
cell: (info) => <span className="dir-table-size">{getBestUnit(info.getValue())}</span>,
|
2024-06-22 09:41:49 +02:00
|
|
|
header: () => <span>Size</span>,
|
|
|
|
size: 55,
|
2024-06-25 21:37:58 +02:00
|
|
|
sortingFn: "auto",
|
2024-06-22 09:41:49 +02:00
|
|
|
}),
|
|
|
|
columnHelper.accessor("mimetype", {
|
2024-06-26 21:14:59 +02:00
|
|
|
cell: (info) => <span className="dir-table-type">{cleanMimetype(info.getValue() ?? "")}</span>,
|
2024-06-22 09:41:49 +02:00
|
|
|
header: () => <span>Type</span>,
|
2024-06-25 21:37:58 +02:00
|
|
|
sortingFn: "alphanumeric",
|
2024-06-22 09:41:49 +02:00
|
|
|
}),
|
|
|
|
],
|
|
|
|
[settings]
|
|
|
|
);
|
|
|
|
|
2024-05-21 01:08:45 +02:00
|
|
|
const table = useReactTable({
|
|
|
|
data,
|
|
|
|
columns,
|
|
|
|
columnResizeMode: "onChange",
|
2024-06-25 21:37:58 +02:00
|
|
|
getSortedRowModel: getSortedRowModel(),
|
2024-05-21 01:08:45 +02:00
|
|
|
getCoreRowModel: getCoreRowModel(),
|
2024-06-25 21:37:58 +02:00
|
|
|
initialState: {
|
|
|
|
sorting: [
|
|
|
|
{
|
|
|
|
id: "path",
|
|
|
|
desc: false,
|
|
|
|
},
|
|
|
|
],
|
|
|
|
},
|
|
|
|
enableMultiSort: false,
|
|
|
|
enableSortingRemoval: false,
|
2024-05-21 01:08:45 +02:00
|
|
|
});
|
|
|
|
|
2024-05-21 21:14:04 +02:00
|
|
|
const columnSizeVars = React.useMemo(() => {
|
|
|
|
const headers = table.getFlatHeaders();
|
|
|
|
const colSizes: { [key: string]: number } = {};
|
|
|
|
for (let i = 0; i < headers.length; i++) {
|
|
|
|
const header = headers[i]!;
|
|
|
|
colSizes[`--header-${header.id}-size`] = header.getSize();
|
|
|
|
colSizes[`--col-${header.column.id}-size`] = header.column.getSize();
|
|
|
|
}
|
|
|
|
return colSizes;
|
|
|
|
}, [table.getState().columnSizingInfo]);
|
|
|
|
|
2024-05-21 01:08:45 +02:00
|
|
|
return (
|
2024-05-21 21:14:04 +02:00
|
|
|
<div className="dir-table" style={{ ...columnSizeVars }}>
|
|
|
|
<div className="dir-table-head">
|
2024-05-21 01:08:45 +02:00
|
|
|
{table.getHeaderGroups().map((headerGroup) => (
|
2024-05-21 21:14:04 +02:00
|
|
|
<div className="dir-table-head-row" key={headerGroup.id}>
|
2024-05-21 01:08:45 +02:00
|
|
|
{headerGroup.headers.map((header) => (
|
2024-05-21 21:14:04 +02:00
|
|
|
<div
|
|
|
|
className="dir-table-head-cell"
|
|
|
|
key={header.id}
|
|
|
|
style={{ width: `calc(var(--header-${header.id}-size) * 1px)` }}
|
2024-06-25 21:37:58 +02:00
|
|
|
onClick={() => header.column.toggleSorting()}
|
2024-05-21 21:14:04 +02:00
|
|
|
>
|
2024-05-21 01:08:45 +02:00
|
|
|
{header.isPlaceholder
|
|
|
|
? null
|
|
|
|
: flexRender(header.column.columnDef.header, header.getContext())}
|
2024-06-25 21:37:58 +02:00
|
|
|
{getSortIcon(header.column.getIsSorted())}
|
2024-05-21 21:14:04 +02:00
|
|
|
<div
|
|
|
|
className="dir-table-head-resize"
|
|
|
|
onMouseDown={header.getResizeHandler()}
|
|
|
|
onTouchStart={header.getResizeHandler()}
|
|
|
|
/>
|
|
|
|
</div>
|
2024-05-21 01:08:45 +02:00
|
|
|
))}
|
2024-05-21 21:14:04 +02:00
|
|
|
</div>
|
2024-05-21 01:08:45 +02:00
|
|
|
))}
|
2024-05-21 21:14:04 +02:00
|
|
|
</div>
|
|
|
|
{table.getState().columnSizingInfo.isResizingColumn ? (
|
2024-06-27 01:59:45 +02:00
|
|
|
<MemoizedTableBody
|
|
|
|
table={table}
|
|
|
|
cwd={cwd}
|
|
|
|
focusIndex={focusIndex}
|
|
|
|
enter={enter}
|
|
|
|
setFileName={setFileName}
|
|
|
|
setFocusIndex={setFocusIndex}
|
|
|
|
/>
|
2024-05-21 21:14:04 +02:00
|
|
|
) : (
|
2024-06-27 01:59:45 +02:00
|
|
|
<TableBody
|
|
|
|
table={table}
|
|
|
|
cwd={cwd}
|
|
|
|
focusIndex={focusIndex}
|
|
|
|
enter={enter}
|
|
|
|
setFileName={setFileName}
|
|
|
|
setFocusIndex={setFocusIndex}
|
|
|
|
/>
|
2024-05-21 21:14:04 +02:00
|
|
|
)}
|
|
|
|
</div>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2024-05-29 09:00:36 +02:00
|
|
|
interface TableBodyProps {
|
|
|
|
table: Table<FileInfo>;
|
2024-06-03 22:24:20 +02:00
|
|
|
cwd: string;
|
2024-06-27 01:59:45 +02:00
|
|
|
focusIndex: number;
|
|
|
|
enter: boolean;
|
|
|
|
setFocusIndex: (_: number) => void;
|
2024-05-29 09:00:36 +02:00
|
|
|
setFileName: (_: string) => void;
|
|
|
|
}
|
|
|
|
|
2024-06-27 01:59:45 +02:00
|
|
|
function TableBody({ table, cwd, focusIndex, enter, setFocusIndex, setFileName }: TableBodyProps) {
|
2024-06-25 22:53:55 +02:00
|
|
|
let [refresh, setRefresh] = React.useState(false);
|
|
|
|
|
2024-06-27 01:59:45 +02:00
|
|
|
React.useEffect(() => {
|
|
|
|
const selected = (table.getSortedRowModel()?.flatRows[focusIndex]?.getValue("path") as string) ?? null;
|
|
|
|
if (selected != null) {
|
|
|
|
console.log("yipee");
|
|
|
|
const fullPath = cwd.concat("/", selected);
|
|
|
|
setFileName(fullPath);
|
|
|
|
}
|
|
|
|
}, [enter]);
|
|
|
|
|
|
|
|
table.getRow;
|
2024-05-21 21:14:04 +02:00
|
|
|
return (
|
|
|
|
<div className="dir-table-body">
|
2024-06-27 01:59:45 +02:00
|
|
|
{table.getRowModel().rows.map((row, idx) => (
|
2024-05-29 09:00:36 +02:00
|
|
|
<div
|
2024-06-27 01:59:45 +02:00
|
|
|
className={clsx("dir-table-body-row", { focused: focusIndex === idx })}
|
2024-05-29 09:00:36 +02:00
|
|
|
key={row.id}
|
|
|
|
onDoubleClick={() => {
|
|
|
|
const newFileName = row.getValue("path") as string;
|
2024-06-03 22:24:20 +02:00
|
|
|
const fullPath = cwd.concat("/", newFileName);
|
|
|
|
setFileName(fullPath);
|
2024-05-29 09:00:36 +02:00
|
|
|
}}
|
2024-06-27 01:59:45 +02:00
|
|
|
onClick={() => setFocusIndex(idx)}
|
2024-06-25 21:37:58 +02:00
|
|
|
onContextMenu={(e) => handleFileContextMenu(e, cwd.concat("/", row.getValue("path") as string))}
|
2024-05-29 09:00:36 +02:00
|
|
|
>
|
2024-06-03 22:24:20 +02:00
|
|
|
{row.getVisibleCells().map((cell) => {
|
|
|
|
return (
|
|
|
|
<div
|
2024-06-04 03:22:26 +02:00
|
|
|
className={clsx("dir-table-body-cell", "col-" + cell.column.id)}
|
2024-06-03 22:24:20 +02:00
|
|
|
key={cell.id}
|
|
|
|
style={{ width: `calc(var(--col-${cell.column.id}-size) * 1px)` }}
|
|
|
|
>
|
2024-06-22 09:41:49 +02:00
|
|
|
{flexRender(cell.column.columnDef.cell, cell.getContext())}
|
2024-06-03 22:24:20 +02:00
|
|
|
</div>
|
|
|
|
);
|
|
|
|
})}
|
2024-05-21 21:14:04 +02:00
|
|
|
</div>
|
|
|
|
))}
|
|
|
|
</div>
|
2024-05-21 01:08:45 +02:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2024-05-21 21:14:04 +02:00
|
|
|
const MemoizedTableBody = React.memo(
|
|
|
|
TableBody,
|
|
|
|
(prev, next) => prev.table.options.data == next.table.options.data
|
|
|
|
) as typeof TableBody;
|
|
|
|
|
2024-05-29 09:00:36 +02:00
|
|
|
interface DirectoryPreviewProps {
|
|
|
|
fileNameAtom: jotai.WritableAtom<string, [string], void>;
|
|
|
|
}
|
|
|
|
|
2024-06-27 01:59:45 +02:00
|
|
|
function DirectoryPreview({ fileNameAtom }: DirectoryPreviewProps) {
|
|
|
|
const [searchText, setSearchText] = React.useState("");
|
|
|
|
let [focusIndex, setFocusIndex] = React.useState(0);
|
|
|
|
const [content, setContent] = React.useState<FileInfo[]>([]);
|
2024-05-29 09:00:36 +02:00
|
|
|
let [fileName, setFileName] = jotai.useAtom(fileNameAtom);
|
2024-06-27 01:59:45 +02:00
|
|
|
const [enter, setEnter] = React.useState(false);
|
|
|
|
|
|
|
|
React.useEffect(() => {
|
|
|
|
const getContent = async () => {
|
|
|
|
const file = await services.FileService.ReadFile(fileName);
|
|
|
|
const serializedContent = util.base64ToString(file?.data64);
|
|
|
|
let content: FileInfo[] = JSON.parse(serializedContent);
|
|
|
|
let filtered = content.filter((fileInfo) => {
|
|
|
|
return fileInfo.path.toLowerCase().includes(searchText);
|
|
|
|
});
|
|
|
|
setContent(filtered);
|
|
|
|
};
|
|
|
|
getContent();
|
|
|
|
}, [fileName, searchText]);
|
|
|
|
|
|
|
|
const handleKeyDown = React.useCallback(
|
|
|
|
(e) => {
|
|
|
|
switch (e.key) {
|
|
|
|
case "Escape":
|
|
|
|
//todo: escape block focus
|
|
|
|
break;
|
|
|
|
case "ArrowUp":
|
|
|
|
e.preventDefault();
|
|
|
|
setFocusIndex((idx) => Math.max(idx - 1, 0));
|
|
|
|
break;
|
|
|
|
case "ArrowDown":
|
|
|
|
e.preventDefault();
|
|
|
|
setFocusIndex((idx) => Math.min(idx + 1, content.length - 1));
|
|
|
|
break;
|
|
|
|
case "Enter":
|
|
|
|
e.preventDefault();
|
|
|
|
console.log("enter thinks focus Index is ", focusIndex);
|
|
|
|
let newFileName = content[focusIndex].path;
|
|
|
|
console.log(
|
|
|
|
"enter thinks contents are",
|
|
|
|
content.slice(0, focusIndex + 1).map((fi) => fi.path)
|
|
|
|
);
|
|
|
|
setEnter((current) => !current);
|
|
|
|
/*
|
|
|
|
const fullPath = fileName.concat("/", newFileName);
|
|
|
|
setFileName(fullPath);
|
|
|
|
*/
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
}
|
|
|
|
},
|
|
|
|
[content, focusIndex, setEnter]
|
|
|
|
);
|
|
|
|
|
|
|
|
React.useEffect(() => {
|
|
|
|
console.log(focusIndex);
|
|
|
|
}, [focusIndex]);
|
|
|
|
|
|
|
|
React.useEffect(() => {
|
|
|
|
document.addEventListener("keydown", handleKeyDown);
|
|
|
|
|
|
|
|
return () => {
|
|
|
|
document.removeEventListener("keydown", handleKeyDown);
|
|
|
|
};
|
|
|
|
}, [handleKeyDown]);
|
|
|
|
|
|
|
|
return (
|
|
|
|
<>
|
|
|
|
<div className="dir-table-search-line">
|
|
|
|
<label>Search:</label>
|
|
|
|
|
|
|
|
<input
|
|
|
|
type="text"
|
|
|
|
className="dir-table-search-box"
|
|
|
|
onChange={(e) => setSearchText(e.target.value.toLowerCase())}
|
|
|
|
maxLength={400}
|
|
|
|
autoFocus={true}
|
|
|
|
/>
|
|
|
|
</div>
|
|
|
|
<DirectoryTable
|
|
|
|
data={content}
|
|
|
|
cwd={fileName}
|
|
|
|
focusIndex={focusIndex}
|
|
|
|
enter={enter}
|
|
|
|
setFileName={setFileName}
|
|
|
|
setFocusIndex={setFocusIndex}
|
|
|
|
/>
|
|
|
|
</>
|
|
|
|
);
|
2024-05-29 09:00:36 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
export { DirectoryPreview };
|