mirror of
https://github.com/mountain-loop/yaak.git
synced 2026-01-16 08:36:40 +01:00
29 lines
991 B
TypeScript
29 lines
991 B
TypeScript
import { invoke } from '@tauri-apps/api/core';
|
|
import type { HttpResponse, HttpResponseEvent } from '@yaakapp-internal/models';
|
|
import { httpResponseEventsAtom, replaceModelsInStore } from '@yaakapp-internal/models';
|
|
import { useAtomValue } from 'jotai';
|
|
import { useEffect, useMemo } from 'react';
|
|
|
|
export function useHttpResponseEvents(response: HttpResponse | null) {
|
|
const allEvents = useAtomValue(httpResponseEventsAtom);
|
|
|
|
useEffect(() => {
|
|
if (response?.id == null) {
|
|
replaceModelsInStore('http_response_event', []);
|
|
return;
|
|
}
|
|
|
|
invoke<HttpResponseEvent[]>('cmd_get_http_response_events', { responseId: response.id }).then(
|
|
(events) => replaceModelsInStore('http_response_event', events),
|
|
);
|
|
}, [response?.id]);
|
|
|
|
// Filter events for the current response
|
|
const events = useMemo(
|
|
() => allEvents.filter((e) => e.responseId === response?.id),
|
|
[allEvents, response?.id],
|
|
);
|
|
|
|
return { data: events, error: null, isLoading: false };
|
|
}
|