Skip to content

Commit 158b79e

Browse files
committed
debug new api /tree
1 parent 76a5614 commit 158b79e

File tree

1 file changed

+3
-23
lines changed

1 file changed

+3
-23
lines changed

web_src/js/features/repo-view-file-tree-sidebar.ts

Lines changed: 3 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -28,10 +28,10 @@ async function toggleSidebar(visibility) {
2828
});
2929
}
3030

31-
async function loadChildren(item?) {
31+
async function loadChildren(item, recursive?: boolean) {
3232
const el = document.querySelector('#view-file-tree');
3333
const apiBaseUrl = el.getAttribute('data-api-base-url');
34-
const response = await GET(`${apiBaseUrl}/contents/${item ? item.path : ''}`);
34+
const response = await GET(`${apiBaseUrl}/tree/${item ? item.path : ''}?recursive=${recursive ?? false}`);
3535
const json = await response.json();
3636
if (json instanceof Array) {
3737
return json.map((i) => ({
@@ -44,26 +44,6 @@ async function loadChildren(item?) {
4444
return null;
4545
}
4646

47-
async function loadRecursive(treePath) {
48-
let root = null;
49-
let parent = null;
50-
let parentPath = '';
51-
for (const i of (`/${treePath}`).split('/')) {
52-
const path = `${parentPath}${parentPath ? '/' : ''}${i}`;
53-
const result = await loadChildren({path});
54-
if (root === null) {
55-
root = result;
56-
parent = root;
57-
} else {
58-
parent = parent.find((item) => item.path === path);
59-
parent.children = result;
60-
parent = result;
61-
}
62-
parentPath = path;
63-
}
64-
return root;
65-
}
66-
6747
async function loadContent(item) {
6848
document.querySelector('.repo-home-filelist').innerHTML = `load content of ${item.path}`;
6949
}
@@ -84,7 +64,7 @@ export async function initViewFileTreeSidebar() {
8464
const treePath = fileTree.getAttribute('data-tree-path');
8565
const selectedItem = ref(treePath);
8666

87-
const files = await loadRecursive(treePath);
67+
const files = await loadChildren({path: treePath}, true);
8868

8969
fileTree.classList.remove('center');
9070
const fileTreeView = createApp(ViewFileTree, {files, selectedItem, loadChildren, loadContent: (item) => {

0 commit comments

Comments
 (0)