mirror of
https://github.com/go-gitea/gitea.git
synced 2026-10-23 16:44:41 +02:00
Convert search box to imperative attach API
- attachSearchBox(el, url, parse) replaces the await-style chooseFromApi - The component handles input update + change-event dispatch on selection, so callers don't loop or write back the value themselves - Each caller is now a single statement; response shape is conveyed via the parse callback's parameter annotation (T inferred) Co-Authored-By: Claude (Opus 4.7) <noreply@anthropic.com>
This commit is contained in:
4 files changed
+112
-132
No files matched your search
@@ -1,22 +1,16 @@
|
||||
import {chooseFromApi} from '../../modules/search.ts';
|
||||
import {attachSearchBox} from '../../modules/search.ts';
|
||||
|
||||
const {appSubUrl} = window.config;
|
||||
|
||||
type RepoSearchResponse = {data: Array<{repository: {full_name: string}}>};
|
||||
|
||||
export async function initCompSearchRepoBox(el: HTMLElement) {
|
||||
export function initCompSearchRepoBox(el: HTMLElement) {
|
||||
const uid = el.getAttribute('data-uid');
|
||||
const exclusive = el.getAttribute('data-exclusive');
|
||||
let url = `${appSubUrl}/repo/search?q={query}&uid=${uid}`;
|
||||
if (exclusive === 'true') url += `&exclusive=true`;
|
||||
const input = el.querySelector<HTMLInputElement>('input.prompt')!;
|
||||
|
||||
while (el.isConnected) {
|
||||
const pick = await chooseFromApi<RepoSearchResponse>(el, url, (response) => response.data.map((item) => ({
|
||||
title: item.repository.full_name.split('/')[1],
|
||||
description: item.repository.full_name,
|
||||
})));
|
||||
input.value = pick.title;
|
||||
input.dispatchEvent(new Event('change', {bubbles: true}));
|
||||
}
|
||||
attachSearchBox(el, url, (response: RepoSearchResponse) => response.data.map((item) => ({
|
||||
title: item.repository.full_name.split('/')[1],
|
||||
description: item.repository.full_name,
|
||||
})));
|
||||
}
|
||||
Reference in new issue
Block a user