forked from renproject/command-center
-
Notifications
You must be signed in to change notification settings - Fork 0
/
graphContainer.ts
32 lines (26 loc) · 1001 Bytes
/
graphContainer.ts
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
import { useApolloClient } from "@apollo/react-hooks";
import { useState } from "react";
import { createContainer } from "unstated-next";
import { useTaskSchedule } from "../hooks/useTaskSchedule";
import { queryRenVM, RenVM } from "../lib/graphQL/queries/renVM";
import { catchBackgroundException } from "../lib/react/errors";
const useGraphContainer = () => {
const client = useApolloClient();
const [renVM, setRenVM] = useState<RenVM | null>(null);
const updater = async () => {
try {
const newRenVM = await queryRenVM(client);
setRenVM(newRenVM);
return { timeout: 60, result: newRenVM };
} catch (error) {
catchBackgroundException(error, "Error in graphStore: updater");
return { timeout: 15, result: renVM };
}
};
const [fetchRenVM] = useTaskSchedule(updater);
return {
renVM,
fetchRenVM,
};
};
export const GraphContainer = createContainer(useGraphContainer);