From d922dcb06227dbd3c05b3d9c66a4ee122cbd7d23 Mon Sep 17 00:00:00 2001 From: Gregory Schier Date: Sun, 9 Apr 2023 22:32:47 -0700 Subject: [PATCH] Fixed multi-window model sync --- src-web/components/GlobalHooks.tsx | 25 +++++-------------- src-web/components/RequestActionsDropdown.tsx | 5 ++++ 2 files changed, 11 insertions(+), 19 deletions(-) diff --git a/src-web/components/GlobalHooks.tsx b/src-web/components/GlobalHooks.tsx index 74f37bc7..4a345e59 100644 --- a/src-web/components/GlobalHooks.tsx +++ b/src-web/components/GlobalHooks.tsx @@ -1,7 +1,5 @@ import { useQueryClient } from '@tanstack/react-query'; import { appWindow } from '@tauri-apps/api/window'; -import { useActiveRequestId } from '../hooks/useActiveRequestId'; -import { useDuplicateRequest } from '../hooks/useDuplicateRequest'; import { keyValueQueryKey } from '../hooks/useKeyValue'; import { requestsQueryKey } from '../hooks/useRequests'; import { useRequestUpdateKey } from '../hooks/useRequestUpdateKey'; @@ -17,14 +15,6 @@ export function GlobalHooks() { const queryClient = useQueryClient(); 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('created_model', ({ payload, windowLabel }) => { if (shouldIgnoreEvent(payload, windowLabel)) return; @@ -40,9 +30,7 @@ export function GlobalHooks() { : null; if (queryKey === null) { - if (payload.model) { - console.log('Unrecognized created model:', payload); - } + console.log('Unrecognized created model:', payload); return; } @@ -66,9 +54,7 @@ export function GlobalHooks() { : null; if (queryKey === null) { - if (payload.model) { - console.log('Unrecognized updated model:', payload); - } + console.log('Unrecognized updated model:', payload); return; } @@ -125,7 +111,8 @@ const shouldIgnoreEvent = (payload: Model, windowLabel: string) => windowLabel === appWindow.label && payload.model !== 'http_response'; const shouldIgnoreModel = (payload: Model) => { - if (payload.model === 'http_response') return false; - if (payload.model === 'key_value' && payload.namespace === NAMESPACE_NO_SYNC) return false; - return true; + if (payload.model === 'key_value') { + return payload.namespace === NAMESPACE_NO_SYNC; + } + return false; }; diff --git a/src-web/components/RequestActionsDropdown.tsx b/src-web/components/RequestActionsDropdown.tsx index a4da9a76..bf051efa 100644 --- a/src-web/components/RequestActionsDropdown.tsx +++ b/src-web/components/RequestActionsDropdown.tsx @@ -24,6 +24,11 @@ export function RequestActionsDropdown({ requestId, children }: Props) { dropdownRef.current?.toggle(); }); + // TODO: Put this somewhere better + useTauriEvent('duplicate_request', () => { + duplicateRequest.mutate(); + }); + return (