@jobber/hooks 2.0.3-preee.52 → 2.1.0
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 +26 -10
- package/dist/useAssert/index.js +5 -1
- package/dist/useAssert/useAssert.js +10 -3
- package/dist/useCollectionQuery/index.js +5 -1
- package/dist/useCollectionQuery/mdxUtils.d.ts +3 -2
- package/dist/useCollectionQuery/mdxUtils.js +12 -8
- package/dist/useCollectionQuery/test-utilities/index.js +19 -3
- package/dist/useCollectionQuery/test-utilities/mocks.d.ts +1 -1
- package/dist/useCollectionQuery/test-utilities/mocks.js +30 -19
- package/dist/useCollectionQuery/test-utilities/queries.d.ts +3 -3
- package/dist/useCollectionQuery/test-utilities/queries.js +7 -4
- package/dist/useCollectionQuery/test-utilities/utils.js +5 -1
- package/dist/useCollectionQuery/uniqueEdges.js +7 -2
- package/dist/useCollectionQuery/uniqueNodes.js +5 -1
- package/dist/useCollectionQuery/useCollectionQuery.js +31 -26
- package/dist/useCollectionQuery/useCollectionQuery.test.js +119 -117
- package/dist/useFocusTrap/index.js +5 -1
- package/dist/useFocusTrap/useFocusTrap.js +8 -4
- package/dist/useFocusTrap/useFocusTrap.test.js +31 -26
- package/dist/useFormState/index.js +5 -1
- package/dist/useFormState/useFormState.js +7 -3
- package/dist/useIsMounted/index.js +5 -1
- package/dist/useIsMounted/useIsMounted.js +8 -4
- package/dist/useIsMounted/useIsMounted.test.js +6 -4
- package/dist/useLiveAnnounce/index.js +5 -1
- package/dist/useLiveAnnounce/useLiveAnnounce.js +8 -4
- package/dist/useLiveAnnounce/useLiveAnnounce.test.js +24 -19
- package/dist/useOnKeyDown/index.js +5 -1
- package/dist/useOnKeyDown/useOnKeyDown.js +10 -3
- package/dist/useOnKeyDown/useOnKeyDown.test.js +12 -7
- package/dist/usePasswordStrength/index.js +5 -1
- package/dist/usePasswordStrength/usePasswordStrength.js +11 -4
- package/dist/useRefocusOnActivator/index.js +5 -1
- package/dist/useRefocusOnActivator/useRefocusOnActivator.js +7 -3
- package/dist/useResizeObserver/index.js +17 -1
- package/dist/useResizeObserver/useResizeObserver.d.ts +2 -1
- package/dist/useResizeObserver/useResizeObserver.js +15 -8
- package/package.json +8 -9
- package/useAssert.d.ts +1 -0
- package/useAssert.js +17 -0
- package/useCollectionQuery.d.ts +1 -0
- package/useCollectionQuery.js +17 -0
- package/useFocusTrap.d.ts +1 -0
- package/useFocusTrap.js +17 -0
- package/useFormState.d.ts +1 -0
- package/useFormState.js +17 -0
- package/useIsMounted.d.ts +1 -0
- package/useIsMounted.js +17 -0
- package/useLiveAnnounce.d.ts +1 -0
- package/useLiveAnnounce.js +17 -0
- package/useOnKeyDown.d.ts +1 -0
- package/useOnKeyDown.js +17 -0
- package/usePasswordStrength.d.ts +1 -0
- package/usePasswordStrength.js +17 -0
- package/useRefocusOnActivator.d.ts +1 -0
- package/useRefocusOnActivator.js +17 -0
- package/useResizeObserver.d.ts +1 -0
- package/useResizeObserver.js +17 -0
package/dist/index.js
CHANGED
|
@@ -1,10 +1,26 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
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("./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);
|
package/dist/useAssert/index.js
CHANGED
|
@@ -1 +1,5 @@
|
|
|
1
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
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,6 +1,12 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
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) {
|
|
4
10
|
if (options === null || options === void 0 ? void 0 : options.warn) {
|
|
5
11
|
console.warn(message);
|
|
6
12
|
}
|
|
@@ -9,3 +15,4 @@ export function useAssert(shouldShow, message, options) {
|
|
|
9
15
|
}
|
|
10
16
|
}
|
|
11
17
|
}
|
|
18
|
+
exports.useAssert = useAssert;
|
|
@@ -1 +1,5 @@
|
|
|
1
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
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,3 +1,4 @@
|
|
|
1
|
+
import { ApolloClient } from "@apollo/client";
|
|
1
2
|
export interface ListQueryType {
|
|
2
3
|
allPlanets: {
|
|
3
4
|
__typename?: "PlanetsConnection";
|
|
@@ -17,8 +18,8 @@ export interface ListQueryType {
|
|
|
17
18
|
totalCount?: number;
|
|
18
19
|
};
|
|
19
20
|
}
|
|
20
|
-
export declare const LIST_QUERY:
|
|
21
|
-
export declare const apolloClient:
|
|
21
|
+
export declare const LIST_QUERY: import("@apollo/client").DocumentNode;
|
|
22
|
+
export declare const apolloClient: ApolloClient<import("@apollo/client").NormalizedCacheObject>;
|
|
22
23
|
interface LoadingState {
|
|
23
24
|
loadingStatus: string;
|
|
24
25
|
loading: boolean;
|
|
@@ -1,5 +1,8 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
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) `
|
|
3
6
|
query ListQuery($cursor: String) {
|
|
4
7
|
allPlanets(first: 4, after: $cursor) {
|
|
5
8
|
pageInfo {
|
|
@@ -16,11 +19,11 @@ export const LIST_QUERY = gql `
|
|
|
16
19
|
}
|
|
17
20
|
}
|
|
18
21
|
`;
|
|
19
|
-
|
|
22
|
+
exports.apolloClient = new client_1.ApolloClient({
|
|
20
23
|
uri: "https://swapi-graphql.netlify.app/.netlify/functions/index",
|
|
21
|
-
cache: new InMemoryCache(),
|
|
24
|
+
cache: new client_1.InMemoryCache(),
|
|
22
25
|
});
|
|
23
|
-
|
|
26
|
+
function getLoadingState(loadingInitialContent, loadingRefresh, loadingNextPage) {
|
|
24
27
|
if (loadingInitialContent) {
|
|
25
28
|
return {
|
|
26
29
|
loading: true,
|
|
@@ -44,7 +47,8 @@ export function getLoadingState(loadingInitialContent, loadingRefresh, loadingNe
|
|
|
44
47
|
loadingStatus: "Loaded",
|
|
45
48
|
};
|
|
46
49
|
}
|
|
47
|
-
|
|
50
|
+
exports.getLoadingState = getLoadingState;
|
|
51
|
+
exports.propsList = [
|
|
48
52
|
{
|
|
49
53
|
id: 0,
|
|
50
54
|
title: "query",
|
|
@@ -75,7 +79,7 @@ export const propsList = [
|
|
|
75
79
|
value: "SubscriptionProps",
|
|
76
80
|
},
|
|
77
81
|
];
|
|
78
|
-
|
|
82
|
+
exports.subscriptionPropsList = [
|
|
79
83
|
{
|
|
80
84
|
id: 0,
|
|
81
85
|
title: "document",
|
|
@@ -102,7 +106,7 @@ export const subscriptionPropsList = [
|
|
|
102
106
|
value: "GetNodeByPath<TSubscription>",
|
|
103
107
|
},
|
|
104
108
|
];
|
|
105
|
-
|
|
109
|
+
exports.returnValues = [
|
|
106
110
|
{
|
|
107
111
|
id: 0,
|
|
108
112
|
title: "data",
|
|
@@ -1,3 +1,19 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
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,15 +1,22 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
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) {
|
|
6
12
|
function ApolloMockedProvider({ children, }) {
|
|
7
|
-
return (
|
|
13
|
+
return (react_1.default.createElement(react_testing_1.MockedProvider, { addTypename: true, mocks: mocks }, children));
|
|
8
14
|
}
|
|
9
15
|
return ApolloMockedProvider;
|
|
10
16
|
}
|
|
17
|
+
exports.wrapper = wrapper;
|
|
11
18
|
let listQueryHasNextPage = true;
|
|
12
|
-
|
|
19
|
+
exports.listQueryResponseMock = jest.fn(id => {
|
|
13
20
|
return {
|
|
14
21
|
data: {
|
|
15
22
|
conversation: {
|
|
@@ -21,14 +28,14 @@ export const listQueryResponseMock = jest.fn(id => {
|
|
|
21
28
|
__typename: "SMSMessageEdge",
|
|
22
29
|
node: {
|
|
23
30
|
__typename: "SMSMessage",
|
|
24
|
-
id: id ||
|
|
31
|
+
id: id || (0, uuid_1.v1)(),
|
|
25
32
|
},
|
|
26
33
|
},
|
|
27
34
|
],
|
|
28
35
|
nodes: [
|
|
29
36
|
{
|
|
30
37
|
__typename: "SMSMessage",
|
|
31
|
-
id: id ||
|
|
38
|
+
id: id || (0, uuid_1.v1)(),
|
|
32
39
|
},
|
|
33
40
|
],
|
|
34
41
|
pageInfo: {
|
|
@@ -41,7 +48,7 @@ export const listQueryResponseMock = jest.fn(id => {
|
|
|
41
48
|
},
|
|
42
49
|
};
|
|
43
50
|
});
|
|
44
|
-
|
|
51
|
+
exports.listQueryWithTotalCountResponseMock = jest.fn(id => {
|
|
45
52
|
return {
|
|
46
53
|
data: {
|
|
47
54
|
conversation: {
|
|
@@ -53,14 +60,14 @@ export const listQueryWithTotalCountResponseMock = jest.fn(id => {
|
|
|
53
60
|
__typename: "SMSMessageEdge",
|
|
54
61
|
node: {
|
|
55
62
|
__typename: "SMSMessage",
|
|
56
|
-
id: id ||
|
|
63
|
+
id: id || (0, uuid_1.v1)(),
|
|
57
64
|
},
|
|
58
65
|
},
|
|
59
66
|
],
|
|
60
67
|
nodes: [
|
|
61
68
|
{
|
|
62
69
|
__typename: "SMSMessage",
|
|
63
|
-
id: id ||
|
|
70
|
+
id: id || (0, uuid_1.v1)(),
|
|
64
71
|
},
|
|
65
72
|
],
|
|
66
73
|
pageInfo: {
|
|
@@ -74,7 +81,7 @@ export const listQueryWithTotalCountResponseMock = jest.fn(id => {
|
|
|
74
81
|
},
|
|
75
82
|
};
|
|
76
83
|
});
|
|
77
|
-
|
|
84
|
+
exports.subscriptionQueryMock = jest.fn(id => {
|
|
78
85
|
return {
|
|
79
86
|
data: {
|
|
80
87
|
conversationMessage: {
|
|
@@ -88,7 +95,7 @@ export const subscriptionQueryMock = jest.fn(id => {
|
|
|
88
95
|
},
|
|
89
96
|
};
|
|
90
97
|
});
|
|
91
|
-
|
|
98
|
+
function buildListRequestMock(query, responseMock, id, searchTerm) {
|
|
92
99
|
return {
|
|
93
100
|
request: {
|
|
94
101
|
query: query,
|
|
@@ -97,16 +104,18 @@ export function buildListRequestMock(query, responseMock, id, searchTerm) {
|
|
|
97
104
|
result: () => responseMock(id),
|
|
98
105
|
};
|
|
99
106
|
}
|
|
100
|
-
|
|
107
|
+
exports.buildListRequestMock = buildListRequestMock;
|
|
108
|
+
function buildSubscriptionRequestMock(id) {
|
|
101
109
|
return {
|
|
102
110
|
request: {
|
|
103
|
-
query: SUBSCRIPTION_QUERY,
|
|
111
|
+
query: queries_1.SUBSCRIPTION_QUERY,
|
|
104
112
|
},
|
|
105
|
-
result: () => subscriptionQueryMock(id),
|
|
113
|
+
result: () => (0, exports.subscriptionQueryMock)(id),
|
|
106
114
|
delay: 100,
|
|
107
115
|
};
|
|
108
116
|
}
|
|
109
|
-
|
|
117
|
+
exports.buildSubscriptionRequestMock = buildSubscriptionRequestMock;
|
|
118
|
+
function buildListRequestMockForNextPage(query, responseMock, id) {
|
|
110
119
|
return {
|
|
111
120
|
request: {
|
|
112
121
|
query: query,
|
|
@@ -115,6 +124,8 @@ export function buildListRequestMockForNextPage(query, responseMock, id) {
|
|
|
115
124
|
result: () => responseMock(id),
|
|
116
125
|
};
|
|
117
126
|
}
|
|
118
|
-
|
|
127
|
+
exports.buildListRequestMockForNextPage = buildListRequestMockForNextPage;
|
|
128
|
+
function setListQueryMockHasNextPage(hasNextPage) {
|
|
119
129
|
listQueryHasNextPage = hasNextPage;
|
|
120
130
|
}
|
|
131
|
+
exports.setListQueryMockHasNextPage = setListQueryMockHasNextPage;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
export declare const LIST_QUERY:
|
|
2
|
-
export declare const LIST_QUERY_WITH_TOTAL_COUNT:
|
|
1
|
+
export declare const LIST_QUERY: import("@apollo/client").DocumentNode;
|
|
2
|
+
export declare const LIST_QUERY_WITH_TOTAL_COUNT: import("@apollo/client").DocumentNode;
|
|
3
3
|
export interface ListQueryType {
|
|
4
4
|
__typename?: "Query";
|
|
5
5
|
conversation?: {
|
|
@@ -25,7 +25,7 @@ export interface ListQueryType {
|
|
|
25
25
|
};
|
|
26
26
|
};
|
|
27
27
|
}
|
|
28
|
-
export declare const SUBSCRIPTION_QUERY:
|
|
28
|
+
export declare const SUBSCRIPTION_QUERY: import("@apollo/client").DocumentNode;
|
|
29
29
|
export interface SubscriptionQueryType {
|
|
30
30
|
__typename?: "Subscription";
|
|
31
31
|
conversationMessage?: {
|
|
@@ -1,5 +1,8 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
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) `
|
|
3
6
|
query ConversationMessages($cursor: string, $searchTerm: string) {
|
|
4
7
|
conversation(id: "MQ==") {
|
|
5
8
|
smsMessages(first: 1, after: $cursor, searchTerm: $searchTerm) {
|
|
@@ -21,7 +24,7 @@ export const LIST_QUERY = gql `
|
|
|
21
24
|
}
|
|
22
25
|
}
|
|
23
26
|
`;
|
|
24
|
-
|
|
27
|
+
exports.LIST_QUERY_WITH_TOTAL_COUNT = (0, client_1.gql) `
|
|
25
28
|
query ConversationMessages($cursor: string, $searchTerm: string) {
|
|
26
29
|
conversation(id: "MQ==") {
|
|
27
30
|
smsMessages(first: 1, after: $cursor, searchTerm: $searchTerm) {
|
|
@@ -44,7 +47,7 @@ export const LIST_QUERY_WITH_TOTAL_COUNT = gql `
|
|
|
44
47
|
}
|
|
45
48
|
}
|
|
46
49
|
`;
|
|
47
|
-
|
|
50
|
+
exports.SUBSCRIPTION_QUERY = (0, client_1.gql) `
|
|
48
51
|
subscription ConversationMessage($conversationId: EncodedId!) {
|
|
49
52
|
conversationMessage(conversationId: $conversationId) {
|
|
50
53
|
smsMessage {
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
"use strict";
|
|
1
2
|
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
2
3
|
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
3
4
|
return new (P || (P = Promise))(function (resolve, reject) {
|
|
@@ -7,8 +8,11 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
7
8
|
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
8
9
|
});
|
|
9
10
|
};
|
|
10
|
-
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
exports.wait = void 0;
|
|
13
|
+
function wait(milliseconds = 0) {
|
|
11
14
|
return __awaiter(this, void 0, void 0, function* () {
|
|
12
15
|
yield new Promise(resolve => setTimeout(resolve, milliseconds));
|
|
13
16
|
});
|
|
14
17
|
}
|
|
18
|
+
exports.wait = wait;
|
|
@@ -1,14 +1,19 @@
|
|
|
1
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.uniqueEdges = exports.createEdge = void 0;
|
|
4
|
+
function createEdge(node) {
|
|
2
5
|
return {
|
|
3
6
|
node: node,
|
|
4
7
|
cursor: "",
|
|
5
8
|
__typename: `${node.__typename}Edge`,
|
|
6
9
|
};
|
|
7
10
|
}
|
|
8
|
-
|
|
11
|
+
exports.createEdge = createEdge;
|
|
12
|
+
function uniqueEdges(edges) {
|
|
9
13
|
const result = new Map();
|
|
10
14
|
edges.forEach(edge => {
|
|
11
15
|
result.set(`${edge.__typename}-${edge.node.__typename}-${edge.node.id}`, edge);
|
|
12
16
|
});
|
|
13
17
|
return Array.from(result.values());
|
|
14
18
|
}
|
|
19
|
+
exports.uniqueEdges = uniqueEdges;
|
|
@@ -1,7 +1,11 @@
|
|
|
1
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.uniqueNodes = void 0;
|
|
4
|
+
function uniqueNodes(nodes) {
|
|
2
5
|
const result = new Map();
|
|
3
6
|
nodes.forEach(node => {
|
|
4
7
|
result.set(`${node.__typename}-${node.id}`, node);
|
|
5
8
|
});
|
|
6
9
|
return Array.from(result.values());
|
|
7
10
|
}
|
|
11
|
+
exports.uniqueNodes = uniqueNodes;
|
|
@@ -1,19 +1,22 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.isAlreadyUpdated = exports.useCollectionQuery = void 0;
|
|
4
|
+
const client_1 = require("@apollo/client");
|
|
5
|
+
const lodash_1 = require("lodash");
|
|
6
|
+
const react_1 = require("react");
|
|
7
|
+
const formatters_1 = require("@jobber/formatters");
|
|
8
|
+
const uniqueNodes_1 = require("./uniqueNodes");
|
|
9
|
+
const uniqueEdges_1 = require("./uniqueEdges");
|
|
10
|
+
const useIsMounted_1 = require("../useIsMounted");
|
|
11
|
+
function useCollectionQuery({ query, queryOptions, getCollectionByPath, subscription, }) {
|
|
9
12
|
var _a, _b;
|
|
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);
|
|
13
|
+
const { data, loading, refetch, error, fetchMore, subscribeToMore } = (0, client_1.useQuery)(query, queryOptions);
|
|
14
|
+
const isMounted = (0, useIsMounted_1.useIsMounted)();
|
|
15
|
+
const [loadingRefresh, setLoadingRefresh] = (0, react_1.useState)(false);
|
|
16
|
+
const [loadingNextPage, setLoadingNextPage] = (0, react_1.useState)(false);
|
|
14
17
|
const loadingInitialContent = loading && !loadingRefresh && !loadingNextPage;
|
|
15
18
|
const isSearching = !!((_a = queryOptions === null || queryOptions === void 0 ? void 0 : queryOptions.variables) === null || _a === void 0 ? void 0 : _a.searchTerm);
|
|
16
|
-
const refresh = useCallback(() => {
|
|
19
|
+
const refresh = (0, react_1.useCallback)(() => {
|
|
17
20
|
if (loadingInitialContent || loadingRefresh) {
|
|
18
21
|
return;
|
|
19
22
|
}
|
|
@@ -26,7 +29,7 @@ export function useCollectionQuery({ query, queryOptions, getCollectionByPath, s
|
|
|
26
29
|
variables: {},
|
|
27
30
|
updateQuery: (prev, { fetchMoreResult }) => fetchMoreResult || prev,
|
|
28
31
|
})
|
|
29
|
-
.catch(err => config.errorNotifier("Refetch Error", err))
|
|
32
|
+
.catch(err => formatters_1.config.errorNotifier("Refetch Error", err))
|
|
30
33
|
.finally(() => {
|
|
31
34
|
if (isMounted.current) {
|
|
32
35
|
setLoadingRefresh(false);
|
|
@@ -39,7 +42,7 @@ export function useCollectionQuery({ query, queryOptions, getCollectionByPath, s
|
|
|
39
42
|
refetch,
|
|
40
43
|
isMounted,
|
|
41
44
|
]);
|
|
42
|
-
const nextPage = useCallback(() => {
|
|
45
|
+
const nextPage = (0, react_1.useCallback)(() => {
|
|
43
46
|
var _a;
|
|
44
47
|
if (loadingInitialContent || loadingRefresh || loadingNextPage) {
|
|
45
48
|
return;
|
|
@@ -55,7 +58,7 @@ export function useCollectionQuery({ query, queryOptions, getCollectionByPath, s
|
|
|
55
58
|
},
|
|
56
59
|
updateQuery: (prev, { fetchMoreResult }) => fetchMoreUpdateQueryHandler(prev, fetchMoreResult, getCollectionByPath),
|
|
57
60
|
})
|
|
58
|
-
.catch(err => config.errorNotifier("FetchMore Error", err))
|
|
61
|
+
.catch(err => formatters_1.config.errorNotifier("FetchMore Error", err))
|
|
59
62
|
.finally(() => {
|
|
60
63
|
if (isMounted.current) {
|
|
61
64
|
setLoadingNextPage(false);
|
|
@@ -71,11 +74,11 @@ export function useCollectionQuery({ query, queryOptions, getCollectionByPath, s
|
|
|
71
74
|
getCollectionByPath,
|
|
72
75
|
isMounted,
|
|
73
76
|
]);
|
|
74
|
-
useEffect(() => {
|
|
77
|
+
(0, react_1.useEffect)(() => {
|
|
75
78
|
if (subscription == undefined)
|
|
76
79
|
return;
|
|
77
80
|
const subscriptionOptions = subscription.options || {};
|
|
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) }));
|
|
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 => formatters_1.config.errorNotifier("Subscribe to More Error", err) }));
|
|
79
82
|
},
|
|
80
83
|
// Disabling this linter so we can force this only run once. If we didn't
|
|
81
84
|
// do this we would need to ensure subscription, subscribeToMore, and getNodeByPath
|
|
@@ -91,6 +94,7 @@ export function useCollectionQuery({ query, queryOptions, getCollectionByPath, s
|
|
|
91
94
|
loadingInitialContent,
|
|
92
95
|
};
|
|
93
96
|
}
|
|
97
|
+
exports.useCollectionQuery = useCollectionQuery;
|
|
94
98
|
/**
|
|
95
99
|
* The following method uses an `output` variable, and indirectly modifies it through the `outputCollection` variable.
|
|
96
100
|
* This type of indirect modification is prone to bugs, but I couldn't think of a better way to write this code.
|
|
@@ -110,7 +114,7 @@ export function useCollectionQuery({ query, queryOptions, getCollectionByPath, s
|
|
|
110
114
|
*/
|
|
111
115
|
function fetchMoreUpdateQueryHandler(prev, fetchMoreResult, getCollectionByPath) {
|
|
112
116
|
const nextCollection = getCollectionByPath(fetchMoreResult);
|
|
113
|
-
const output = cloneDeep(prev);
|
|
117
|
+
const output = (0, lodash_1.cloneDeep)(prev);
|
|
114
118
|
const outputCollection = getCollectionByPath(output);
|
|
115
119
|
if (outputCollection === undefined || nextCollection === undefined) {
|
|
116
120
|
return output;
|
|
@@ -121,12 +125,12 @@ function fetchMoreUpdateQueryHandler(prev, fetchMoreResult, getCollectionByPath)
|
|
|
121
125
|
if (outputCollection.edges && nextCollection.edges) {
|
|
122
126
|
outputCollection.edges = getUpdatedEdges(outputCollection.edges, nextCollection.edges);
|
|
123
127
|
}
|
|
124
|
-
Object.assign(outputCollection, Object.assign({ pageInfo: cloneDeep(nextCollection.pageInfo) }, getTotalCount(nextCollection.totalCount)));
|
|
128
|
+
Object.assign(outputCollection, Object.assign({ pageInfo: (0, lodash_1.cloneDeep)(nextCollection.pageInfo) }, getTotalCount(nextCollection.totalCount)));
|
|
125
129
|
return output;
|
|
126
130
|
}
|
|
127
131
|
function subscribeToMoreHandler(isSearching, prev, getCollectionByPath, subscriptionData, getNodeByPath) {
|
|
128
132
|
const node = getNodeByPath(subscriptionData);
|
|
129
|
-
const output = cloneDeep(prev);
|
|
133
|
+
const output = (0, lodash_1.cloneDeep)(prev);
|
|
130
134
|
const outputCollection = getCollectionByPath(output);
|
|
131
135
|
if (outputCollection == undefined || node == undefined)
|
|
132
136
|
return output;
|
|
@@ -137,9 +141,9 @@ function subscribeToMoreHandler(isSearching, prev, getCollectionByPath, subscrip
|
|
|
137
141
|
outputCollection.nodes = getUpdatedNodes(outputCollection.nodes, [node], false);
|
|
138
142
|
}
|
|
139
143
|
if (outputCollection.edges) {
|
|
140
|
-
outputCollection.edges = getUpdatedEdges(outputCollection.edges, [createEdge(node)], false);
|
|
144
|
+
outputCollection.edges = getUpdatedEdges(outputCollection.edges, [(0, uniqueEdges_1.createEdge)(node)], false);
|
|
141
145
|
}
|
|
142
|
-
Object.assign(outputCollection, Object.assign({ pageInfo: cloneDeep(outputCollection.pageInfo) }, getTotalCount(outputCollection.totalCount, 1)));
|
|
146
|
+
Object.assign(outputCollection, Object.assign({ pageInfo: (0, lodash_1.cloneDeep)(outputCollection.pageInfo) }, getTotalCount(outputCollection.totalCount, 1)));
|
|
143
147
|
return output;
|
|
144
148
|
}
|
|
145
149
|
function getTotalCount(totalCount, additionalCount = 0) {
|
|
@@ -147,7 +151,7 @@ function getTotalCount(totalCount, additionalCount = 0) {
|
|
|
147
151
|
? { totalCount: totalCount + additionalCount }
|
|
148
152
|
: {};
|
|
149
153
|
}
|
|
150
|
-
|
|
154
|
+
function isAlreadyUpdated(outputCollection, newNode) {
|
|
151
155
|
let edgesAlreadyUpdated = true;
|
|
152
156
|
let nodesAlreadyUpdated = true;
|
|
153
157
|
if (outputCollection.edges) {
|
|
@@ -162,15 +166,16 @@ export function isAlreadyUpdated(outputCollection, newNode) {
|
|
|
162
166
|
}
|
|
163
167
|
return edgesAlreadyUpdated && nodesAlreadyUpdated;
|
|
164
168
|
}
|
|
169
|
+
exports.isAlreadyUpdated = isAlreadyUpdated;
|
|
165
170
|
function getUpdatedEdges(prevEdges, nextEdges, appendToEnd = true) {
|
|
166
171
|
const newEdges = appendToEnd
|
|
167
172
|
? [...prevEdges, ...nextEdges]
|
|
168
173
|
: [...nextEdges, ...prevEdges];
|
|
169
|
-
return uniqueEdges(newEdges);
|
|
174
|
+
return (0, uniqueEdges_1.uniqueEdges)(newEdges);
|
|
170
175
|
}
|
|
171
176
|
function getUpdatedNodes(prevNodes, nextNodes, appendToEnd = true) {
|
|
172
177
|
const newNodes = appendToEnd
|
|
173
178
|
? [...prevNodes, ...nextNodes]
|
|
174
179
|
: [...nextNodes, ...prevNodes];
|
|
175
|
-
return uniqueNodes(newNodes);
|
|
180
|
+
return (0, uniqueNodes_1.uniqueNodes)(newNodes);
|
|
176
181
|
}
|