Add indexed history search across iOS and web
TestFlight / Build and upload (push) Successful in 1m55s
TestFlight / Build and upload (push) Successful in 1m55s
This commit is contained in:
@@ -0,0 +1,24 @@
|
||||
import type { WorkspaceSearchResponse } from "./api";
|
||||
|
||||
// Cleanup cancels both the debounce and fetch, and also rejects late responses
|
||||
// from transports that finish after cancellation.
|
||||
export function scheduleWorkspaceSearch(
|
||||
query: string,
|
||||
request: (query: string, signal: AbortSignal) => Promise<WorkspaceSearchResponse>,
|
||||
onResult: (result: WorkspaceSearchResponse) => void,
|
||||
onError: (error: unknown) => void
|
||||
) {
|
||||
const controller = new AbortController();
|
||||
const timer = setTimeout(async () => {
|
||||
try {
|
||||
const result = await request(query, controller.signal);
|
||||
if (!controller.signal.aborted) onResult(result);
|
||||
} catch (error) {
|
||||
if (!controller.signal.aborted) onError(error);
|
||||
}
|
||||
}, 300);
|
||||
return () => {
|
||||
clearTimeout(timer);
|
||||
controller.abort();
|
||||
};
|
||||
}
|
||||
Reference in New Issue
Block a user