-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathuse-schedule-queue-items-subscription.ts
More file actions
42 lines (34 loc) · 1.38 KB
/
use-schedule-queue-items-subscription.ts
File metadata and controls
42 lines (34 loc) · 1.38 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
40
41
42
import type { ComputedRef } from "vue";
import { computed } from "vue";
import type { ScheduleQueueItem } from "@/graphql/codegen/generated";
import {
useScheduleQueueItemsQuery,
useScheduleQueueItemsSSubscription,
} from "@/graphql/codegen/generated";
import { onReady } from "@/utils/on-ready";
import type { OnReady } from "@/utils/on-ready";
interface _ScheduleQueueItemsSubscription {
items: ComputedRef<ScheduleQueueItem[] | undefined>;
loading: ComputedRef<boolean>;
error: ComputedRef<Error | undefined>;
subscription: ReturnType<typeof useScheduleQueueItemsSSubscription>;
query: ReturnType<typeof useScheduleQueueItemsQuery>;
}
type ScheduleQueueItemsSubscription = OnReady<_ScheduleQueueItemsSubscription>;
export function useSubscribeScheduleQueueItems(): ScheduleQueueItemsSubscription {
const query = useScheduleQueueItemsQuery({
requestPolicy: "network-only",
variables: {},
});
const subscription = useScheduleQueueItemsSSubscription({ variables: {} });
const loading = computed(() => query.fetching?.value);
const error = computed(() => subscription.error?.value || query.error?.value);
const items = computed(() =>
error.value
? undefined
: subscription.data?.value?.scheduleQueueItems ||
query.data?.value?.schedule.queue.items,
);
const ret = { items, loading, error, subscription, query };
return onReady(ret, query);
}