Skip to content

Commit e45940d

Browse files
committed
add tree sidebar to file view
1 parent 59e46d4 commit e45940d

File tree

3 files changed

+17
-11
lines changed

3 files changed

+17
-11
lines changed

web_src/js/components/ViewFileTree.vue

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,16 @@ import ViewFileTreeItem from './ViewFileTreeItem.vue';
33
44
defineProps<{
55
files: any,
6-
selectedItem: string,
6+
selectedItem: any,
77
loadChildren: any,
8+
loadContent: any;
89
}>();
910
</script>
1011

1112
<template>
1213
<div class="view-file-tree-items">
1314
<!-- only render the tree if we're visible. in many cases this is something that doesn't change very often -->
14-
<ViewFileTreeItem v-for="item in files" :key="item.name" :item="item" :selected-item="selectedItem" :load-children="loadChildren"/>
15+
<ViewFileTreeItem v-for="item in files" :key="item.name" :item="item" :selected-item="selectedItem" :load-content="loadContent" :load-children="loadChildren"/>
1516
</div>
1617
</template>
1718

web_src/js/components/ViewFileTreeItem.vue

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,14 @@ type Item = {
1212
1313
const props = defineProps<{
1414
item: Item,
15+
loadContent: any;
1516
loadChildren: any;
16-
selectedItem?: string;
17+
selectedItem?: any;
1718
}>();
1819
1920
const isLoading = ref(false);
20-
const collapsed = ref(!props.item.children);
2121
const children = ref(props.item.children);
22+
const collapsed = ref(!props.item.children);
2223
2324
const doLoadChildren = async () => {
2425
collapsed.value = !collapsed.value;
@@ -32,19 +33,19 @@ const doLoadChildren = async () => {
3233
3334
const doLoadDirContent = () => {
3435
doLoadChildren();
35-
window.location.href = props.item.htmlUrl;
36+
props.loadContent(props.item);
3637
};
3738
3839
const doLoadFileContent = () => {
39-
window.location.href = props.item.htmlUrl;
40+
props.loadContent(props.item);
4041
};
4142
</script>
4243

4344
<template>
4445
<!--title instead of tooltip above as the tooltip needs too much work with the current methods, i.e. not being loaded or staying open for "too long"-->
4546
<div
4647
v-if="item.isFile" class="item-file"
47-
:class="{'selected': selectedItem === item.path}"
48+
:class="{'selected': selectedItem.value === item.path}"
4849
:title="item.name"
4950
@click.stop="doLoadFileContent"
5051
>
@@ -54,7 +55,7 @@ const doLoadFileContent = () => {
5455
</div>
5556
<div
5657
v-else class="item-directory"
57-
:class="{'selected': selectedItem === item.path}"
58+
:class="{'selected': selectedItem.value === item.path}"
5859
:title="item.name"
5960
@click.stop="doLoadDirContent"
6061
>
@@ -66,7 +67,7 @@ const doLoadFileContent = () => {
6667
</div>
6768

6869
<div v-if="children?.length" v-show="!collapsed" class="sub-items">
69-
<ViewFileTreeItem v-for="childItem in children" :key="childItem.name" :item="childItem" :selected-item="selectedItem" :load-children="loadChildren"/>
70+
<ViewFileTreeItem v-for="childItem in children" :key="childItem.name" :item="childItem" :selected-item="selectedItem" :load-content="loadContent" :load-children="loadChildren"/>
7071
</div>
7172
</template>
7273
<style scoped>

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

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import {createApp} from 'vue';
1+
import {createApp, ref} from 'vue';
22
import {toggleElem} from '../utils/dom.ts';
33
import {GET, PUT} from '../modules/fetch.ts';
44
import ViewFileTree from '../components/ViewFileTree.vue';
@@ -78,10 +78,14 @@ export async function initViewFileTreeSidebar() {
7878

7979
const fileTree = document.querySelector('#view-file-tree');
8080
const treePath = fileTree.getAttribute('data-tree-path');
81+
const selectedItem = ref(treePath);
8182

8283
const files = await loadRecursive(treePath);
8384

8485
fileTree.classList.remove('center');
85-
const fileTreeView = createApp(ViewFileTree, {files, selectedItem: treePath, loadChildren});
86+
const fileTreeView = createApp(ViewFileTree, {files, selectedItem, loadChildren, loadContent: (item) => {
87+
window.history.pushState(null, null, item.htmlUrl);
88+
selectedItem.value = item.path;
89+
}});
8690
fileTreeView.mount(fileTree);
8791
}

0 commit comments

Comments
 (0)