@knocklabs/react-core 0.4.0 → 0.5.0-rc.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/CHANGELOG.md +11 -0
- package/dist/cjs/modules/core/context/KnockProvider.js.map +1 -1
- package/dist/cjs/modules/core/hooks/useAuthenticatedKnockClient.js.map +1 -1
- package/dist/cjs/modules/core/hooks/useStableOptions.js +1 -1
- package/dist/cjs/modules/core/hooks/useStableOptions.js.map +1 -1
- package/dist/cjs/modules/core/utils.js.map +1 -1
- package/dist/cjs/modules/feed/context/KnockFeedProvider.js.map +1 -1
- package/dist/cjs/modules/feed/hooks/useFeedSettings.js.map +1 -1
- package/dist/cjs/modules/feed/hooks/useNotificationStore.js +1 -1
- package/dist/cjs/modules/feed/hooks/useNotificationStore.js.map +1 -1
- package/dist/cjs/modules/feed/hooks/useNotifications.js.map +1 -1
- package/dist/cjs/modules/i18n/context/KnockI18nProvider.js.map +1 -1
- package/dist/cjs/modules/i18n/hooks/useTranslations.js.map +1 -1
- package/dist/cjs/modules/ms-teams/context/KnockMsTeamsProvider.js.map +1 -1
- package/dist/cjs/modules/ms-teams/hooks/useConnectedMsTeamsChannels.js.map +1 -1
- package/dist/cjs/modules/ms-teams/hooks/useMsTeamsAuth.js.map +1 -1
- package/dist/cjs/modules/ms-teams/hooks/useMsTeamsChannels.js.map +1 -1
- package/dist/cjs/modules/ms-teams/hooks/useMsTeamsConnectionStatus.js.map +1 -1
- package/dist/cjs/modules/ms-teams/hooks/useMsTeamsTeams.js.map +1 -1
- package/dist/cjs/modules/slack/context/KnockSlackProvider.js.map +1 -1
- package/dist/cjs/modules/slack/hooks/useConnectedSlackChannels.js.map +1 -1
- package/dist/cjs/modules/slack/hooks/useSlackAuth.js.map +1 -1
- package/dist/cjs/modules/slack/hooks/useSlackChannels.js.map +1 -1
- package/dist/cjs/modules/slack/hooks/useSlackConnectionStatus.js.map +1 -1
- package/dist/esm/modules/core/context/KnockProvider.mjs.map +1 -1
- package/dist/esm/modules/core/hooks/useAuthenticatedKnockClient.mjs.map +1 -1
- package/dist/esm/modules/core/hooks/useStableOptions.mjs +1 -1
- package/dist/esm/modules/core/hooks/useStableOptions.mjs.map +1 -1
- package/dist/esm/modules/core/utils.mjs.map +1 -1
- package/dist/esm/modules/feed/context/KnockFeedProvider.mjs.map +1 -1
- package/dist/esm/modules/feed/hooks/useFeedSettings.mjs.map +1 -1
- package/dist/esm/modules/feed/hooks/useNotificationStore.mjs +7 -13
- package/dist/esm/modules/feed/hooks/useNotificationStore.mjs.map +1 -1
- package/dist/esm/modules/feed/hooks/useNotifications.mjs.map +1 -1
- package/dist/esm/modules/i18n/context/KnockI18nProvider.mjs.map +1 -1
- package/dist/esm/modules/i18n/hooks/useTranslations.mjs.map +1 -1
- package/dist/esm/modules/ms-teams/context/KnockMsTeamsProvider.mjs.map +1 -1
- package/dist/esm/modules/ms-teams/hooks/useConnectedMsTeamsChannels.mjs.map +1 -1
- package/dist/esm/modules/ms-teams/hooks/useMsTeamsAuth.mjs.map +1 -1
- package/dist/esm/modules/ms-teams/hooks/useMsTeamsChannels.mjs.map +1 -1
- package/dist/esm/modules/ms-teams/hooks/useMsTeamsConnectionStatus.mjs.map +1 -1
- package/dist/esm/modules/ms-teams/hooks/useMsTeamsTeams.mjs.map +1 -1
- package/dist/esm/modules/slack/context/KnockSlackProvider.mjs.map +1 -1
- package/dist/esm/modules/slack/hooks/useConnectedSlackChannels.mjs.map +1 -1
- package/dist/esm/modules/slack/hooks/useSlackAuth.mjs.map +1 -1
- package/dist/esm/modules/slack/hooks/useSlackChannels.mjs.map +1 -1
- package/dist/esm/modules/slack/hooks/useSlackConnectionStatus.mjs.map +1 -1
- package/dist/types/modules/feed/context/KnockFeedProvider.d.ts +2 -2
- package/dist/types/modules/feed/context/KnockFeedProvider.d.ts.map +1 -1
- package/dist/types/modules/feed/hooks/useNotificationStore.d.ts +13 -3
- package/dist/types/modules/feed/hooks/useNotificationStore.d.ts.map +1 -1
- package/package.json +8 -6
- package/src/modules/core/hooks/useStableOptions.ts +1 -1
- package/src/modules/feed/context/KnockFeedProvider.tsx +2 -2
- package/src/modules/feed/hooks/useNotificationStore.ts +44 -33
|
@@ -1,44 +1,55 @@
|
|
|
1
|
-
import { Feed, FeedStoreState } from "@knocklabs/client";
|
|
2
|
-
import * as React from "react";
|
|
3
|
-
import type { DispatchWithoutAction } from "react";
|
|
4
|
-
import create, { StateSelector } from "zustand";
|
|
1
|
+
import { Feed, type FeedStoreState } from "@knocklabs/client";
|
|
5
2
|
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
//
|
|
3
|
+
// A hook designed to create a `UseBoundStore` instance.
|
|
4
|
+
// We used to have to do some extra work to do this, but
|
|
5
|
+
// with zustand updated we can just use the feedClient.store
|
|
6
|
+
// directly.
|
|
10
7
|
function useCreateNotificationStore(feedClient: Feed) {
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
[feedClient],
|
|
14
|
-
);
|
|
15
|
-
|
|
16
|
-
// Warning: this is a hack that will cause any components downstream to re-render
|
|
17
|
-
// as a result of the store updating.
|
|
18
|
-
const [, forceUpdate] = React.useReducer((c) => c + 1, 0) as [
|
|
19
|
-
never,
|
|
20
|
-
() => void,
|
|
21
|
-
];
|
|
22
|
-
|
|
23
|
-
useIsomorphicLayoutEffect(() => {
|
|
24
|
-
const rerender = forceUpdate as DispatchWithoutAction;
|
|
25
|
-
const unsubscribe = feedClient.store.subscribe(rerender);
|
|
8
|
+
return feedClient.store;
|
|
9
|
+
}
|
|
26
10
|
|
|
27
|
-
|
|
11
|
+
/**
|
|
12
|
+
* Below we do some typing to specify that if a selector is provided,
|
|
13
|
+
* the return type will be the type returned by the selector.
|
|
14
|
+
*
|
|
15
|
+
* This is important because the store state type is not always the same as the
|
|
16
|
+
* return type of the selector.
|
|
17
|
+
*
|
|
18
|
+
*/
|
|
28
19
|
|
|
29
|
-
|
|
30
|
-
|
|
20
|
+
type StateSelector<T, U> = (state: T) => U;
|
|
21
|
+
type FeedStoreStateSelector<T> = StateSelector<FeedStoreState, T>;
|
|
31
22
|
|
|
32
|
-
|
|
33
|
-
|
|
23
|
+
// Function overload for when no selector is provided
|
|
24
|
+
function useNotificationStore(feedClient: Feed): FeedStoreState;
|
|
34
25
|
|
|
35
|
-
//
|
|
36
|
-
function useNotificationStore(
|
|
26
|
+
// Function overload for when a selector is provided
|
|
27
|
+
function useNotificationStore<T>(
|
|
28
|
+
feedClient: Feed,
|
|
29
|
+
selector: FeedStoreStateSelector<T>,
|
|
30
|
+
): T;
|
|
31
|
+
|
|
32
|
+
/**
|
|
33
|
+
* A hook used to access content within the notification store.
|
|
34
|
+
*
|
|
35
|
+
* A selector can be used to access a subset of the store state.
|
|
36
|
+
*
|
|
37
|
+
* @example
|
|
38
|
+
*
|
|
39
|
+
* ```ts
|
|
40
|
+
* const { items, metadata } = useNotificationStore(feedClient, (state) => ({
|
|
41
|
+
* items: state.items,
|
|
42
|
+
* metadata: state.metadata,
|
|
43
|
+
* }));
|
|
44
|
+
* ```
|
|
45
|
+
*/
|
|
46
|
+
function useNotificationStore<T>(
|
|
37
47
|
feedClient: Feed,
|
|
38
|
-
selector?:
|
|
39
|
-
) {
|
|
48
|
+
selector?: FeedStoreStateSelector<T>,
|
|
49
|
+
): T | FeedStoreState {
|
|
40
50
|
const useStore = useCreateNotificationStore(feedClient);
|
|
41
|
-
|
|
51
|
+
const storeState = useStore();
|
|
52
|
+
return selector ? selector(storeState) : storeState;
|
|
42
53
|
}
|
|
43
54
|
|
|
44
55
|
export { useCreateNotificationStore };
|