-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathuse-schedule-auto-mode-state-subscription.ts
More file actions
39 lines (31 loc) · 1.27 KB
/
use-schedule-auto-mode-state-subscription.ts
File metadata and controls
39 lines (31 loc) · 1.27 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
import type { ComputedRef } from "vue";
import { computed } from "vue";
import {
useQScheduleAutoModeStateQuery,
useScheduleAutoModeStateSSubscription,
} from "@/graphql/codegen/generated";
import { onReady } from "@/utils/on-ready";
import type { OnReady } from "@/utils/on-ready";
interface _ScheduleAutoModeStateSubscription {
autoModeState: ComputedRef<string | undefined>;
error: ComputedRef<Error | undefined>;
subscription: ReturnType<typeof useScheduleAutoModeStateSSubscription>;
query: ReturnType<typeof useQScheduleAutoModeStateQuery>;
}
type ScheduleAutoModeStateSubscription = OnReady<_ScheduleAutoModeStateSubscription>;
export function useSubscribeScheduleAutoModeState(): ScheduleAutoModeStateSubscription {
const query = useQScheduleAutoModeStateQuery({
requestPolicy: "network-only",
variables: {},
});
const subscription = useScheduleAutoModeStateSSubscription({ variables: {} });
const error = computed(() => subscription.error?.value || query.error?.value);
const autoModeState = computed(() =>
error.value
? undefined
: subscription.data?.value?.scheduleAutoModeState ||
query.data?.value?.schedule.autoMode.state,
);
const ret = { autoModeState, error, subscription, query };
return onReady(ret, query);
}