diff --git a/src/lib/components/chat/Tabs/GitIssues.svelte b/src/lib/components/chat/Tabs/GitIssues.svelte index 2333b3ebe4..3f762c6957 100644 --- a/src/lib/components/chat/Tabs/GitIssues.svelte +++ b/src/lib/components/chat/Tabs/GitIssues.svelte @@ -44,6 +44,9 @@ let selected: Issue | null = null; let state = 'open'; let search = ''; + // The search GitHub ran for the loaded list. Servers that can't search leave it empty. + let searched = ''; + let searchTimer: ReturnType | undefined; let listLoading = false; let loading = false; let busy = false; @@ -62,9 +65,14 @@ { value: 'closed', label: $i18n.t('Closed') }, { value: 'all', label: $i18n.t('All') } ]; - $: filtered = issues.filter((issue) => - `${issue.number} ${issue.title}`.toLowerCase().includes(search.toLowerCase()) - ); + // Filter what's loaded right away; GitHub's results replace it once they arrive. + $: filtered = + search.trim() === searched + ? issues + : issues.filter((issue) => + `${issue.number} ${issue.title}`.toLowerCase().includes(search.trim().toLowerCase()) + ); + $: queueSearch(search); $: showingDetail = !!selected || creating || editing; const status = (issue: Issue) => @@ -100,13 +108,27 @@ params: Record = {}, payload?: Record ) => gitRequest(target, directory, `issue/${operation}`, params, payload); + let requested = ''; + const queueSearch = (value: string) => { + if (value.trim() === requested) return; + requested = value.trim(); + clearTimeout(searchTimer); + searchTimer = setTimeout(() => void load(), 300); + }; const load = async () => { const version = ++listGeneration; listLoading = true; listError = ''; try { - const data = await request<{ items: Issue[] }>('list', { state }); - if (version === listGeneration) issues = data.items; + const query = search.trim(); + const data = await request<{ items: Issue[]; search?: string }>( + 'list', + query ? { state, search: query } : { state } + ); + if (version === listGeneration) { + issues = data.items; + searched = data.search ?? ''; + } } catch (reason) { if (version === listGeneration) listError = String(reason instanceof Error ? reason.message : reason); @@ -180,6 +202,7 @@ void load(); }); onDestroy(() => { + clearTimeout(searchTimer); ++generation; ++listGeneration; }); @@ -256,7 +279,7 @@ {#if !filtered.length}
- {$i18n.t(listLoading ? 'Loading...' : 'No issues')} + {$i18n.t(listLoading ? 'Loading...' : search.trim() ? 'No results found' : 'No issues')}
{/if} diff --git a/src/lib/components/chat/Tabs/GitPullRequests.svelte b/src/lib/components/chat/Tabs/GitPullRequests.svelte index 5036d851a9..65aae8bcdf 100644 --- a/src/lib/components/chat/Tabs/GitPullRequests.svelte +++ b/src/lib/components/chat/Tabs/GitPullRequests.svelte @@ -67,6 +67,9 @@ let selected: PullRequest | null = null; let state = 'open'; let search = ''; + // The search GitHub ran for the loaded list. Servers that can't search leave it empty. + let searched = ''; + let searchTimer: ReturnType | undefined; let view: 'summary' | 'code' | 'checks' | 'activity' = 'summary'; let diff = ''; let listLoading = false; @@ -112,9 +115,14 @@ approve: $i18n.t('Approve'), 'request-changes': $i18n.t('Request changes') } as Record; - $: filtered = prs.filter((pr) => - `${pr.number} ${pr.title}`.toLowerCase().includes(search.toLowerCase()) - ); + // Filter what's loaded right away; GitHub's results replace it once they arrive. + $: filtered = + search.trim() === searched + ? prs + : prs.filter((pr) => + `${pr.number} ${pr.title}`.toLowerCase().includes(search.trim().toLowerCase()) + ); + $: queueSearch(search); $: showingDetail = !!selected || creating || editing; $: failingChecks = (selected?.statusCheckRollup ?? []).filter( (check) => checkOutcome(check) === 'fail' @@ -164,13 +172,27 @@ params: Record = {}, payload?: Record ) => gitRequest(target, directory, `pr/${operation}`, params, payload); + let requested = ''; + const queueSearch = (value: string) => { + if (value.trim() === requested) return; + requested = value.trim(); + clearTimeout(searchTimer); + searchTimer = setTimeout(() => void load(), 300); + }; const load = async () => { const version = ++listGeneration; listLoading = true; listError = ''; try { - const data = await request<{ items: PullRequest[] }>('list', { state }); - if (version === listGeneration) prs = data.items; + const query = search.trim(); + const data = await request<{ items: PullRequest[]; search?: string }>( + 'list', + query ? { state, search: query } : { state } + ); + if (version === listGeneration) { + prs = data.items; + searched = data.search ?? ''; + } } catch (reason) { if (version === listGeneration) listError = String(reason instanceof Error ? reason.message : reason); @@ -267,6 +289,7 @@ void load(); }); onDestroy(() => { + clearTimeout(searchTimer); ++generation; ++listGeneration; }); @@ -347,7 +370,9 @@ {#if !filtered.length}
- {$i18n.t(listLoading ? 'Loading...' : 'No pull requests')} + {$i18n.t( + listLoading ? 'Loading...' : search.trim() ? 'No results found' : 'No pull requests' + )}
{/if}