@go-avro/avro-js 0.0.9-beta.0 → 0.0.9-beta.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -2,8 +2,9 @@ import { useMutation, useQuery, useInfiniteQuery } from "@tanstack/react-query";
|
|
|
2
2
|
import { AvroQueryClient } from "../../client/QueryClient";
|
|
3
3
|
AvroQueryClient.prototype.useGetUserSessions = function () {
|
|
4
4
|
return useQuery({
|
|
5
|
-
queryKey: ['sessions'],
|
|
5
|
+
queryKey: ['sessions', this.companyId],
|
|
6
6
|
queryFn: () => this.get({ path: '/session' }),
|
|
7
|
+
enabled: Boolean(this.companyId),
|
|
7
8
|
});
|
|
8
9
|
};
|
|
9
10
|
AvroQueryClient.prototype.useCreateUserSession = function () {
|
|
@@ -17,9 +18,9 @@ AvroQueryClient.prototype.useCreateUserSession = function () {
|
|
|
17
18
|
});
|
|
18
19
|
},
|
|
19
20
|
onMutate: async ({ sessionData }) => {
|
|
20
|
-
await queryClient.cancelQueries({ queryKey: ['sessions'] });
|
|
21
|
-
const previousSessions = queryClient.getQueryData(['sessions']);
|
|
22
|
-
queryClient.setQueryData(['sessions'], (oldData) => {
|
|
21
|
+
await queryClient.cancelQueries({ queryKey: ['sessions', this.companyId] });
|
|
22
|
+
const previousSessions = queryClient.getQueryData(['sessions', this.companyId]);
|
|
23
|
+
queryClient.setQueryData(['sessions', this.companyId], (oldData) => {
|
|
23
24
|
if (!oldData)
|
|
24
25
|
return [];
|
|
25
26
|
if (Array.isArray(oldData)) {
|
|
@@ -38,11 +39,11 @@ AvroQueryClient.prototype.useCreateUserSession = function () {
|
|
|
38
39
|
},
|
|
39
40
|
onError: (err, variables, context) => {
|
|
40
41
|
if (context?.previousSessions) {
|
|
41
|
-
queryClient.setQueryData(['sessions'], context.previousSessions);
|
|
42
|
+
queryClient.setQueryData(['sessions', this.companyId], context.previousSessions);
|
|
42
43
|
}
|
|
43
44
|
},
|
|
44
45
|
onSettled: () => {
|
|
45
|
-
queryClient.invalidateQueries({ queryKey: ['sessions'] });
|
|
46
|
+
queryClient.invalidateQueries({ queryKey: ['sessions', this.companyId] });
|
|
46
47
|
},
|
|
47
48
|
});
|
|
48
49
|
};
|
|
@@ -57,9 +58,9 @@ AvroQueryClient.prototype.useCreateSessionBreak = function () {
|
|
|
57
58
|
});
|
|
58
59
|
},
|
|
59
60
|
onMutate: async ({ sessionId, breakData }) => {
|
|
60
|
-
await queryClient.cancelQueries({ queryKey: ['sessions'] });
|
|
61
|
-
const previousSessions = queryClient.getQueryData(['sessions']);
|
|
62
|
-
queryClient.setQueryData(['sessions'], (oldData) => {
|
|
61
|
+
await queryClient.cancelQueries({ queryKey: ['sessions', this.companyId] });
|
|
62
|
+
const previousSessions = queryClient.getQueryData(['sessions', this.companyId]);
|
|
63
|
+
queryClient.setQueryData(['sessions', this.companyId], (oldData) => {
|
|
63
64
|
if (!oldData)
|
|
64
65
|
return oldData;
|
|
65
66
|
if (Array.isArray(oldData)) {
|
|
@@ -83,11 +84,11 @@ AvroQueryClient.prototype.useCreateSessionBreak = function () {
|
|
|
83
84
|
},
|
|
84
85
|
onError: (err, variables, context) => {
|
|
85
86
|
if (context?.previousSessions) {
|
|
86
|
-
queryClient.setQueryData(['sessions'], context.previousSessions);
|
|
87
|
+
queryClient.setQueryData(['sessions', this.companyId], context.previousSessions);
|
|
87
88
|
}
|
|
88
89
|
},
|
|
89
90
|
onSettled: () => {
|
|
90
|
-
queryClient.invalidateQueries({ queryKey: ['sessions'] });
|
|
91
|
+
queryClient.invalidateQueries({ queryKey: ['sessions', this.companyId] });
|
|
91
92
|
},
|
|
92
93
|
});
|
|
93
94
|
};
|
|
@@ -102,9 +103,9 @@ AvroQueryClient.prototype.useUpdateUserSession = function () {
|
|
|
102
103
|
});
|
|
103
104
|
},
|
|
104
105
|
onMutate: async ({ sessionId, updates }) => {
|
|
105
|
-
await queryClient.cancelQueries({ queryKey: ['sessions'] });
|
|
106
|
-
const previousSessions = queryClient.getQueryData(['sessions']);
|
|
107
|
-
queryClient.setQueryData(['sessions'], (oldData) => {
|
|
106
|
+
await queryClient.cancelQueries({ queryKey: ['sessions', this.companyId] });
|
|
107
|
+
const previousSessions = queryClient.getQueryData(['sessions', this.companyId]);
|
|
108
|
+
queryClient.setQueryData(['sessions', this.companyId], (oldData) => {
|
|
108
109
|
if (!oldData)
|
|
109
110
|
return oldData;
|
|
110
111
|
if (Array.isArray(oldData)) {
|
|
@@ -116,11 +117,11 @@ AvroQueryClient.prototype.useUpdateUserSession = function () {
|
|
|
116
117
|
},
|
|
117
118
|
onError: (err, variables, context) => {
|
|
118
119
|
if (context?.previousSessions) {
|
|
119
|
-
queryClient.setQueryData(['sessions'], context.previousSessions);
|
|
120
|
+
queryClient.setQueryData(['sessions', this.companyId], context.previousSessions);
|
|
120
121
|
}
|
|
121
122
|
},
|
|
122
123
|
onSettled: () => {
|
|
123
|
-
queryClient.invalidateQueries({ queryKey: ['sessions'] });
|
|
124
|
+
queryClient.invalidateQueries({ queryKey: ['sessions', this.companyId] });
|
|
124
125
|
},
|
|
125
126
|
});
|
|
126
127
|
};
|
|
@@ -135,9 +136,9 @@ AvroQueryClient.prototype.useUpdateSessionBreak = function () {
|
|
|
135
136
|
});
|
|
136
137
|
},
|
|
137
138
|
onMutate: async ({ breakId, updates }) => {
|
|
138
|
-
await queryClient.cancelQueries({ queryKey: ['sessions'] });
|
|
139
|
-
const previousSessions = queryClient.getQueryData(['sessions']);
|
|
140
|
-
queryClient.setQueryData(['sessions'], (oldData) => {
|
|
139
|
+
await queryClient.cancelQueries({ queryKey: ['sessions', this.companyId] });
|
|
140
|
+
const previousSessions = queryClient.getQueryData(['sessions', this.companyId]);
|
|
141
|
+
queryClient.setQueryData(['sessions', this.companyId], (oldData) => {
|
|
141
142
|
if (!oldData)
|
|
142
143
|
return oldData;
|
|
143
144
|
if (Array.isArray(oldData)) {
|
|
@@ -152,11 +153,11 @@ AvroQueryClient.prototype.useUpdateSessionBreak = function () {
|
|
|
152
153
|
},
|
|
153
154
|
onError: (err, variables, context) => {
|
|
154
155
|
if (context?.previousSessions) {
|
|
155
|
-
queryClient.setQueryData(['sessions'], context.previousSessions);
|
|
156
|
+
queryClient.setQueryData(['sessions', this.companyId], context.previousSessions);
|
|
156
157
|
}
|
|
157
158
|
},
|
|
158
159
|
onSettled: () => {
|
|
159
|
-
queryClient.invalidateQueries({ queryKey: ['sessions'] });
|
|
160
|
+
queryClient.invalidateQueries({ queryKey: ['sessions', this.companyId] });
|
|
160
161
|
},
|
|
161
162
|
});
|
|
162
163
|
};
|