Fixed multi-window model sync

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

View File

@@ -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<Model>('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;
};

View File

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