Barre latérale : arborescence des dossiers communs sous « Fichiers »
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01LNfwm3Thvy13p3GDnEHmGD
This commit is contained in:
1 parent
ca53cedc32
commit
819ac94f60
3 files changed
+161
-1
No files matched your search
@@ -2,6 +2,7 @@ import { useCallback, useEffect, useRef, useState } from "react";
|
|||||||
import { api, FAVORIS, PERSO, POUBELLE, type Entry, type Me } from "./api";
|
import { api, FAVORIS, PERSO, POUBELLE, type Entry, type Me } from "./api";
|
||||||
import { ActionMenu } from "./ActionMenu";
|
import { ActionMenu } from "./ActionMenu";
|
||||||
import { Explorer } from "./Explorer";
|
import { Explorer } from "./Explorer";
|
||||||
|
import { FolderTree } from "./FolderTree";
|
||||||
import { Login } from "./Login";
|
import { Login } from "./Login";
|
||||||
import { SettingsDialog } from "./SettingsDialog";
|
import { SettingsDialog } from "./SettingsDialog";
|
||||||
import { Splitter } from "./Splitter";
|
import { Splitter } from "./Splitter";
|
||||||
@@ -92,6 +93,7 @@ function Shell({ me, reloadMe }: { me: Me; reloadMe: () => Promise<unknown> }) {
|
|||||||
const [goto, setGoto] = useState<{ dir: string; seq: number }>({ dir: hashDir(), seq: 0 });
|
const [goto, setGoto] = useState<{ dir: string; seq: number }>({ dir: hashDir(), seq: 0 });
|
||||||
const [refreshKey, setRefreshKey] = useState(0);
|
const [refreshKey, setRefreshKey] = useState(0);
|
||||||
const [places, setPlaces] = useState<Entry[]>([]);
|
const [places, setPlaces] = useState<Entry[]>([]);
|
||||||
|
const [treeKey, setTreeKey] = useState(0);
|
||||||
const [drawer, setDrawer] = useState(false);
|
const [drawer, setDrawer] = useState(false);
|
||||||
const [settings, setSettings] = useState<"account" | "tokens" | "shares" | "general" | "users" | null>(null);
|
const [settings, setSettings] = useState<"account" | "tokens" | "shares" | "general" | "users" | null>(null);
|
||||||
const [userMenu, setUserMenu] = useState<HTMLElement | null>(null);
|
const [userMenu, setUserMenu] = useState<HTMLElement | null>(null);
|
||||||
@@ -156,6 +158,7 @@ function Shell({ me, reloadMe }: { me: Me; reloadMe: () => Promise<unknown> }) {
|
|||||||
|
|
||||||
const onMutated = useCallback(() => {
|
const onMutated = useCallback(() => {
|
||||||
loadPlaces();
|
loadPlaces();
|
||||||
|
setTreeKey((k) => k + 1);
|
||||||
reloadMe();
|
reloadMe();
|
||||||
}, [loadPlaces, reloadMe]);
|
}, [loadPlaces, reloadMe]);
|
||||||
|
|
||||||
@@ -204,7 +207,8 @@ function Shell({ me, reloadMe }: { me: Me; reloadMe: () => Promise<unknown> }) {
|
|||||||
{drawer && <div className="scrim" onClick={() => setDrawer(false)} />}
|
{drawer && <div className="scrim" onClick={() => setDrawer(false)} />}
|
||||||
<aside className={`sidebar ${drawer ? "open" : ""}`}>
|
<aside className={`sidebar ${drawer ? "open" : ""}`}>
|
||||||
<nav>
|
<nav>
|
||||||
{navItem("", "Fichiers", <FolderIcon />, current === "")}
|
{navItem("", "Fichiers", <FolderIcon />, dir === "")}
|
||||||
|
<FolderTree current={current === "" ? dir : ""} reloadKey={refreshKey + treeKey} onOpen={go} />
|
||||||
{navItem(PERSO, "Personnel", <UserIcon />, current === PERSO)}
|
{navItem(PERSO, "Personnel", <UserIcon />, current === PERSO)}
|
||||||
{navItem(FAVORIS, "Favoris", <StarFilledIcon />, current === FAVORIS)}
|
{navItem(FAVORIS, "Favoris", <StarFilledIcon />, current === FAVORIS)}
|
||||||
{navItem(POUBELLE, "Poubelle", trash?.count ? <TrashFullIcon /> : <TrashIcon />, current === POUBELLE, trash?.count)}
|
{navItem(POUBELLE, "Poubelle", trash?.count ? <TrashFullIcon /> : <TrashIcon />, current === POUBELLE, trash?.count)}
|
||||||
|
|||||||
@@ -0,0 +1,98 @@
|
|||||||
|
import { useCallback, useEffect, useRef, useState } from "react";
|
||||||
|
import { api, type Entry } from "./api";
|
||||||
|
import { FolderGlyph } from "./folderIcons";
|
||||||
|
import { ChevronDownIcon, ChevronRightIcon } from "./icons";
|
||||||
|
|
||||||
|
interface Props {
|
||||||
|
/** Dossier courant s'il est dans l'arborescence commune, "" sinon. */
|
||||||
|
current: string;
|
||||||
|
/** Change à chaque modification (création, renommage, suppression…) : recharge les niveaux affichés. */
|
||||||
|
reloadKey: number;
|
||||||
|
onOpen: (path: string) => void;
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Arborescence commune dans la barre latérale : chargée niveau par niveau, à la demande. */
|
||||||
|
export function FolderTree({ current, reloadKey, onOpen }: Props) {
|
||||||
|
// Sous-dossiers déjà chargés, par chemin parent ("" = racine).
|
||||||
|
const [kids, setKids] = useState<Record<string, Entry[]>>({});
|
||||||
|
const [open, setOpen] = useState<Set<string>>(() => new Set());
|
||||||
|
const openRef = useRef(open);
|
||||||
|
openRef.current = open;
|
||||||
|
const kidsRef = useRef(kids);
|
||||||
|
kidsRef.current = kids;
|
||||||
|
|
||||||
|
const load = useCallback(async (dir: string) => {
|
||||||
|
let es: Entry[] = [];
|
||||||
|
try {
|
||||||
|
es = (await api.list(dir)).filter((e) => e.isDir && !e.special);
|
||||||
|
} catch {
|
||||||
|
/* dossier disparu ou illisible : branche vide */
|
||||||
|
}
|
||||||
|
setKids((k) => ({ ...k, [dir]: es }));
|
||||||
|
}, []);
|
||||||
|
|
||||||
|
// Racine et branches dépliées, au démarrage puis après chaque modification.
|
||||||
|
useEffect(() => {
|
||||||
|
load("");
|
||||||
|
openRef.current.forEach((p) => load(p));
|
||||||
|
}, [load, reloadKey]);
|
||||||
|
|
||||||
|
// Le dossier courant reste visible : ses parents sont dépliés.
|
||||||
|
useEffect(() => {
|
||||||
|
if (!current) return;
|
||||||
|
const parts = current.split("/");
|
||||||
|
const ancestors = parts.slice(0, -1).map((_, i) => parts.slice(0, i + 1).join("/"));
|
||||||
|
if (ancestors.length === 0) return;
|
||||||
|
setOpen((o) => {
|
||||||
|
if (ancestors.every((a) => o.has(a))) return o;
|
||||||
|
const n = new Set(o);
|
||||||
|
ancestors.forEach((a) => n.add(a));
|
||||||
|
return n;
|
||||||
|
});
|
||||||
|
ancestors.forEach((a) => kidsRef.current[a] === undefined && load(a));
|
||||||
|
}, [current, load]);
|
||||||
|
|
||||||
|
const toggle = (p: string) => {
|
||||||
|
const opening = !open.has(p);
|
||||||
|
setOpen((o) => {
|
||||||
|
const n = new Set(o);
|
||||||
|
if (opening) n.add(p);
|
||||||
|
else n.delete(p);
|
||||||
|
return n;
|
||||||
|
});
|
||||||
|
if (opening && kids[p] === undefined) load(p);
|
||||||
|
};
|
||||||
|
|
||||||
|
const branch = (dir: string, depth: number) => (
|
||||||
|
<ul className="folder-tree" role={depth === 0 ? "tree" : "group"} aria-label={depth === 0 ? "Dossiers" : undefined}>
|
||||||
|
{(kids[dir] ?? []).map((e) => {
|
||||||
|
const isOpen = open.has(e.path);
|
||||||
|
const sub = kids[e.path];
|
||||||
|
const leaf = sub !== undefined && sub.length === 0;
|
||||||
|
return (
|
||||||
|
<li key={e.path} role="treeitem" aria-expanded={leaf ? undefined : isOpen} aria-selected={current === e.path}>
|
||||||
|
<div className={`tree-row ${current === e.path ? "on" : ""}`} style={{ paddingLeft: `${depth * 14}px` }}>
|
||||||
|
{leaf ? (
|
||||||
|
<span className="tree-twisty" />
|
||||||
|
) : (
|
||||||
|
<button className="tree-twisty" onClick={() => toggle(e.path)} tabIndex={-1} aria-label={isOpen ? `Replier ${e.name}` : `Déplier ${e.name}`}>
|
||||||
|
{isOpen ? <ChevronDownIcon size={14} /> : <ChevronRightIcon size={14} />}
|
||||||
|
</button>
|
||||||
|
)}
|
||||||
|
<button className="tree-label" onClick={() => onOpen(e.path)} title={e.name}>
|
||||||
|
<span className="folder">
|
||||||
|
<FolderGlyph name={e.icon} size={16} />
|
||||||
|
</span>
|
||||||
|
<span className="tree-name">{e.name}</span>
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
{isOpen && sub && sub.length > 0 && branch(e.path, depth + 1)}
|
||||||
|
</li>
|
||||||
|
);
|
||||||
|
})}
|
||||||
|
</ul>
|
||||||
|
);
|
||||||
|
|
||||||
|
if (!kids[""]?.length) return null;
|
||||||
|
return branch("", 0);
|
||||||
|
}
|
||||||
@@ -2233,3 +2233,61 @@ th.c-size .th-btn {
|
|||||||
.csv-table tbody tr:hover td {
|
.csv-table tbody tr:hover td {
|
||||||
background: var(--hover);
|
background: var(--hover);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* Arborescence commune dans la barre latérale (FolderTree.tsx). */
|
||||||
|
.folder-tree {
|
||||||
|
list-style: none;
|
||||||
|
margin: 0;
|
||||||
|
padding: 0;
|
||||||
|
}
|
||||||
|
.sidebar nav > .folder-tree {
|
||||||
|
margin: 0 0 0.3rem 0.6rem;
|
||||||
|
}
|
||||||
|
.tree-row {
|
||||||
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
|
min-width: 0;
|
||||||
|
border-radius: var(--radius-sm);
|
||||||
|
}
|
||||||
|
.tree-row:hover {
|
||||||
|
background: var(--hover);
|
||||||
|
}
|
||||||
|
.tree-row.on {
|
||||||
|
background: var(--accent-soft);
|
||||||
|
color: var(--accent);
|
||||||
|
}
|
||||||
|
.tree-twisty {
|
||||||
|
flex: none;
|
||||||
|
width: 1.4rem;
|
||||||
|
height: 1.9rem;
|
||||||
|
padding: 0;
|
||||||
|
border: 0;
|
||||||
|
background: transparent;
|
||||||
|
color: var(--muted);
|
||||||
|
}
|
||||||
|
.tree-twisty:hover:not(:disabled) {
|
||||||
|
background: transparent;
|
||||||
|
color: var(--fg);
|
||||||
|
}
|
||||||
|
.tree-label {
|
||||||
|
flex: 1;
|
||||||
|
min-width: 0;
|
||||||
|
justify-content: flex-start;
|
||||||
|
height: 1.9rem;
|
||||||
|
padding: 0 0.4rem 0 0.1rem;
|
||||||
|
border: 0;
|
||||||
|
background: transparent;
|
||||||
|
font-weight: 400;
|
||||||
|
color: inherit;
|
||||||
|
}
|
||||||
|
.tree-label:hover:not(:disabled) {
|
||||||
|
background: transparent;
|
||||||
|
}
|
||||||
|
.tree-label .folder {
|
||||||
|
display: inline-flex;
|
||||||
|
color: var(--folder);
|
||||||
|
}
|
||||||
|
.tree-name {
|
||||||
|
overflow: hidden;
|
||||||
|
text-overflow: ellipsis;
|
||||||
|
}
|
||||||
Reference in new issue
Block a user