Skip to content

Commit aebcd37

Browse files
committed
Only execute robot queries when connected
1 parent 63779fb commit aebcd37

File tree

1 file changed

+5
-2
lines changed

1 file changed

+5
-2
lines changed

src/lib/hooks/create-robot-query.svelte.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,12 @@ import {
44
type QueryObserverResult,
55
} from '@tanstack/svelte-query';
66

7-
import type { RobotClient } from '@viamrobotics/sdk';
7+
import { MachineConnectionEvent, type RobotClient } from '@viamrobotics/sdk';
88
import { toStore, fromStore } from 'svelte/store';
99
import { usePolling } from './use-polling.svelte';
1010
import { useQueryLogger } from '$lib/query-logger';
1111
import { useEnabledQueries } from './use-enabled-queries.svelte';
12+
import { useConnectionStatus } from './robot-clients.svelte';
1213

1314
// eslint-disable-next-line @typescript-eslint/no-explicit-any
1415
export type ArgumentsType<T> = T extends (...args: infer U) => any ? U : never;
@@ -37,6 +38,7 @@ export const createRobotQuery = <T extends RobotClient, K extends keyof T>(
3738
]
3839
| [options?: (() => QueryOptions) | QueryOptions]
3940
): { current: QueryObserverResult<ResolvedReturnType<T[K]>> } => {
41+
const connectionStatus = useConnectionStatus();
4042
const debug = useQueryLogger();
4143
const enabledQueries = useEnabledQueries();
4244
let [args, options] = additional;
@@ -52,7 +54,8 @@ export const createRobotQuery = <T extends RobotClient, K extends keyof T>(
5254
const _args = $derived(typeof args === 'function' ? args() : args);
5355
const methodName = $derived(String(method));
5456
const enabled = $derived(
55-
client.current !== undefined &&
57+
connectionStatus.current === MachineConnectionEvent.CONNECTED &&
58+
client.current !== undefined &&
5659
_options?.enabled !== false &&
5760
enabledQueries.robotQueries
5861
);

0 commit comments

Comments
 (0)