wip fix file tree
This commit is contained in:
parent
4d60d67f04
commit
79acd79f6c
|
|
@ -169,7 +169,7 @@ export const EdFileBrowser = () => {
|
||||||
className={cx(
|
className={cx(
|
||||||
"border-r",
|
"border-r",
|
||||||
css`
|
css`
|
||||||
width: 10px;
|
width: 5px;
|
||||||
`
|
`
|
||||||
)}
|
)}
|
||||||
/>
|
/>
|
||||||
|
|
|
||||||
|
|
@ -104,7 +104,7 @@ const TreeItem: FC<{
|
||||||
f.path === path && "border-r-2 bg-blue-100 border-r-blue-700"
|
f.path === path && "border-r-2 bg-blue-100 border-r-blue-700"
|
||||||
)}
|
)}
|
||||||
onClick={() => {
|
onClick={() => {
|
||||||
f.selected.clear();
|
f.selected.clear();
|
||||||
f.path = path;
|
f.path = path;
|
||||||
p.render();
|
p.render();
|
||||||
if (!f.expanded[path] || !f.entry[path]) {
|
if (!f.expanded[path] || !f.entry[path]) {
|
||||||
|
|
@ -287,10 +287,12 @@ const toggleDir = (p: PG, path: string, forceExpand?: boolean) => {
|
||||||
if (expanded) {
|
if (expanded) {
|
||||||
if (expanded.includes(path) && !forceExpand) {
|
if (expanded.includes(path) && !forceExpand) {
|
||||||
p.ui.popup.file.expanded[p.site.id] = expanded.filter((e) => e !== path);
|
p.ui.popup.file.expanded[p.site.id] = expanded.filter((e) => e !== path);
|
||||||
|
refreshTree(p);
|
||||||
} else {
|
} else {
|
||||||
p.ui.popup.file.expanded[p.site.id] = [...expanded, path];
|
p.ui.popup.file.expanded[p.site.id] = [...expanded, path];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
localStorage.setItem(
|
localStorage.setItem(
|
||||||
"panel-file-expanded",
|
"panel-file-expanded",
|
||||||
JSON.stringify(p.ui.popup.file.expanded)
|
JSON.stringify(p.ui.popup.file.expanded)
|
||||||
|
|
@ -307,32 +309,51 @@ export const reloadFileTree = async (p: PG) => {
|
||||||
}
|
}
|
||||||
|
|
||||||
if (exp) {
|
if (exp) {
|
||||||
for (const [k, v] of Object.entries(p.ui.popup.file.entry)) {
|
const promises: Promise<any>[] = [];
|
||||||
if (
|
const added = new Set<string>();
|
||||||
p.ui.popup.file.entry[k] &&
|
const fetched = new Set<string>();
|
||||||
!exp.includes(k) &&
|
for (const e of exp.sort((a, b) => a.length - b.length)) {
|
||||||
k !== "/" &&
|
|
||||||
k !== p.ui.popup.file.path
|
|
||||||
) {
|
|
||||||
delete p.ui.popup.file.entry[k];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
const promises = [];
|
|
||||||
for (const e of exp) {
|
|
||||||
if (e) {
|
if (e) {
|
||||||
if (!p.ui.popup.file.entry[e]) {
|
if (!p.ui.popup.file.entry[e]) {
|
||||||
promises.push(
|
let exists = false;
|
||||||
p.script.api._raw(`/_file${e}/?dir`).then((fe: FEntry[]) => {
|
|
||||||
if (Array.isArray(fe)) {
|
if (e.split("/").length <= 2) {
|
||||||
p.ui.popup.file.entry[e] = fe;
|
added.add(e);
|
||||||
|
exists = true;
|
||||||
|
} else {
|
||||||
|
for (const a of added) {
|
||||||
|
if (e.startsWith(a)) {
|
||||||
|
exists = true;
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
})
|
}
|
||||||
);
|
}
|
||||||
|
|
||||||
|
if (exists) {
|
||||||
|
const url = `/_file${e}/?dir`;
|
||||||
|
if (!fetched.has(url)) {
|
||||||
|
fetched.add(url);
|
||||||
|
promises.push(
|
||||||
|
p.script.api._raw(url).then((fe: FEntry[]) => {
|
||||||
|
if (Array.isArray(fe)) {
|
||||||
|
p.ui.popup.file.entry[e] = fe;
|
||||||
|
} else {
|
||||||
|
p.ui.popup.file.expanded[p.site.id] = exp.filter(
|
||||||
|
(item) => item !== e
|
||||||
|
);
|
||||||
|
}
|
||||||
|
})
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
await Promise.all(promises);
|
await Promise.all(promises);
|
||||||
|
localStorage.setItem(
|
||||||
|
"panel-file-expanded",
|
||||||
|
JSON.stringify(p.ui.popup.file.expanded)
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
const f = p.ui.popup.file;
|
const f = p.ui.popup.file;
|
||||||
|
|
@ -345,8 +366,23 @@ export const reloadFileTree = async (p: PG) => {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
const tree: NodeModel<FEntry>[] = p.ui.popup.file.tree;
|
refreshTree(p);
|
||||||
|
};
|
||||||
|
|
||||||
|
const refreshTree = (p: PG) => {
|
||||||
|
const exp = p.ui.popup.file.expanded[p.site.id];
|
||||||
|
for (const [k, v] of Object.entries(p.ui.popup.file.entry)) {
|
||||||
|
if (
|
||||||
|
p.ui.popup.file.entry[k] &&
|
||||||
|
!exp.includes(k) &&
|
||||||
|
k !== "/" &&
|
||||||
|
k !== p.ui.popup.file.path
|
||||||
|
) {
|
||||||
|
delete p.ui.popup.file.entry[k];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const tree: NodeModel<FEntry>[] = p.ui.popup.file.tree;
|
||||||
tree.length = 0;
|
tree.length = 0;
|
||||||
tree.push({ id: "/", text: "/", parent: "" });
|
tree.push({ id: "/", text: "/", parent: "" });
|
||||||
const added = new Set<string>(["/"]);
|
const added = new Set<string>(["/"]);
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue