mirror of
https://github.com/go-gitea/gitea.git
synced 2026-09-02 11:03:23 +09:00
refactor: improve types in the frontend, misc fixes (#39142)
This commit is contained in:
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user