Skip to content

Commit 84e2d70

Browse files
committed
fix nav bug
1 parent a585ab7 commit 84e2d70

File tree

2 files changed

+17
-12
lines changed

2 files changed

+17
-12
lines changed

web_src/js/components/ViewFileTree.vue

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -21,12 +21,17 @@ async function loadChildren(treePath: string, subPath: string = '') {
2121
return json.fileTreeNodes ?? null;
2222
}
2323
24-
async function loadViewContent(treePath: string) {
25-
// load content by path (content based on home_content.tmpl)
26-
window.history.pushState({treePath}, null, `${props.repoLink}/src/${props.currentRefNameSubURL}/${pathEscapeSegments(treePath)}`);
27-
const response = await GET(`${window.location.href}?only_content=true`);
28-
const contentEl = document.querySelector('.repo-view-content');
29-
contentEl.innerHTML = await response.text();
24+
async function loadViewContent(url: string) {
25+
url = url.includes('?') ? url.replace('?', '?only_content=true') : `${url}?only_content=true`;
26+
const response = await GET(url);
27+
document.querySelector('.repo-view-content').innerHTML = await response.text();
28+
}
29+
30+
async function navigateTreeView(treePath: string) {
31+
const url = `${props.repoLink}/src/${props.currentRefNameSubURL}/${pathEscapeSegments(treePath)}`;
32+
window.history.pushState({treePath, url}, null, url);
33+
selectedItem.value = treePath;
34+
await loadViewContent(url);
3035
}
3136
3237
onMounted(async () => {
@@ -35,15 +40,15 @@ onMounted(async () => {
3540
elRoot.value.closest('.is-loading')?.classList?.remove('is-loading');
3641
window.addEventListener('popstate', (e) => {
3742
selectedItem.value = e.state?.treePath || '';
38-
loadViewContent(selectedItem.value);
43+
if (e.state?.url) loadViewContent(e.state.url);
3944
});
4045
});
4146
</script>
4247

4348
<template>
4449
<div class="view-file-tree-items" ref="elRoot">
4550
<!-- only render the tree if we're visible. in many cases this is something that doesn't change very often -->
46-
<ViewFileTreeItem v-for="item in files" :key="item.name" :item="item" :selected-item="selectedItem" :load-content="loadViewContent" :load-children="loadChildren"/>
51+
<ViewFileTreeItem v-for="item in files" :key="item.name" :item="item" :selected-item="selectedItem" :navigate-view-content="navigateTreeView" :load-children="loadChildren"/>
4752
</div>
4853
</template>
4954

web_src/js/components/ViewFileTreeItem.vue

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ type Item = {
1212
1313
const props = defineProps<{
1414
item: Item,
15-
loadContent: any;
15+
navigateViewContent: any;
1616
loadChildren: any;
1717
selectedItem?: any;
1818
}>();
@@ -35,11 +35,11 @@ const doLoadChildren = async () => {
3535
3636
const doLoadDirContent = () => {
3737
doLoadChildren();
38-
props.loadContent(props.item.fullPath);
38+
props.navigateViewContent(props.item.fullPath);
3939
};
4040
4141
const doLoadFileContent = () => {
42-
props.loadContent(props.item.fullPath);
42+
props.navigateViewContent(props.item.fullPath);
4343
};
4444
4545
const doGotoSubModule = () => {
@@ -102,7 +102,7 @@ const doGotoSubModule = () => {
102102
</div>
103103

104104
<div v-if="children?.length" v-show="!collapsed" class="sub-items">
105-
<ViewFileTreeItem v-for="childItem in children" :key="childItem.entryName" :item="childItem" :selected-item="selectedItem" :load-content="loadContent" :load-children="loadChildren"/>
105+
<ViewFileTreeItem v-for="childItem in children" :key="childItem.entryName" :item="childItem" :selected-item="selectedItem" :navigate-view-content="navigateViewContent" :load-children="loadChildren"/>
106106
</div>
107107
</template>
108108
<style scoped>

0 commit comments

Comments
 (0)