Skip to content

Commit 2a8f9c8

Browse files
committed
fix
1 parent a1cee9e commit 2a8f9c8

File tree

3 files changed

+24
-13
lines changed

3 files changed

+24
-13
lines changed

templates/repo/home.tmpl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
{{$hasAndShowTreeSidebar := and $hasTreeSidebar $showTreeSidebar}}
99
<div role="main" aria-label="{{.Title}}" class="page-content repository file list {{if .IsBlame}}blame{{end}}">
1010
{{template "repo/header" .}}
11-
<div class="ui container {{if .IsBlame}}fluid padded{{end}}">
11+
<div class="ui container {{if or $hasTreeSidebar .IsBlame}}fluid padded{{end}}">
1212
{{template "base/alert" .}}
1313

1414
{{if .Repository.IsArchived}}

templates/repo/view_file_tree_sidebar.tmpl

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,10 @@
1+
{{$branchDropdownCurrentRefType := "branch"}}
2+
{{$branchDropdownCurrentRefShortName := .BranchName}}
3+
{{if .IsViewTag}}
4+
{{$branchDropdownCurrentRefType = "tag"}}
5+
{{$branchDropdownCurrentRefShortName = .TagName}}
6+
{{end}}
7+
18
<div class="view-file-tree-sidebar-top">
29
<div class="sidebar-header">
310
<button class="hide-tree-sidebar-button ui compact basic button icon" title="{{ctx.Locale.Tr "repo.diff.hide_file_tree"}}">
@@ -6,12 +13,6 @@
613
<b> Files</b>
714
</div>
815
<div class="sidebar-ref">
9-
{{$branchDropdownCurrentRefType := "branch"}}
10-
{{$branchDropdownCurrentRefShortName := .BranchName}}
11-
{{if .IsViewTag}}
12-
{{$branchDropdownCurrentRefType = "tag"}}
13-
{{$branchDropdownCurrentRefShortName = .TagName}}
14-
{{end}}
1516
{{template "repo/branch_dropdown" dict
1617
"Repository" .Repository
1718
"ShowTabBranches" true
@@ -59,5 +60,10 @@
5960
</div>
6061
</div>
6162
<div class="view-file-tree-sidebar-bottom">
62-
<div id="view-file-tree" class="is-loading" data-api-base-url="{{.RepoLink}}" data-tree-path="{{$.TreePath}}"></div>
63+
<div id="view-file-tree" class="is-loading"
64+
data-api-base-url="{{.RepoLink}}"
65+
data-tree-path="{{$.TreePath}}"
66+
data-current-ref-type="{{$branchDropdownCurrentRefType}}"
67+
data-current-ref-short-name="{{$branchDropdownCurrentRefShortName}}"
68+
></div>
6369
</div>

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

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,11 @@ async function toggleSidebar(visibility) {
2929
}
3030

3131
async function loadChildren(item, recursive?: boolean) {
32-
const el = document.querySelector('#view-file-tree');
33-
const apiBaseUrl = el.getAttribute('data-api-base-url');
34-
const response = await GET(`${apiBaseUrl}/tree/${item ? item.path : ''}?ref=&recursive=${recursive ?? false}`);
32+
const fileTree = document.querySelector('#view-file-tree');
33+
const apiBaseUrl = fileTree.getAttribute('data-api-base-url');
34+
const refType = fileTree.getAttribute('data-current-ref-type');
35+
const refName = fileTree.getAttribute('data-current-ref-short-name');
36+
const response = await GET(`${apiBaseUrl}/tree/${item ? item.path : ''}?ref=${refType}/${refName}&recursive=${recursive ?? false}`);
3537
const json = await response.json();
3638
if (json instanceof Array) {
3739
return json.map((i) => ({
@@ -64,15 +66,18 @@ export async function initViewFileTreeSidebar() {
6466
});
6567

6668
const fileTree = document.querySelector('#view-file-tree');
69+
const baseUrl = fileTree.getAttribute('data-api-base-url');
6770
const treePath = fileTree.getAttribute('data-tree-path');
68-
const basePath = window.location.href.replace(treePath, '');
71+
const refType = fileTree.getAttribute('data-current-ref-type');
72+
const refName = fileTree.getAttribute('data-current-ref-short-name');
73+
6974
const selectedItem = ref(treePath);
7075

7176
const files = await loadChildren({path: treePath}, true);
7277

7378
fileTree.classList.remove('is-loading');
7479
const fileTreeView = createApp(ViewFileTree, {files, selectedItem, loadChildren, loadContent: (item) => {
75-
window.history.pushState(null, null, `${basePath}${item.path}`);
80+
window.history.pushState(null, null, `${baseUrl}/src/${refType}/${refName}/${item.path}`);
7681
selectedItem.value = item.path;
7782
loadContent(item);
7883
}});

0 commit comments

Comments
 (0)