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
+8 -4
View File
@@ -3,9 +3,13 @@ import {hideElem, queryElemChildren, showElem} from '../utils/dom.ts';
import {POST} from '../modules/fetch.ts';
import {showErrorToast, type Toast} from '../modules/toast.ts';
import {fomanticQuery} from '../modules/fomantic/base.ts';
import type {FomanticApiResponse, JQueryElem} from '../types.ts';
const {appSubUrl} = window.config;
type TopicSearchResponse = {topics: Array<{topic_name: string}>};
type TopicSearchResult = {description: string, 'data-value': string};
export function initRepoTopicBar() {
const mgrBtn = document.querySelector<HTMLButtonElement>('#manage_topic');
if (!mgrBtn) return;
@@ -87,10 +91,10 @@ export function initRepoTopicBar() {
apiSettings: {
url: `${appSubUrl}/explore/topics/search?q={query}`,
throttle: 500,
onResponse(this: any, res: any) {
const formattedResponse = {
onResponse(this: {urlData: {query: string}}, res: TopicSearchResponse) {
const formattedResponse: FomanticApiResponse<TopicSearchResult> = {
success: false,
results: [] as Array<Record<string, any>>,
results: [],
};
const query = stripTags(this.urlData.query.trim());
let found_query = false;
@@ -134,7 +138,7 @@ export function initRepoTopicBar() {
this.attr('data-value', value).contents().first().replaceWith(value);
return fomanticQuery(this);
},
onAdd(addedValue: string, _addedText: any, $addedChoice: any) {
onAdd(addedValue: string, _addedText: any, $addedChoice: JQueryElem) {
addedValue = addedValue.toLowerCase().trim();
$addedChoice[0].setAttribute('data-value', addedValue);
$addedChoice[0].setAttribute('data-text', addedValue);