Fixed multi-window model sync

This commit is contained in:
Gregory Schier
2023-04-09 22:32:47 -07:00
parent e85dd32005
commit 6bc1f9f494
2 changed files with 11 additions and 19 deletions

View File

@@ -1,7 +1,5 @@
import { useQueryClient } from '@tanstack/react-query'; import { useQueryClient } from '@tanstack/react-query';
import { appWindow } from '@tauri-apps/api/window'; import { appWindow } from '@tauri-apps/api/window';
import { useActiveRequestId } from '../hooks/useActiveRequestId';
import { useDuplicateRequest } from '../hooks/useDuplicateRequest';
import { keyValueQueryKey } from '../hooks/useKeyValue'; import { keyValueQueryKey } from '../hooks/useKeyValue';
import { requestsQueryKey } from '../hooks/useRequests'; import { requestsQueryKey } from '../hooks/useRequests';
import { useRequestUpdateKey } from '../hooks/useRequestUpdateKey'; import { useRequestUpdateKey } from '../hooks/useRequestUpdateKey';
@@ -17,14 +15,6 @@ export function GlobalHooks() {
const queryClient = useQueryClient(); const queryClient = useQueryClient();
const { wasUpdatedExternally } = useRequestUpdateKey(null); const { wasUpdatedExternally } = useRequestUpdateKey(null);
const activeRequestId = useActiveRequestId();
const duplicateRequest = useDuplicateRequest({ id: activeRequestId, navigateAfter: true });
// TODO: Put this somewhere better
useTauriEvent('duplicate_request', () => {
duplicateRequest.mutate();
});
useTauriEvent<Model>('created_model', ({ payload, windowLabel }) => { useTauriEvent<Model>('created_model', ({ payload, windowLabel }) => {
if (shouldIgnoreEvent(payload, windowLabel)) return; if (shouldIgnoreEvent(payload, windowLabel)) return;
@@ -40,9 +30,7 @@ export function GlobalHooks() {
: null; : null;
if (queryKey === null) { if (queryKey === null) {
if (payload.model) { console.log('Unrecognized created model:', payload);
console.log('Unrecognized created model:', payload);
}
return; return;
} }
@@ -66,9 +54,7 @@ export function GlobalHooks() {
: null; : null;
if (queryKey === null) { if (queryKey === null) {
if (payload.model) { console.log('Unrecognized updated model:', payload);
console.log('Unrecognized updated model:', payload);
}
return; return;
} }
@@ -125,7 +111,8 @@ const shouldIgnoreEvent = (payload: Model, windowLabel: string) =>
windowLabel === appWindow.label && payload.model !== 'http_response'; windowLabel === appWindow.label && payload.model !== 'http_response';
const shouldIgnoreModel = (payload: Model) => { const shouldIgnoreModel = (payload: Model) => {
if (payload.model === 'http_response') return false; if (payload.model === 'key_value') {
if (payload.model === 'key_value' && payload.namespace === NAMESPACE_NO_SYNC) return false; return payload.namespace === NAMESPACE_NO_SYNC;
return true; }
return false;
}; };

View File

@@ -24,6 +24,11 @@ export function RequestActionsDropdown({ requestId, children }: Props) {
dropdownRef.current?.toggle(); dropdownRef.current?.toggle();
}); });
// TODO: Put this somewhere better
useTauriEvent('duplicate_request', () => {
duplicateRequest.mutate();
});
return ( return (
<Dropdown <Dropdown
ref={dropdownRef} ref={dropdownRef}