@jobber/hooks 2.6.3-JOB-80005.6 → 2.7.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/README.mdx +1 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.js +1 -0
- package/dist/useBool/index.d.ts +1 -0
- package/dist/useBool/index.js +5 -0
- package/dist/useBool/useBool.d.ts +13 -0
- package/dist/useBool/useBool.js +12 -0
- package/dist/useBool/useBool.test.d.ts +1 -0
- package/dist/useBool/useBool.test.js +28 -0
- package/dist/useCollectionQuery/useCollectionQuery.js +3 -0
- package/dist/useCollectionQuery/useCollectionQuery.test.js +7 -0
- package/package.json +3 -3
- package/useBool.d.ts +1 -0
- package/useBool.js +17 -0
package/README.mdx
CHANGED
|
@@ -5,6 +5,7 @@ Shared hooks for components in Atlantis.
|
|
|
5
5
|
## Hooks
|
|
6
6
|
|
|
7
7
|
- [useAssert](../?path=/docs/hooks-useassert--page)
|
|
8
|
+
- [useBool](../?path=/docs/hooks-usebool--page)
|
|
8
9
|
- [useCollectionQuery](../?path=/docs/hooks-usecollectionquery--use-collection-query)
|
|
9
10
|
- [useFormState](../?path=/docs/hooks-useformstate--use-form-state)
|
|
10
11
|
- [useIsMounted](../?path=/docs/hooks-useismounted--use-is-mounted)
|
package/dist/index.d.ts
CHANGED
package/dist/index.js
CHANGED
|
@@ -15,6 +15,7 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
15
15
|
};
|
|
16
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
17
|
__exportStar(require("./useAssert"), exports);
|
|
18
|
+
__exportStar(require("./useBool"), exports);
|
|
18
19
|
__exportStar(require("./useBreakpoints"), exports);
|
|
19
20
|
__exportStar(require("./useCollectionQuery"), exports);
|
|
20
21
|
__exportStar(require("./useFocusTrap"), exports);
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { useBool } from "./useBool";
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
declare const brand: unique symbol;
|
|
2
|
+
type Callback = () => void;
|
|
3
|
+
export type SetTrue = Callback & {
|
|
4
|
+
[brand]: "SetTrue";
|
|
5
|
+
};
|
|
6
|
+
export type SetFalse = Callback & {
|
|
7
|
+
[brand]: "SetFalse";
|
|
8
|
+
};
|
|
9
|
+
export type Toggle = Callback & {
|
|
10
|
+
[brand]: "Toggle";
|
|
11
|
+
};
|
|
12
|
+
export declare function useBool(initialState?: boolean): [boolean, SetTrue, SetFalse, Toggle];
|
|
13
|
+
export {};
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.useBool = void 0;
|
|
4
|
+
const react_1 = require("react");
|
|
5
|
+
function useBool(initialState = false) {
|
|
6
|
+
const [state, setState] = (0, react_1.useState)(initialState);
|
|
7
|
+
const setTrue = (0, react_1.useCallback)(() => setState(true), []);
|
|
8
|
+
const setFalse = (0, react_1.useCallback)(() => setState(false), []);
|
|
9
|
+
const toggle = (0, react_1.useCallback)(() => setState(current => !current), []);
|
|
10
|
+
return [state, setTrue, setFalse, toggle];
|
|
11
|
+
}
|
|
12
|
+
exports.useBool = useBool;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const react_1 = require("@testing-library/react");
|
|
4
|
+
const useBool_1 = require("./useBool");
|
|
5
|
+
describe("useBool, a hook for managing boolean state", () => {
|
|
6
|
+
it("by default has an initial state that is `false`", () => {
|
|
7
|
+
const [value] = (0, react_1.renderHook)(() => (0, useBool_1.useBool)()).result.current;
|
|
8
|
+
expect(value).toBe(false);
|
|
9
|
+
});
|
|
10
|
+
it("can be provided an initial state", () => {
|
|
11
|
+
const [value] = (0, react_1.renderHook)(() => (0, useBool_1.useBool)(true)).result.current;
|
|
12
|
+
expect(value).toBe(true);
|
|
13
|
+
});
|
|
14
|
+
it("provides helpful setters and a toggle method", () => {
|
|
15
|
+
const { result } = (0, react_1.renderHook)(() => (0, useBool_1.useBool)());
|
|
16
|
+
const value = () => result.current[0];
|
|
17
|
+
const [, setTrue, setFalse, toggle] = result.current;
|
|
18
|
+
expect(value()).toBe(false);
|
|
19
|
+
(0, react_1.act)(setTrue);
|
|
20
|
+
expect(value()).toBe(true);
|
|
21
|
+
(0, react_1.act)(setFalse);
|
|
22
|
+
expect(value()).toBe(false);
|
|
23
|
+
(0, react_1.act)(toggle);
|
|
24
|
+
expect(value()).toBe(true);
|
|
25
|
+
(0, react_1.act)(toggle);
|
|
26
|
+
expect(value()).toBe(false);
|
|
27
|
+
});
|
|
28
|
+
});
|
|
@@ -56,6 +56,7 @@ function useCollectionQuery({ query, queryOptions, getCollectionByPath, subscrip
|
|
|
56
56
|
return;
|
|
57
57
|
}
|
|
58
58
|
setLoadingNextPage(true);
|
|
59
|
+
setHookError(undefined);
|
|
59
60
|
fetchMore({
|
|
60
61
|
variables: {
|
|
61
62
|
cursor: pageInfo.endCursor,
|
|
@@ -85,6 +86,8 @@ function useCollectionQuery({ query, queryOptions, getCollectionByPath, subscrip
|
|
|
85
86
|
if (subscription == undefined)
|
|
86
87
|
return;
|
|
87
88
|
const subscriptionOptions = subscription.options || {};
|
|
89
|
+
// Reset this state so we can handle errors from the subscription
|
|
90
|
+
setHookError(undefined);
|
|
88
91
|
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 => {
|
|
89
92
|
formatters_1.config.errorNotifier("Subscribe to More Error", err);
|
|
90
93
|
setHookError(err);
|
|
@@ -226,6 +226,7 @@ describe("useCollectionQuery", () => {
|
|
|
226
226
|
},
|
|
227
227
|
error: mockError,
|
|
228
228
|
},
|
|
229
|
+
(0, test_utilities_1.buildListRequestMockForNextPage)(query, responseMock),
|
|
229
230
|
]),
|
|
230
231
|
});
|
|
231
232
|
yield (0, react_hooks_1.act)(test_utilities_1.wait);
|
|
@@ -234,6 +235,12 @@ describe("useCollectionQuery", () => {
|
|
|
234
235
|
});
|
|
235
236
|
yield (0, react_hooks_1.act)(test_utilities_1.wait);
|
|
236
237
|
expect(result.current.error).toEqual(mockError);
|
|
238
|
+
// should clear the error after a successful fetch
|
|
239
|
+
(0, react_hooks_1.act)(() => {
|
|
240
|
+
result.current.nextPage();
|
|
241
|
+
});
|
|
242
|
+
yield (0, react_hooks_1.act)(test_utilities_1.wait);
|
|
243
|
+
expect(result.current.error).toBeUndefined();
|
|
237
244
|
}));
|
|
238
245
|
});
|
|
239
246
|
});
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@jobber/hooks",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.7.0",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"main": "./dist/index.js",
|
|
6
6
|
"types": "./dist/index.d.js",
|
|
@@ -20,7 +20,7 @@
|
|
|
20
20
|
],
|
|
21
21
|
"devDependencies": {
|
|
22
22
|
"@apollo/react-testing": "^4.0.0",
|
|
23
|
-
"@jobber/formatters": "
|
|
23
|
+
"@jobber/formatters": "*",
|
|
24
24
|
"@testing-library/react": "^14.0.0",
|
|
25
25
|
"@testing-library/react-hooks": "^7.0.0",
|
|
26
26
|
"@testing-library/user-event": "^14.5.1",
|
|
@@ -45,5 +45,5 @@
|
|
|
45
45
|
"@apollo/client": "^3.0.0",
|
|
46
46
|
"react": "^18"
|
|
47
47
|
},
|
|
48
|
-
"gitHead": "
|
|
48
|
+
"gitHead": "7d69952a16458e6fcafd0a5e4215bab444d074dc"
|
|
49
49
|
}
|
package/useBool.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from "./dist/useBool";
|
package/useBool.js
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true,
|
|
5
|
+
});
|
|
6
|
+
|
|
7
|
+
var useBool = require("./dist/useBool");
|
|
8
|
+
|
|
9
|
+
Object.keys(useBool).forEach(function(key) {
|
|
10
|
+
if (key === "default" || key === "__esModule") return;
|
|
11
|
+
Object.defineProperty(exports, key, {
|
|
12
|
+
enumerable: true,
|
|
13
|
+
get: function get() {
|
|
14
|
+
return useBool[key];
|
|
15
|
+
},
|
|
16
|
+
});
|
|
17
|
+
});
|