This commit is contained in:
Kerwin Bryant
2025-01-06 03:20:42 +00:00
parent ad9b126ad6
commit c949f42d4d
4 changed files with 111 additions and 139 deletions
@@ -2,23 +2,17 @@ import {createApp, ref} from 'vue';
import {toggleElem} from '../utils/dom.ts';
import {GET, PUT} from '../modules/fetch.ts';
import ViewFileTree from '../components/ViewFileTree.vue';
import RepoBranchTagSelector from '../components/RepoBranchTagSelector.vue';
import {initGlobalDropdown} from './common-page.ts';
async function toggleSidebar(visibility) {
const sidebarEl = document.querySelector('.repo-view-file-tree-sidebar');
const showBtnEl = document.querySelector('.show-tree-sidebar-button');
const refSelectorEl = document.querySelector('.repo-home-filelist .js-branch-tag-selector');
const newPrBtnEl = document.querySelector('.repo-home-filelist #new-pull-request');
const addFileEl = document.querySelector('.repo-home-filelist .add-file-dropdown');
const containerClassList = sidebarEl.parentElement.classList;
containerClassList.toggle('repo-grid-tree-sidebar', visibility);
containerClassList.toggle('repo-grid-filelist-only', !visibility);
toggleElem(sidebarEl, visibility);
toggleElem(showBtnEl, !visibility);
toggleElem(refSelectorEl, !visibility);
toggleElem(newPrBtnEl, !visibility);
if (addFileEl) {
toggleElem(addFileEl, !visibility);
}
// save to session
await PUT('/repo/preferences', {
@@ -46,24 +40,34 @@ async function loadChildren(item, recursive?: boolean) {
return null;
}
async function loadContent(item) {
// todo: change path of `repo_path` `path_history`
async function loadContent() {
// load content by path (content based on home_content.tmpl)
const response = await GET(`${window.location.href}?only_content=true`);
document.querySelector('#path_content').innerHTML = await response.text();
document.querySelector('.repo-home-filelist').innerHTML = await response.text();
reloadContentScript();
}
function reloadContentScript() {
document.querySelector('.repo-home-filelist .show-tree-sidebar-button').addEventListener('click', () => {
toggleSidebar(true);
});
const refSelectorEl = document.querySelector('.repo-home-filelist .js-branch-tag-selector');
if (refSelectorEl) {
createApp(RepoBranchTagSelector, {elRoot: refSelectorEl}).mount(refSelectorEl);
}
initGlobalDropdown();
}
export async function initViewFileTreeSidebar() {
const sidebarElement = document.querySelector('.repo-view-file-tree-sidebar');
if (!sidebarElement) return;
document.querySelector('.show-tree-sidebar-button').addEventListener('click', () => {
toggleSidebar(true);
});
document.querySelector('.hide-tree-sidebar-button').addEventListener('click', () => {
toggleSidebar(false);
});
document.querySelector('.repo-home-filelist .show-tree-sidebar-button').addEventListener('click', () => {
toggleSidebar(true);
});
const fileTree = document.querySelector('#view-file-tree');
const baseUrl = fileTree.getAttribute('data-api-base-url');
@@ -79,7 +83,7 @@ export async function initViewFileTreeSidebar() {
const fileTreeView = createApp(ViewFileTree, {files, selectedItem, loadChildren, loadContent: (item) => {
window.history.pushState(null, null, `${baseUrl}/src/${refType}/${refName}/${item.path}`);
selectedItem.value = item.path;
loadContent(item);
loadContent();
}});
fileTreeView.mount(fileTree);
}