import { asset, Head } from "$fresh/runtime.ts"; import { useState } from "preact/hooks"; import { extname, join } from "path/posix.ts"; import { ComponentChild } from "preact"; import UpList from "./UpList.tsx"; import { extToIcon } from "../src/media.ts"; import { encodePath } from "../util/util.ts"; function ListItem(props: { href: string; icon: string; children: ComponentChild; }) { return (
  • {props.children}

  • ); } export interface EntryInfo { name: string; isFile: boolean; isDirectory: boolean; isSymlink: boolean; size: number; lastModified?: Date; } interface DirListProps { path: string; files: EntryInfo[]; } export function DirList(props: DirListProps) { const data = props; const [files, setFiles] = useState(data.files); return (
    ); function sortDir() { // sort by directory first then by index const sorted_files = files.map((x, i) => ([x, i] as [EntryInfo, number])) .sort( ([a, ai], [b, bi]) => { if (a.isDirectory && !b.isDirectory) { return -1; } else if (!a.isDirectory && b.isDirectory) { return 1; } else { return ai - bi; } }, ); setFiles(sorted_files.map(([x, _]) => x)); } function sortAlpha() { // sort by alphabet first then by index const sorted_files = files.map((x, i) => ([x, i] as [EntryInfo, number])) .sort( ([a, ai], [b, bi]) => { const ret = a.name.localeCompare(b.name); if (ret === 0) { return ai - bi; } else { return ret; } }, ); setFiles(sorted_files.map(([x, _]) => x)); } } export default DirList;