refactor: improve types in the frontend, misc fixes (#39142)

This commit is contained in:
silverwind
2026-08-31 04:12:25 -07:00
committed by GitHub
parent 535fc29ae8
commit 7c93ead628
46 changed files with 392 additions and 217 deletions
+6 -3
View File
@@ -1,11 +1,14 @@
import {hideElem, showElem, toggleElem} from '../utils/dom.ts';
import {GET} from '../modules/fetch.ts';
type GitRef = {name: string, web_link: string};
type RefsResponse = {tags: GitRef[], branches: GitRef[], default_branch: string};
async function loadBranchesAndTags(area: Element, loadingButton: Element) {
loadingButton.classList.add('disabled');
try {
const res = await GET(loadingButton.getAttribute('data-url')!);
const data = await res.json();
const data: RefsResponse = await res.json();
hideElem(loadingButton);
addTags(area, data.tags);
addBranches(area, data.branches, data.default_branch);
@@ -15,7 +18,7 @@ async function loadBranchesAndTags(area: Element, loadingButton: Element) {
}
}
function addTags(area: Element, tags: Array<Record<string, any>>) {
function addTags(area: Element, tags: GitRef[]) {
const tagArea = area.querySelector('.tag-area')!;
toggleElem(tagArea.parentElement!, tags.length > 0);
for (const tag of tags) {
@@ -23,7 +26,7 @@ function addTags(area: Element, tags: Array<Record<string, any>>) {
}
}
function addBranches(area: Element, branches: Array<Record<string, any>>, defaultBranch: string) {
function addBranches(area: Element, branches: GitRef[], defaultBranch: string) {
const defaultBranchTooltip = area.getAttribute('data-text-default-branch-tooltip');
const branchArea = area.querySelector('.branch-area')!;
toggleElem(branchArea.parentElement!, branches.length > 0);