1
1
mirror of https://github.com/go-gitea/gitea synced 2025-12-06 21:08:25 +00:00
Files
gitea/web_src/js/features/repo-view-file-tree.ts
silverwind 46d7adefe0 Enable TypeScript strictNullChecks (#35843)
A big step towards enabling strict mode in Typescript.

There was definitely a good share of potential bugs while refactoring
this. When in doubt, I opted to keep the potentially broken behaviour.
Notably, the `DOMEvent` type is gone, it was broken and we're better of
with type assertions on `e.target`.

---------

Signed-off-by: silverwind <me@silverwind.io>
Signed-off-by: wxiaoguang <wxiaoguang@gmail.com>
Co-authored-by: delvh <dev.lh@web.de>
Co-authored-by: wxiaoguang <wxiaoguang@gmail.com>
2025-12-03 02:13:16 +00:00

42 lines
1.6 KiB
TypeScript

import {createApp} from 'vue';
import {toggleElem} from '../utils/dom.ts';
import {POST} from '../modules/fetch.ts';
import ViewFileTree from '../components/ViewFileTree.vue';
import {registerGlobalEventFunc} from '../modules/observer.ts';
const {appSubUrl} = window.config;
function isUserSignedIn() {
return Boolean(document.querySelector('#navbar .user-menu'));
}
async function toggleSidebar(btn: HTMLElement) {
const elToggleShow = document.querySelector('.repo-view-file-tree-toggle[data-toggle-action="show"]')!;
const elFileTreeContainer = document.querySelector('.repo-view-file-tree-container')!;
const shouldShow = btn.getAttribute('data-toggle-action') === 'show';
toggleElem(elFileTreeContainer, shouldShow);
toggleElem(elToggleShow, !shouldShow);
// FIXME: need to remove "full height" style from parent element
if (!isUserSignedIn()) return;
await POST(`${appSubUrl}/user/settings/update_preferences`, {
data: {codeViewShowFileTree: shouldShow},
});
}
export async function initRepoViewFileTree() {
const sidebar = document.querySelector<HTMLElement>('.repo-view-file-tree-container');
const repoViewContent = document.querySelector('.repo-view-content');
if (!sidebar || !repoViewContent) return;
registerGlobalEventFunc('click', 'onRepoViewFileTreeToggle', toggleSidebar);
const fileTree = sidebar.querySelector('#view-file-tree')!;
createApp(ViewFileTree, {
repoLink: fileTree.getAttribute('data-repo-link'),
treePath: fileTree.getAttribute('data-tree-path'),
currentRefNameSubURL: fileTree.getAttribute('data-current-ref-name-sub-url'),
}).mount(fileTree);
}