@jobber/hooks 2.0.3-pre.50 → 2.0.3-pre1.52
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.d.ts +10 -10
- package/dist/index.js +11 -26
- package/dist/useAssert/index.d.ts +1 -1
- package/dist/useAssert/index.js +1 -5
- package/dist/useAssert/useAssert.js +3 -10
- package/dist/useCollectionQuery/index.d.ts +1 -1
- package/dist/useCollectionQuery/index.js +1 -5
- package/dist/useCollectionQuery/mdxUtils.d.ts +2 -3
- package/dist/useCollectionQuery/mdxUtils.js +8 -12
- package/dist/useCollectionQuery/test-utilities/index.d.ts +3 -3
- package/dist/useCollectionQuery/test-utilities/index.js +3 -19
- package/dist/useCollectionQuery/test-utilities/mocks.d.ts +1 -1
- package/dist/useCollectionQuery/test-utilities/mocks.js +19 -30
- package/dist/useCollectionQuery/test-utilities/queries.d.ts +3 -3
- package/dist/useCollectionQuery/test-utilities/queries.js +4 -7
- package/dist/useCollectionQuery/test-utilities/utils.js +1 -5
- package/dist/useCollectionQuery/uniqueEdges.d.ts +1 -1
- package/dist/useCollectionQuery/uniqueEdges.js +2 -7
- package/dist/useCollectionQuery/uniqueNodes.js +1 -5
- package/dist/useCollectionQuery/useCollectionQuery.d.ts +2 -2
- package/dist/useCollectionQuery/useCollectionQuery.js +26 -31
- package/dist/useCollectionQuery/useCollectionQuery.test.js +119 -119
- package/dist/useFocusTrap/index.d.ts +1 -1
- package/dist/useFocusTrap/index.js +1 -5
- package/dist/useFocusTrap/useFocusTrap.js +4 -8
- package/dist/useFocusTrap/useFocusTrap.test.js +26 -31
- package/dist/useFormState/index.d.ts +1 -1
- package/dist/useFormState/index.js +1 -5
- package/dist/useFormState/useFormState.js +3 -7
- package/dist/useIsMounted/index.d.ts +1 -1
- package/dist/useIsMounted/index.js +1 -5
- package/dist/useIsMounted/useIsMounted.js +4 -8
- package/dist/useIsMounted/useIsMounted.test.js +4 -6
- package/dist/useLiveAnnounce/index.d.ts +1 -1
- package/dist/useLiveAnnounce/index.js +1 -5
- package/dist/useLiveAnnounce/useLiveAnnounce.js +4 -8
- package/dist/useLiveAnnounce/useLiveAnnounce.test.js +19 -24
- package/dist/useOnKeyDown/index.d.ts +1 -1
- package/dist/useOnKeyDown/index.js +1 -5
- package/dist/useOnKeyDown/useOnKeyDown.js +3 -10
- package/dist/useOnKeyDown/useOnKeyDown.test.js +7 -12
- package/dist/usePasswordStrength/index.d.ts +1 -1
- package/dist/usePasswordStrength/index.js +1 -5
- package/dist/usePasswordStrength/usePasswordStrength.js +4 -11
- package/dist/useRefocusOnActivator/index.d.ts +1 -1
- package/dist/useRefocusOnActivator/index.js +1 -5
- package/dist/useRefocusOnActivator/useRefocusOnActivator.js +3 -7
- package/dist/useResizeObserver/index.d.ts +1 -1
- package/dist/useResizeObserver/index.js +1 -17
- package/dist/useResizeObserver/useResizeObserver.d.ts +1 -2
- package/dist/useResizeObserver/useResizeObserver.js +8 -15
- package/package.json +3 -13
package/dist/index.d.ts
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
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";
|
|
1
|
+
export * from "./useAssert/index.js";
|
|
2
|
+
export * from "./useCollectionQuery/index.js";
|
|
3
|
+
export * from "./useFocusTrap/index.js";
|
|
4
|
+
export * from "./useFormState/index.js";
|
|
5
|
+
export * from "./useIsMounted/index.js";
|
|
6
|
+
export * from "./useLiveAnnounce/index.js";
|
|
7
|
+
export * from "./useOnKeyDown/index.js";
|
|
8
|
+
export * from "./usePasswordStrength/index.js";
|
|
9
|
+
export * from "./useRefocusOnActivator/index.js";
|
|
10
|
+
export * from "./useResizeObserver/index.js";
|
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
|
+
/* eslint-disable import/no-internal-modules */
|
|
2
|
+
export * from "./useAssert/index.js";
|
|
3
|
+
export * from "./useCollectionQuery/index.js";
|
|
4
|
+
export * from "./useFocusTrap/index.js";
|
|
5
|
+
export * from "./useFormState/index.js";
|
|
6
|
+
export * from "./useIsMounted/index.js";
|
|
7
|
+
export * from "./useLiveAnnounce/index.js";
|
|
8
|
+
export * from "./useOnKeyDown/index.js";
|
|
9
|
+
export * from "./usePasswordStrength/index.js";
|
|
10
|
+
export * from "./useRefocusOnActivator/index.js";
|
|
11
|
+
export * from "./useResizeObserver/index.js";
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export { useAssert } from "./useAssert";
|
|
1
|
+
export { useAssert } from "./useAssert.js";
|
package/dist/useAssert/index.js
CHANGED
|
@@ -1,5 +1 @@
|
|
|
1
|
-
|
|
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
|
+
export { useAssert } from "./useAssert.js";
|
|
@@ -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,3 @@ function useAssert(shouldShow, message, options) {
|
|
|
15
9
|
}
|
|
16
10
|
}
|
|
17
11
|
}
|
|
18
|
-
exports.useAssert = useAssert;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export { useCollectionQuery } from "./useCollectionQuery";
|
|
1
|
+
export { useCollectionQuery } from "./useCollectionQuery.js";
|
|
@@ -1,5 +1 @@
|
|
|
1
|
-
|
|
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
|
+
export { useCollectionQuery } from "./useCollectionQuery.js";
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import { ApolloClient } from "@apollo/client";
|
|
2
1
|
export interface ListQueryType {
|
|
3
2
|
allPlanets: {
|
|
4
3
|
__typename?: "PlanetsConnection";
|
|
@@ -18,8 +17,8 @@ export interface ListQueryType {
|
|
|
18
17
|
totalCount?: number;
|
|
19
18
|
};
|
|
20
19
|
}
|
|
21
|
-
export declare const LIST_QUERY:
|
|
22
|
-
export declare const apolloClient:
|
|
20
|
+
export declare const LIST_QUERY: any;
|
|
21
|
+
export declare const apolloClient: any;
|
|
23
22
|
interface LoadingState {
|
|
24
23
|
loadingStatus: string;
|
|
25
24
|
loading: boolean;
|
|
@@ -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",
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
export * from "./queries";
|
|
2
|
-
export * from "./utils";
|
|
3
|
-
export * from "./mocks";
|
|
1
|
+
export * from "./queries.js";
|
|
2
|
+
export * from "./utils.js";
|
|
3
|
+
export * from "./mocks.js";
|
|
@@ -1,19 +1,3 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
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
|
+
export * from "./queries.js";
|
|
2
|
+
export * from "./utils.js";
|
|
3
|
+
export * from "./mocks.js";
|
|
@@ -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.js";
|
|
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,6 @@ 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
|
-
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: any;
|
|
2
|
+
export declare const LIST_QUERY_WITH_TOTAL_COUNT: any;
|
|
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: any;
|
|
29
29
|
export interface SubscriptionQueryType {
|
|
30
30
|
__typename?: "Subscription";
|
|
31
31
|
conversationMessage?: {
|
|
@@ -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 {
|
|
@@ -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,8 @@ 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
|
-
exports.wait = wait;
|
|
@@ -1,19 +1,14 @@
|
|
|
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
|
-
exports.uniqueEdges = uniqueEdges;
|
|
@@ -1,11 +1,7 @@
|
|
|
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
|
-
exports.uniqueNodes = uniqueNodes;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { ApolloError, DocumentNode, QueryHookOptions, SubscribeToMoreOptions } from "@apollo/client";
|
|
2
|
-
import { Node } from "./uniqueNodes";
|
|
3
|
-
import { Edge } from "./uniqueEdges";
|
|
2
|
+
import { Node } from "./uniqueNodes.js";
|
|
3
|
+
import { Edge } from "./uniqueEdges.js";
|
|
4
4
|
interface UseCollectionQueryArguments<TQuery, TSubscription> {
|
|
5
5
|
/**
|
|
6
6
|
* The graphQL query that fetches the collection
|
|
@@ -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.js";
|
|
6
|
+
import { createEdge, uniqueEdges } from "./uniqueEdges.js";
|
|
7
|
+
import { useIsMounted } from "../useIsMounted/index.js";
|
|
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,15 @@ 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
|
}
|