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:
@@ -235,7 +235,7 @@ export function autosize(textarea: HTMLTextAreaElement, {viewportMarginBottom =
|
||||
};
|
||||
}
|
||||
|
||||
export function onInputDebounce(fn: () => Promisable<any>) {
|
||||
export function onInputDebounce(fn: () => Promisable<void>) {
|
||||
return debounce(fn, 300);
|
||||
}
|
||||
|
||||
@@ -277,7 +277,7 @@ export function createElementFromHTML<T extends Element>(htmlString: string): T
|
||||
return div.firstChild as T;
|
||||
}
|
||||
|
||||
export function createElementFromAttrs<T extends HTMLElement>(tagName: string, attrs: Record<string, any> | null, ...children: (Node | string)[]): T {
|
||||
export function createElementFromAttrs<T extends HTMLElement>(tagName: string, attrs: Record<string, string | number | boolean | null | undefined> | null, ...children: (Node | string)[]): T {
|
||||
const el = document.createElement(tagName);
|
||||
for (const [key, value] of Object.entries(attrs || {})) {
|
||||
if (value === undefined || value === null) continue;
|
||||
|
||||
@@ -25,7 +25,7 @@ export type TimedFunction<T extends (...args: Array<any>) => any> = ((...args: P
|
||||
function createTimed<T extends (...args: Array<any>) => any>(func: T, wait: number, leading: boolean, trailing: boolean, isThrottle: boolean): TimedFunction<T> {
|
||||
let timer: TimeoutId | null = null;
|
||||
let pendingArgs: Parameters<T> | null = null;
|
||||
let resolvers: Array<{resolve: (value: any) => void, reject: (reason: any) => void}> = [];
|
||||
let resolvers: Array<{resolve: (value: Awaited<ReturnType<T>>) => void, reject: (reason: any) => void}> = [];
|
||||
|
||||
const invoke = async (args: Parameters<T>): Promise<void> => {
|
||||
const settling = resolvers;
|
||||
|
||||
@@ -71,11 +71,11 @@ export async function matchMention(mentionsUrl: string, queryText: string): Prom
|
||||
return sortAndReduce(results);
|
||||
}
|
||||
|
||||
export async function matchIssue(owner: string, repo: string, issueIndexStr: string, query: string, signal: AbortSignal): Promise<Issue[]> {
|
||||
export async function matchIssue(owner: string, repo: string, issueIndexStr: string | undefined, query: string, signal: AbortSignal): Promise<Issue[]> {
|
||||
const res = await GET(`${window.config.appSubUrl}/${owner}/${repo}/issues/suggestions?q=${encodeURIComponent(query)}`, {signal});
|
||||
|
||||
const issues: Issue[] = await res.json();
|
||||
const issueNumber = parseInt(issueIndexStr);
|
||||
const issueNumber = parseInt(issueIndexStr || '');
|
||||
|
||||
// filter out issue with same id
|
||||
return issues.filter((i) => i.number !== issueNumber);
|
||||
|
||||
@@ -54,7 +54,7 @@ export type DayDataObject = {
|
||||
};
|
||||
|
||||
export function fillEmptyStartDaysWithZeroes(startDays: number[], data: DayDataObject): DayData[] {
|
||||
const result: Record<string, any> = {};
|
||||
const result: DayDataObject = {};
|
||||
|
||||
for (const startDay of startDays) {
|
||||
result[startDay] = data[startDay] || {'week': startDay, 'additions': 0, 'deletions': 0, 'commits': 0};
|
||||
|
||||
Reference in New Issue
Block a user