-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathindex.ts
34 lines (29 loc) · 896 Bytes
/
index.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
33
34
import { useMutation, useQuery, useQueryClient } from "@tanstack/react-query"
import { widgetListsApi } from "../../clients"
import widgetLists from "./keyFactory"
import { WidgetInstance } from "api/v0"
/**
* Query is disabled if id is undefined.
*/
const useWidgetList = (id: number | undefined) => {
return useQuery({
...widgetLists.detail(id ?? -1),
enabled: id !== undefined,
})
}
const useMutateWidgetsList = (id: number) => {
const client = useQueryClient()
return useMutation({
mutationFn: (data: WidgetInstance[]) =>
widgetListsApi
.widgetListsPartialUpdate({
id: id,
PatchedWidgetListRequest: { widgets: data as WidgetInstance[] },
})
.then((response) => response.data),
onSuccess: (_data) => {
client.invalidateQueries(widgetLists._def)
},
})
}
export { useWidgetList, useMutateWidgetsList }