@jobber/hooks 2.0.3-JOB-23925.73 → 2.0.3-dar.45
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.
- package/dist/index.js +11 -26
- package/dist/index.js.map +1 -0
- package/dist/useAssert/index.js +2 -5
- package/dist/useAssert/index.js.map +1 -0
- package/dist/useAssert/useAssert.js +4 -10
- package/dist/useAssert/useAssert.js.map +1 -0
- package/dist/useCollectionQuery/index.js +2 -5
- package/dist/useCollectionQuery/index.js.map +1 -0
- package/dist/useCollectionQuery/mdxUtils.js +9 -12
- package/dist/useCollectionQuery/mdxUtils.js.map +1 -0
- package/dist/useCollectionQuery/test-utilities/index.js +4 -19
- package/dist/useCollectionQuery/test-utilities/index.js.map +1 -0
- package/dist/useCollectionQuery/test-utilities/mocks.js +20 -30
- package/dist/useCollectionQuery/test-utilities/mocks.js.map +1 -0
- package/dist/useCollectionQuery/test-utilities/queries.js +5 -7
- package/dist/useCollectionQuery/test-utilities/queries.js.map +1 -0
- package/dist/useCollectionQuery/test-utilities/utils.js +2 -5
- package/dist/useCollectionQuery/test-utilities/utils.js.map +1 -0
- package/dist/useCollectionQuery/uniqueEdges.js +3 -7
- package/dist/useCollectionQuery/uniqueEdges.js.map +1 -0
- package/dist/useCollectionQuery/uniqueNodes.js +2 -5
- package/dist/useCollectionQuery/uniqueNodes.js.map +1 -0
- package/dist/useCollectionQuery/useCollectionQuery.js +27 -31
- package/dist/useCollectionQuery/useCollectionQuery.js.map +1 -0
- package/dist/useCollectionQuery/useCollectionQuery.test.js +118 -119
- package/dist/useCollectionQuery/useCollectionQuery.test.js.map +1 -0
- package/dist/useFocusTrap/index.js +2 -5
- package/dist/useFocusTrap/index.js.map +1 -0
- package/dist/useFocusTrap/useFocusTrap.js +5 -8
- package/dist/useFocusTrap/useFocusTrap.js.map +1 -0
- package/dist/useFocusTrap/useFocusTrap.test.js +27 -31
- package/dist/useFocusTrap/useFocusTrap.test.js.map +1 -0
- package/dist/useFormState/index.js +2 -5
- package/dist/useFormState/index.js.map +1 -0
- package/dist/useFormState/useFormState.js +4 -7
- package/dist/useFormState/useFormState.js.map +1 -0
- package/dist/useIsMounted/index.js +2 -5
- package/dist/useIsMounted/index.js.map +1 -0
- package/dist/useIsMounted/useIsMounted.js +5 -8
- package/dist/useIsMounted/useIsMounted.js.map +1 -0
- package/dist/useIsMounted/useIsMounted.test.js +5 -6
- package/dist/useIsMounted/useIsMounted.test.js.map +1 -0
- package/dist/useLiveAnnounce/index.js +2 -5
- package/dist/useLiveAnnounce/index.js.map +1 -0
- package/dist/useLiveAnnounce/useLiveAnnounce.js +5 -8
- package/dist/useLiveAnnounce/useLiveAnnounce.js.map +1 -0
- package/dist/useLiveAnnounce/useLiveAnnounce.test.js +20 -24
- package/dist/useLiveAnnounce/useLiveAnnounce.test.js.map +1 -0
- package/dist/useOnKeyDown/index.js +2 -5
- package/dist/useOnKeyDown/index.js.map +1 -0
- package/dist/useOnKeyDown/useOnKeyDown.js +4 -10
- package/dist/useOnKeyDown/useOnKeyDown.js.map +1 -0
- package/dist/useOnKeyDown/useOnKeyDown.test.js +8 -12
- package/dist/useOnKeyDown/useOnKeyDown.test.js.map +1 -0
- package/dist/usePasswordStrength/index.js +2 -5
- package/dist/usePasswordStrength/index.js.map +1 -0
- package/dist/usePasswordStrength/usePasswordStrength.js +5 -11
- package/dist/usePasswordStrength/usePasswordStrength.js.map +1 -0
- package/dist/useRefocusOnActivator/index.js +2 -5
- package/dist/useRefocusOnActivator/index.js.map +1 -0
- package/dist/useRefocusOnActivator/useRefocusOnActivator.js +4 -7
- package/dist/useRefocusOnActivator/useRefocusOnActivator.js.map +1 -0
- package/dist/useResizeObserver/index.js +2 -17
- package/dist/useResizeObserver/index.js.map +1 -0
- package/dist/useResizeObserver/useResizeObserver.js +9 -15
- package/dist/useResizeObserver/useResizeObserver.js.map +1 -0
- package/package.json +3 -3
package/dist/index.js
CHANGED
|
@@ -1,26 +1,11 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
}));
|
|
13
|
-
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
-
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
-
};
|
|
16
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
-
__exportStar(require("./useAssert"), exports);
|
|
18
|
-
__exportStar(require("./useCollectionQuery"), exports);
|
|
19
|
-
__exportStar(require("./useFocusTrap"), exports);
|
|
20
|
-
__exportStar(require("./useFormState"), exports);
|
|
21
|
-
__exportStar(require("./useIsMounted"), exports);
|
|
22
|
-
__exportStar(require("./useLiveAnnounce"), exports);
|
|
23
|
-
__exportStar(require("./useOnKeyDown"), exports);
|
|
24
|
-
__exportStar(require("./usePasswordStrength"), exports);
|
|
25
|
-
__exportStar(require("./useRefocusOnActivator"), exports);
|
|
26
|
-
__exportStar(require("./useResizeObserver"), exports);
|
|
1
|
+
export * from "./useAssert";
|
|
2
|
+
export * from "./useCollectionQuery";
|
|
3
|
+
export * from "./useFocusTrap";
|
|
4
|
+
export * from "./useFormState";
|
|
5
|
+
export * from "./useIsMounted";
|
|
6
|
+
export * from "./useLiveAnnounce";
|
|
7
|
+
export * from "./useOnKeyDown";
|
|
8
|
+
export * from "./usePasswordStrength";
|
|
9
|
+
export * from "./useRefocusOnActivator";
|
|
10
|
+
export * from "./useResizeObserver";
|
|
11
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,aAAa,CAAC;AAC5B,cAAc,sBAAsB,CAAC;AACrC,cAAc,gBAAgB,CAAC;AAC/B,cAAc,gBAAgB,CAAC;AAC/B,cAAc,gBAAgB,CAAC;AAC/B,cAAc,mBAAmB,CAAC;AAClC,cAAc,gBAAgB,CAAC;AAC/B,cAAc,uBAAuB,CAAC;AACtC,cAAc,yBAAyB,CAAC;AACxC,cAAc,qBAAqB,CAAC"}
|
package/dist/useAssert/index.js
CHANGED
|
@@ -1,5 +1,2 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
exports.useAssert = void 0;
|
|
4
|
-
var useAssert_1 = require("./useAssert");
|
|
5
|
-
Object.defineProperty(exports, "useAssert", { enumerable: true, get: function () { return useAssert_1.useAssert; } });
|
|
1
|
+
export { useAssert } from "./useAssert";
|
|
2
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/useAssert/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC"}
|
|
@@ -1,12 +1,6 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
};
|
|
5
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.useAssert = void 0;
|
|
7
|
-
const process_1 = __importDefault(require("process"));
|
|
8
|
-
function useAssert(shouldShow, message, options) {
|
|
9
|
-
if (process_1.default.env.NODE_ENV !== "production" && shouldShow) {
|
|
1
|
+
import process from "process";
|
|
2
|
+
export function useAssert(shouldShow, message, options) {
|
|
3
|
+
if (process.env.NODE_ENV !== "production" && shouldShow) {
|
|
10
4
|
if (options === null || options === void 0 ? void 0 : options.warn) {
|
|
11
5
|
console.warn(message);
|
|
12
6
|
}
|
|
@@ -15,4 +9,4 @@ function useAssert(shouldShow, message, options) {
|
|
|
15
9
|
}
|
|
16
10
|
}
|
|
17
11
|
}
|
|
18
|
-
|
|
12
|
+
//# sourceMappingURL=useAssert.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useAssert.js","sourceRoot":"","sources":["../../src/useAssert/useAssert.tsx"],"names":[],"mappings":"AAAA,OAAO,OAAO,MAAM,SAAS,CAAC;AAM9B,MAAM,UAAU,SAAS,CACvB,UAAmB,EACnB,OAAe,EACf,OAAiB;IAEjB,IAAI,OAAO,CAAC,GAAG,CAAC,QAAQ,KAAK,YAAY,IAAI,UAAU,EAAE;QACvD,IAAI,OAAO,aAAP,OAAO,uBAAP,OAAO,CAAE,IAAI,EAAE;YACjB,OAAO,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;SACvB;aAAM;YACL,MAAM,IAAI,KAAK,CAAC,OAAO,CAAC,CAAC;SAC1B;KACF;AACH,CAAC"}
|
|
@@ -1,5 +1,2 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
exports.useCollectionQuery = void 0;
|
|
4
|
-
var useCollectionQuery_1 = require("./useCollectionQuery");
|
|
5
|
-
Object.defineProperty(exports, "useCollectionQuery", { enumerable: true, get: function () { return useCollectionQuery_1.useCollectionQuery; } });
|
|
1
|
+
export { useCollectionQuery } from "./useCollectionQuery";
|
|
2
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/useCollectionQuery/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,kBAAkB,EAAE,MAAM,sBAAsB,CAAC"}
|
|
@@ -1,8 +1,5 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
exports.returnValues = exports.subscriptionPropsList = exports.propsList = exports.getLoadingState = exports.apolloClient = exports.LIST_QUERY = void 0;
|
|
4
|
-
const client_1 = require("@apollo/client");
|
|
5
|
-
exports.LIST_QUERY = (0, client_1.gql) `
|
|
1
|
+
import { ApolloClient, InMemoryCache, gql } from "@apollo/client";
|
|
2
|
+
export const LIST_QUERY = gql `
|
|
6
3
|
query ListQuery($cursor: String) {
|
|
7
4
|
allPlanets(first: 4, after: $cursor) {
|
|
8
5
|
pageInfo {
|
|
@@ -19,11 +16,11 @@ exports.LIST_QUERY = (0, client_1.gql) `
|
|
|
19
16
|
}
|
|
20
17
|
}
|
|
21
18
|
`;
|
|
22
|
-
|
|
19
|
+
export const apolloClient = new ApolloClient({
|
|
23
20
|
uri: "https://swapi-graphql.netlify.app/.netlify/functions/index",
|
|
24
|
-
cache: new
|
|
21
|
+
cache: new InMemoryCache(),
|
|
25
22
|
});
|
|
26
|
-
function getLoadingState(loadingInitialContent, loadingRefresh, loadingNextPage) {
|
|
23
|
+
export function getLoadingState(loadingInitialContent, loadingRefresh, loadingNextPage) {
|
|
27
24
|
if (loadingInitialContent) {
|
|
28
25
|
return {
|
|
29
26
|
loading: true,
|
|
@@ -47,8 +44,7 @@ function getLoadingState(loadingInitialContent, loadingRefresh, loadingNextPage)
|
|
|
47
44
|
loadingStatus: "Loaded",
|
|
48
45
|
};
|
|
49
46
|
}
|
|
50
|
-
|
|
51
|
-
exports.propsList = [
|
|
47
|
+
export const propsList = [
|
|
52
48
|
{
|
|
53
49
|
id: 0,
|
|
54
50
|
title: "query",
|
|
@@ -79,7 +75,7 @@ exports.propsList = [
|
|
|
79
75
|
value: "SubscriptionProps",
|
|
80
76
|
},
|
|
81
77
|
];
|
|
82
|
-
|
|
78
|
+
export const subscriptionPropsList = [
|
|
83
79
|
{
|
|
84
80
|
id: 0,
|
|
85
81
|
title: "document",
|
|
@@ -106,7 +102,7 @@ exports.subscriptionPropsList = [
|
|
|
106
102
|
value: "GetNodeByPath<TSubscription>",
|
|
107
103
|
},
|
|
108
104
|
];
|
|
109
|
-
|
|
105
|
+
export const returnValues = [
|
|
110
106
|
{
|
|
111
107
|
id: 0,
|
|
112
108
|
title: "data",
|
|
@@ -150,3 +146,4 @@ exports.returnValues = [
|
|
|
150
146
|
value: "boolean",
|
|
151
147
|
},
|
|
152
148
|
];
|
|
149
|
+
//# sourceMappingURL=mdxUtils.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"mdxUtils.js","sourceRoot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jE,KAAK,EAAE,SAAS;KACjB;CACF,CAAC"}
|
|
@@ -1,19 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
-
}
|
|
8
|
-
Object.defineProperty(o, k2, desc);
|
|
9
|
-
}) : (function(o, m, k, k2) {
|
|
10
|
-
if (k2 === undefined) k2 = k;
|
|
11
|
-
o[k2] = m[k];
|
|
12
|
-
}));
|
|
13
|
-
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
-
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
-
};
|
|
16
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
-
__exportStar(require("./queries"), exports);
|
|
18
|
-
__exportStar(require("./utils"), exports);
|
|
19
|
-
__exportStar(require("./mocks"), exports);
|
|
1
|
+
export * from "./queries";
|
|
2
|
+
export * from "./utils";
|
|
3
|
+
export * from "./mocks";
|
|
4
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/useCollectionQuery/test-utilities/index.ts"],"names":[],"mappings":"AAAA,cAAc,WAAW,CAAC;AAC1B,cAAc,SAAS,CAAC;AACxB,cAAc,SAAS,CAAC"}
|
|
@@ -1,22 +1,15 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
};
|
|
5
|
-
|
|
6
|
-
exports.setListQueryMockHasNextPage = exports.buildListRequestMockForNextPage = exports.buildSubscriptionRequestMock = exports.buildListRequestMock = exports.subscriptionQueryMock = exports.listQueryWithTotalCountResponseMock = exports.listQueryResponseMock = exports.wrapper = void 0;
|
|
7
|
-
const react_testing_1 = require("@apollo/react-testing");
|
|
8
|
-
const react_1 = __importDefault(require("react"));
|
|
9
|
-
const uuid_1 = require("uuid");
|
|
10
|
-
const queries_1 = require("./queries");
|
|
11
|
-
function wrapper(mocks) {
|
|
1
|
+
import { MockedProvider } from "@apollo/react-testing";
|
|
2
|
+
import React from "react";
|
|
3
|
+
import { v1 as uuidv1 } from "uuid";
|
|
4
|
+
import { SUBSCRIPTION_QUERY } from "./queries";
|
|
5
|
+
export function wrapper(mocks) {
|
|
12
6
|
function ApolloMockedProvider({ children, }) {
|
|
13
|
-
return (
|
|
7
|
+
return (React.createElement(MockedProvider, { addTypename: true, mocks: mocks }, children));
|
|
14
8
|
}
|
|
15
9
|
return ApolloMockedProvider;
|
|
16
10
|
}
|
|
17
|
-
exports.wrapper = wrapper;
|
|
18
11
|
let listQueryHasNextPage = true;
|
|
19
|
-
|
|
12
|
+
export const listQueryResponseMock = jest.fn(id => {
|
|
20
13
|
return {
|
|
21
14
|
data: {
|
|
22
15
|
conversation: {
|
|
@@ -28,14 +21,14 @@ exports.listQueryResponseMock = jest.fn(id => {
|
|
|
28
21
|
__typename: "SMSMessageEdge",
|
|
29
22
|
node: {
|
|
30
23
|
__typename: "SMSMessage",
|
|
31
|
-
id: id || (
|
|
24
|
+
id: id || uuidv1(),
|
|
32
25
|
},
|
|
33
26
|
},
|
|
34
27
|
],
|
|
35
28
|
nodes: [
|
|
36
29
|
{
|
|
37
30
|
__typename: "SMSMessage",
|
|
38
|
-
id: id || (
|
|
31
|
+
id: id || uuidv1(),
|
|
39
32
|
},
|
|
40
33
|
],
|
|
41
34
|
pageInfo: {
|
|
@@ -48,7 +41,7 @@ exports.listQueryResponseMock = jest.fn(id => {
|
|
|
48
41
|
},
|
|
49
42
|
};
|
|
50
43
|
});
|
|
51
|
-
|
|
44
|
+
export const listQueryWithTotalCountResponseMock = jest.fn(id => {
|
|
52
45
|
return {
|
|
53
46
|
data: {
|
|
54
47
|
conversation: {
|
|
@@ -60,14 +53,14 @@ exports.listQueryWithTotalCountResponseMock = jest.fn(id => {
|
|
|
60
53
|
__typename: "SMSMessageEdge",
|
|
61
54
|
node: {
|
|
62
55
|
__typename: "SMSMessage",
|
|
63
|
-
id: id || (
|
|
56
|
+
id: id || uuidv1(),
|
|
64
57
|
},
|
|
65
58
|
},
|
|
66
59
|
],
|
|
67
60
|
nodes: [
|
|
68
61
|
{
|
|
69
62
|
__typename: "SMSMessage",
|
|
70
|
-
id: id || (
|
|
63
|
+
id: id || uuidv1(),
|
|
71
64
|
},
|
|
72
65
|
],
|
|
73
66
|
pageInfo: {
|
|
@@ -81,7 +74,7 @@ exports.listQueryWithTotalCountResponseMock = jest.fn(id => {
|
|
|
81
74
|
},
|
|
82
75
|
};
|
|
83
76
|
});
|
|
84
|
-
|
|
77
|
+
export const subscriptionQueryMock = jest.fn(id => {
|
|
85
78
|
return {
|
|
86
79
|
data: {
|
|
87
80
|
conversationMessage: {
|
|
@@ -95,7 +88,7 @@ exports.subscriptionQueryMock = jest.fn(id => {
|
|
|
95
88
|
},
|
|
96
89
|
};
|
|
97
90
|
});
|
|
98
|
-
function buildListRequestMock(query, responseMock, id, searchTerm) {
|
|
91
|
+
export function buildListRequestMock(query, responseMock, id, searchTerm) {
|
|
99
92
|
return {
|
|
100
93
|
request: {
|
|
101
94
|
query: query,
|
|
@@ -104,18 +97,16 @@ function buildListRequestMock(query, responseMock, id, searchTerm) {
|
|
|
104
97
|
result: () => responseMock(id),
|
|
105
98
|
};
|
|
106
99
|
}
|
|
107
|
-
|
|
108
|
-
function buildSubscriptionRequestMock(id) {
|
|
100
|
+
export function buildSubscriptionRequestMock(id) {
|
|
109
101
|
return {
|
|
110
102
|
request: {
|
|
111
|
-
query:
|
|
103
|
+
query: SUBSCRIPTION_QUERY,
|
|
112
104
|
},
|
|
113
|
-
result: () =>
|
|
105
|
+
result: () => subscriptionQueryMock(id),
|
|
114
106
|
delay: 100,
|
|
115
107
|
};
|
|
116
108
|
}
|
|
117
|
-
|
|
118
|
-
function buildListRequestMockForNextPage(query, responseMock, id) {
|
|
109
|
+
export function buildListRequestMockForNextPage(query, responseMock, id) {
|
|
119
110
|
return {
|
|
120
111
|
request: {
|
|
121
112
|
query: query,
|
|
@@ -124,8 +115,7 @@ function buildListRequestMockForNextPage(query, responseMock, id) {
|
|
|
124
115
|
result: () => responseMock(id),
|
|
125
116
|
};
|
|
126
117
|
}
|
|
127
|
-
|
|
128
|
-
function setListQueryMockHasNextPage(hasNextPage) {
|
|
118
|
+
export function setListQueryMockHasNextPage(hasNextPage) {
|
|
129
119
|
listQueryHasNextPage = hasNextPage;
|
|
130
120
|
}
|
|
131
|
-
|
|
121
|
+
//# sourceMappingURL=mocks.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"mocks.js","sourceRoot":"","sources":["../../../src/useCollectionQuery/test-utilities/mocks.tsx"],"names":[],"mappings":"AACA,OAAO,EAAE,cAAc,EAAkB,MAAM,uBAAuB,CAAC;AACvE,OAAO,KAAK,MAAM,OAAO,CAAC;AAC1B,OAAO,EAAE,EAAE,IAAI,MAAM,EAAE,MAAM,MAAM,CAAC;AACpC,OAAO,EAAE,kBAAkB,EAAE,MAAM,WAAW,CAAC;AAE/C,MAAM,UAAU,OAAO,CAAC,KAAuB;IAC7C,SAAS,oBAAoB,CAAC,EAC5B,QAAQ,GAGT;QACC,OAAO,CACL,oBAAC,cAAc,IAAC,WAAW,EAAE,IAAI,EAAE,KAAK,EAAE,KAAK,IAC5C,QAAQ,CACM,CAClB,CAAC;IACJ,CAAC;IAED,OAAO,oBAA+C,CAAC;AACzD,CAAC;AAED,IAAI,oBAAoB,GAAG,IAAI,CAAC;AAChC,MAAM,CAAC,MAAM,qBAAqB,GAAG,IAAI,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE;IAChD,OAAO;QACL,IAAI,EAAE;YACJ,YAAY,EAAE;gBACZ,UAAU,EAAE,cAAc;gBAC1B,WAAW,EAAE;oBACX,UAAU,EAAE,sBAAsB;oBAClC,KAAK,EAAE;wB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U,EAAE;oBACV,UAAU,EAAE,gBAAgB;oBAC5B,EAAE,EAAE,EAAE;iBACP;aACF;SACF;KACF,CAAC;AACJ,CAAC,CAAC,CAAC;AAEH,MAAM,UAAU,oBAAoB,CAClC,KAAmB,EACnB,YAAuB,EACvB,EAAuB,EACvB,UAA+B;IAE/B,OAAO;QACL,OAAO,EAAE;YACP,KAAK,EAAE,KAAK;YACZ,SAAS,EAAE,EAAE,UAAU,EAAE,UAAU,EAAE;SACtC;QACD,MAAM,EAAE,GAAG,EAAE,CAAC,YAAY,CAAC,EAAE,CAAC;KAC/B,CAAC;AACJ,CAAC;AAED,MAAM,UAAU,4BAA4B,CAAC,EAAuB;IAClE,OAAO;QACL,OAAO,EAAE;YACP,KAAK,EAAE,kBAAkB;SAC1B;QACD,MAAM,EAAE,GAAG,EAAE,CAAC,qBAAqB,CAAC,EAAE,CAAC;QACvC,KAAK,EAAE,GAAG;KACX,CAAC;AACJ,CAAC;AAED,MAAM,UAAU,+BAA+B,CAC7C,KAAmB,EACnB,YAAuB,EACvB,EAAuB;IAEvB,OAAO;QACL,OAAO,EAAE;YACP,KAAK,EAAE,KAAK;YACZ,SAAS,EAAE,EAAE,MAAM,EAAE,IAAI,EAAE;SAC5B;QACD,MAAM,EAAE,GAAG,EAAE,CAAC,YAAY,CAAC,EAAE,CAAC;KAC/B,CAAC;AACJ,CAAC;AAED,MAAM,UAAU,2BAA2B,CAAC,WAAoB;IAC9D,oBAAoB,GAAG,WAAW,CAAC;AACrC,CAAC"}
|
|
@@ -1,8 +1,5 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
exports.SUBSCRIPTION_QUERY = exports.LIST_QUERY_WITH_TOTAL_COUNT = exports.LIST_QUERY = void 0;
|
|
4
|
-
const client_1 = require("@apollo/client");
|
|
5
|
-
exports.LIST_QUERY = (0, client_1.gql) `
|
|
1
|
+
import { gql } from "@apollo/client";
|
|
2
|
+
export const LIST_QUERY = gql `
|
|
6
3
|
query ConversationMessages($cursor: string, $searchTerm: string) {
|
|
7
4
|
conversation(id: "MQ==") {
|
|
8
5
|
smsMessages(first: 1, after: $cursor, searchTerm: $searchTerm) {
|
|
@@ -24,7 +21,7 @@ exports.LIST_QUERY = (0, client_1.gql) `
|
|
|
24
21
|
}
|
|
25
22
|
}
|
|
26
23
|
`;
|
|
27
|
-
|
|
24
|
+
export const LIST_QUERY_WITH_TOTAL_COUNT = gql `
|
|
28
25
|
query ConversationMessages($cursor: string, $searchTerm: string) {
|
|
29
26
|
conversation(id: "MQ==") {
|
|
30
27
|
smsMessages(first: 1, after: $cursor, searchTerm: $searchTerm) {
|
|
@@ -47,7 +44,7 @@ exports.LIST_QUERY_WITH_TOTAL_COUNT = (0, client_1.gql) `
|
|
|
47
44
|
}
|
|
48
45
|
}
|
|
49
46
|
`;
|
|
50
|
-
|
|
47
|
+
export const SUBSCRIPTION_QUERY = gql `
|
|
51
48
|
subscription ConversationMessage($conversationId: EncodedId!) {
|
|
52
49
|
conversationMessage(conversationId: $conversationId) {
|
|
53
50
|
smsMessage {
|
|
@@ -57,3 +54,4 @@ exports.SUBSCRIPTION_QUERY = (0, client_1.gql) `
|
|
|
57
54
|
}
|
|
58
55
|
}
|
|
59
56
|
`;
|
|
57
|
+
//# sourceMappingURL=queries.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"queries.js","sourceRoot":"","sources":["../../../src/useCollectionQuery/test-utilities/queries.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,GAAG,EAAE,MAAM,gBAAgB,CAAC;AAErC,MAAM,CAAC,MAAM,UAAU,GAAG,GAAG,CAAA;;;;;;;;;;;;;;;;;;;;;CAqB5B,CAAC;AAEF,MAAM,CAAC,MAAM,2BAA2B,GAAG,GAAG,CAAA;;;;;;;;;;;;;;;;;;;;;;CAsB7C,CAAC;AA4BF,MAAM,CAAC,MAAM,kBAAkB,GAAG,GAAG,CAAA;;;;;;;;;CASpC,CAAC"}
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
"use strict";
|
|
2
1
|
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
2
|
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
3
|
return new (P || (P = Promise))(function (resolve, reject) {
|
|
@@ -8,11 +7,9 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
8
7
|
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
8
|
});
|
|
10
9
|
};
|
|
11
|
-
|
|
12
|
-
exports.wait = void 0;
|
|
13
|
-
function wait(milliseconds = 0) {
|
|
10
|
+
export function wait(milliseconds = 0) {
|
|
14
11
|
return __awaiter(this, void 0, void 0, function* () {
|
|
15
12
|
yield new Promise(resolve => setTimeout(resolve, milliseconds));
|
|
16
13
|
});
|
|
17
14
|
}
|
|
18
|
-
|
|
15
|
+
//# sourceMappingURL=utils.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"utils.js","sourceRoot":"","sources":["../../../src/useCollectionQuery/test-utilities/utils.ts"],"names":[],"mappings":";;;;;;;;;AAAA,MAAM,UAAgB,IAAI,CAAC,YAAY,GAAG,CAAC;;QACzC,MAAM,IAAI,OAAO,CAAC,OAAO,CAAC,EAAE,CAAC,UAAU,CAAC,OAAO,EAAE,YAAY,CAAC,CAAC,CAAC;IAClE,CAAC;CAAA"}
|
|
@@ -1,19 +1,15 @@
|
|
|
1
|
-
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.uniqueEdges = exports.createEdge = void 0;
|
|
4
|
-
function createEdge(node) {
|
|
1
|
+
export function createEdge(node) {
|
|
5
2
|
return {
|
|
6
3
|
node: node,
|
|
7
4
|
cursor: "",
|
|
8
5
|
__typename: `${node.__typename}Edge`,
|
|
9
6
|
};
|
|
10
7
|
}
|
|
11
|
-
|
|
12
|
-
function uniqueEdges(edges) {
|
|
8
|
+
export function uniqueEdges(edges) {
|
|
13
9
|
const result = new Map();
|
|
14
10
|
edges.forEach(edge => {
|
|
15
11
|
result.set(`${edge.__typename}-${edge.node.__typename}-${edge.node.id}`, edge);
|
|
16
12
|
});
|
|
17
13
|
return Array.from(result.values());
|
|
18
14
|
}
|
|
19
|
-
|
|
15
|
+
//# sourceMappingURL=uniqueEdges.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"uniqueEdges.js","sourceRoot":"","sources":["../../src/useCollectionQuery/uniqueEdges.tsx"],"names":[],"mappings":"AAQA,MAAM,UAAU,UAAU,CAAC,IAAU;IACnC,OAAO;QACL,IAAI,EAAE,IAAI;QACV,MAAM,EAAE,EAAE;QACV,UAAU,EAAE,GAAG,IAAI,CAAC,UAAU,MAAM;KACrC,CAAC;AACJ,CAAC;AAED,MAAM,UAAU,WAAW,CAAC,KAAa;IACvC,MAAM,MAAM,GAAG,IAAI,GAAG,EAAgB,CAAC;IACvC,KAAK,CAAC,OAAO,CAAC,IAAI,CAAC,EAAE;QACnB,MAAM,CAAC,GAAG,CACR,GAAG,IAAI,CAAC,UAAU,IAAI,IAAI,CAAC,IAAI,CAAC,UAAU,IAAI,IAAI,CAAC,IAAI,CAAC,EAAE,EAAE,EAC5D,IAAI,CACL,CAAC;IACJ,CAAC,CAAC,CAAC;IACH,OAAO,KAAK,CAAC,IAAI,CAAC,MAAM,CAAC,MAAM,EAAE,CAAC,CAAC;AACrC,CAAC"}
|
|
@@ -1,11 +1,8 @@
|
|
|
1
|
-
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.uniqueNodes = void 0;
|
|
4
|
-
function uniqueNodes(nodes) {
|
|
1
|
+
export function uniqueNodes(nodes) {
|
|
5
2
|
const result = new Map();
|
|
6
3
|
nodes.forEach(node => {
|
|
7
4
|
result.set(`${node.__typename}-${node.id}`, node);
|
|
8
5
|
});
|
|
9
6
|
return Array.from(result.values());
|
|
10
7
|
}
|
|
11
|
-
|
|
8
|
+
//# sourceMappingURL=uniqueNodes.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"uniqueNodes.js","sourceRoot":"","sources":["../../src/useCollectionQuery/uniqueNodes.tsx"],"names":[],"mappings":"AAKA,MAAM,UAAU,WAAW,CAAC,KAAa;IACvC,MAAM,MAAM,GAAG,IAAI,GAAG,EAAgB,CAAC;IACvC,KAAK,CAAC,OAAO,CAAC,IAAI,CAAC,EAAE;QACnB,MAAM,CAAC,GAAG,CAAC,GAAG,IAAI,CAAC,UAAU,IAAI,IAAI,CAAC,EAAE,EAAE,EAAE,IAAI,CAAC,CAAC;IACpD,CAAC,CAAC,CAAC;IACH,OAAO,KAAK,CAAC,IAAI,CAAC,MAAM,CAAC,MAAM,EAAE,CAAC,CAAC;AACrC,CAAC"}
|
|
@@ -1,22 +1,19 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
const uniqueEdges_1 = require("./uniqueEdges");
|
|
10
|
-
const useIsMounted_1 = require("../useIsMounted");
|
|
11
|
-
function useCollectionQuery({ query, queryOptions, getCollectionByPath, subscription, }) {
|
|
1
|
+
import { useQuery, } from "@apollo/client";
|
|
2
|
+
import { cloneDeep } from "lodash";
|
|
3
|
+
import { useCallback, useEffect, useState } from "react";
|
|
4
|
+
import { config } from "@jobber/formatters";
|
|
5
|
+
import { uniqueNodes } from "./uniqueNodes";
|
|
6
|
+
import { createEdge, uniqueEdges } from "./uniqueEdges";
|
|
7
|
+
import { useIsMounted } from "../useIsMounted";
|
|
8
|
+
export function useCollectionQuery({ query, queryOptions, getCollectionByPath, subscription, }) {
|
|
12
9
|
var _a, _b;
|
|
13
|
-
const { data, loading, refetch, error, fetchMore, subscribeToMore } =
|
|
14
|
-
const isMounted =
|
|
15
|
-
const [loadingRefresh, setLoadingRefresh] =
|
|
16
|
-
const [loadingNextPage, setLoadingNextPage] =
|
|
10
|
+
const { data, loading, refetch, error, fetchMore, subscribeToMore } = useQuery(query, queryOptions);
|
|
11
|
+
const isMounted = useIsMounted();
|
|
12
|
+
const [loadingRefresh, setLoadingRefresh] = useState(false);
|
|
13
|
+
const [loadingNextPage, setLoadingNextPage] = useState(false);
|
|
17
14
|
const loadingInitialContent = loading && !loadingRefresh && !loadingNextPage;
|
|
18
15
|
const isSearching = !!((_a = queryOptions === null || queryOptions === void 0 ? void 0 : queryOptions.variables) === null || _a === void 0 ? void 0 : _a.searchTerm);
|
|
19
|
-
const refresh =
|
|
16
|
+
const refresh = useCallback(() => {
|
|
20
17
|
if (loadingInitialContent || loadingRefresh) {
|
|
21
18
|
return;
|
|
22
19
|
}
|
|
@@ -29,7 +26,7 @@ function useCollectionQuery({ query, queryOptions, getCollectionByPath, subscrip
|
|
|
29
26
|
variables: {},
|
|
30
27
|
updateQuery: (prev, { fetchMoreResult }) => fetchMoreResult || prev,
|
|
31
28
|
})
|
|
32
|
-
.catch(err =>
|
|
29
|
+
.catch(err => config.errorNotifier("Refetch Error", err))
|
|
33
30
|
.finally(() => {
|
|
34
31
|
if (isMounted.current) {
|
|
35
32
|
setLoadingRefresh(false);
|
|
@@ -42,7 +39,7 @@ function useCollectionQuery({ query, queryOptions, getCollectionByPath, subscrip
|
|
|
42
39
|
refetch,
|
|
43
40
|
isMounted,
|
|
44
41
|
]);
|
|
45
|
-
const nextPage =
|
|
42
|
+
const nextPage = useCallback(() => {
|
|
46
43
|
var _a;
|
|
47
44
|
if (loadingInitialContent || loadingRefresh || loadingNextPage) {
|
|
48
45
|
return;
|
|
@@ -58,7 +55,7 @@ function useCollectionQuery({ query, queryOptions, getCollectionByPath, subscrip
|
|
|
58
55
|
},
|
|
59
56
|
updateQuery: (prev, { fetchMoreResult }) => fetchMoreUpdateQueryHandler(prev, fetchMoreResult, getCollectionByPath),
|
|
60
57
|
})
|
|
61
|
-
.catch(err =>
|
|
58
|
+
.catch(err => config.errorNotifier("FetchMore Error", err))
|
|
62
59
|
.finally(() => {
|
|
63
60
|
if (isMounted.current) {
|
|
64
61
|
setLoadingNextPage(false);
|
|
@@ -74,11 +71,11 @@ function useCollectionQuery({ query, queryOptions, getCollectionByPath, subscrip
|
|
|
74
71
|
getCollectionByPath,
|
|
75
72
|
isMounted,
|
|
76
73
|
]);
|
|
77
|
-
|
|
74
|
+
useEffect(() => {
|
|
78
75
|
if (subscription == undefined)
|
|
79
76
|
return;
|
|
80
77
|
const subscriptionOptions = subscription.options || {};
|
|
81
|
-
return subscribeToMore(Object.assign(Object.assign({}, subscriptionOptions), { document: subscription.document, updateQuery: (prev, { subscriptionData }) => subscribeToMoreHandler(isSearching, prev, getCollectionByPath, subscriptionData === null || subscriptionData === void 0 ? void 0 : subscriptionData.data, subscription.getNodeByPath), onError: err =>
|
|
78
|
+
return subscribeToMore(Object.assign(Object.assign({}, subscriptionOptions), { document: subscription.document, updateQuery: (prev, { subscriptionData }) => subscribeToMoreHandler(isSearching, prev, getCollectionByPath, subscriptionData === null || subscriptionData === void 0 ? void 0 : subscriptionData.data, subscription.getNodeByPath), onError: err => config.errorNotifier("Subscribe to More Error", err) }));
|
|
82
79
|
},
|
|
83
80
|
// Disabling this linter so we can force this only run once. If we didn't
|
|
84
81
|
// do this we would need to ensure subscription, subscribeToMore, and getNodeByPath
|
|
@@ -94,7 +91,6 @@ function useCollectionQuery({ query, queryOptions, getCollectionByPath, subscrip
|
|
|
94
91
|
loadingInitialContent,
|
|
95
92
|
};
|
|
96
93
|
}
|
|
97
|
-
exports.useCollectionQuery = useCollectionQuery;
|
|
98
94
|
/**
|
|
99
95
|
* The following method uses an `output` variable, and indirectly modifies it through the `outputCollection` variable.
|
|
100
96
|
* This type of indirect modification is prone to bugs, but I couldn't think of a better way to write this code.
|
|
@@ -114,7 +110,7 @@ exports.useCollectionQuery = useCollectionQuery;
|
|
|
114
110
|
*/
|
|
115
111
|
function fetchMoreUpdateQueryHandler(prev, fetchMoreResult, getCollectionByPath) {
|
|
116
112
|
const nextCollection = getCollectionByPath(fetchMoreResult);
|
|
117
|
-
const output =
|
|
113
|
+
const output = cloneDeep(prev);
|
|
118
114
|
const outputCollection = getCollectionByPath(output);
|
|
119
115
|
if (outputCollection === undefined || nextCollection === undefined) {
|
|
120
116
|
return output;
|
|
@@ -125,12 +121,12 @@ function fetchMoreUpdateQueryHandler(prev, fetchMoreResult, getCollectionByPath)
|
|
|
125
121
|
if (outputCollection.edges && nextCollection.edges) {
|
|
126
122
|
outputCollection.edges = getUpdatedEdges(outputCollection.edges, nextCollection.edges);
|
|
127
123
|
}
|
|
128
|
-
Object.assign(outputCollection, Object.assign({ pageInfo:
|
|
124
|
+
Object.assign(outputCollection, Object.assign({ pageInfo: cloneDeep(nextCollection.pageInfo) }, getTotalCount(nextCollection.totalCount)));
|
|
129
125
|
return output;
|
|
130
126
|
}
|
|
131
127
|
function subscribeToMoreHandler(isSearching, prev, getCollectionByPath, subscriptionData, getNodeByPath) {
|
|
132
128
|
const node = getNodeByPath(subscriptionData);
|
|
133
|
-
const output =
|
|
129
|
+
const output = cloneDeep(prev);
|
|
134
130
|
const outputCollection = getCollectionByPath(output);
|
|
135
131
|
if (outputCollection == undefined || node == undefined)
|
|
136
132
|
return output;
|
|
@@ -141,9 +137,9 @@ function subscribeToMoreHandler(isSearching, prev, getCollectionByPath, subscrip
|
|
|
141
137
|
outputCollection.nodes = getUpdatedNodes(outputCollection.nodes, [node], false);
|
|
142
138
|
}
|
|
143
139
|
if (outputCollection.edges) {
|
|
144
|
-
outputCollection.edges = getUpdatedEdges(outputCollection.edges, [
|
|
140
|
+
outputCollection.edges = getUpdatedEdges(outputCollection.edges, [createEdge(node)], false);
|
|
145
141
|
}
|
|
146
|
-
Object.assign(outputCollection, Object.assign({ pageInfo:
|
|
142
|
+
Object.assign(outputCollection, Object.assign({ pageInfo: cloneDeep(outputCollection.pageInfo) }, getTotalCount(outputCollection.totalCount, 1)));
|
|
147
143
|
return output;
|
|
148
144
|
}
|
|
149
145
|
function getTotalCount(totalCount, additionalCount = 0) {
|
|
@@ -151,7 +147,7 @@ function getTotalCount(totalCount, additionalCount = 0) {
|
|
|
151
147
|
? { totalCount: totalCount + additionalCount }
|
|
152
148
|
: {};
|
|
153
149
|
}
|
|
154
|
-
function isAlreadyUpdated(outputCollection, newNode) {
|
|
150
|
+
export function isAlreadyUpdated(outputCollection, newNode) {
|
|
155
151
|
let edgesAlreadyUpdated = true;
|
|
156
152
|
let nodesAlreadyUpdated = true;
|
|
157
153
|
if (outputCollection.edges) {
|
|
@@ -166,16 +162,16 @@ function isAlreadyUpdated(outputCollection, newNode) {
|
|
|
166
162
|
}
|
|
167
163
|
return edgesAlreadyUpdated && nodesAlreadyUpdated;
|
|
168
164
|
}
|
|
169
|
-
exports.isAlreadyUpdated = isAlreadyUpdated;
|
|
170
165
|
function getUpdatedEdges(prevEdges, nextEdges, appendToEnd = true) {
|
|
171
166
|
const newEdges = appendToEnd
|
|
172
167
|
? [...prevEdges, ...nextEdges]
|
|
173
168
|
: [...nextEdges, ...prevEdges];
|
|
174
|
-
return
|
|
169
|
+
return uniqueEdges(newEdges);
|
|
175
170
|
}
|
|
176
171
|
function getUpdatedNodes(prevNodes, nextNodes, appendToEnd = true) {
|
|
177
172
|
const newNodes = appendToEnd
|
|
178
173
|
? [...prevNodes, ...nextNodes]
|
|
179
174
|
: [...nextNodes, ...prevNodes];
|
|
180
|
-
return
|
|
175
|
+
return uniqueNodes(newNodes);
|
|
181
176
|
}
|
|
177
|
+
//# sourceMappingURL=useCollectionQuery.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useCollectionQuery.js","sourceRoot":"","sources":["../../src/useCollectionQuery/useCollectionQuery.ts"],"names":[],"mappings":"AAAA,OAAO,EAKL,QAAQ,GACT,MAAM,gBAAgB,CAAC;AACxB,OAAO,EAAE,SAAS,EAAE,MAAM,QAAQ,CAAC;AACnC,OAAO,EAAE,WAAW,EAAE,SAAS,EAAE,QAAQ,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