@unitedstatespowersquadrons/components 1.4.0-1 → 1.4.0-3

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.
@@ -14,10 +14,8 @@ interface BroadcastPayload {
14
14
  dismissToast?: number;
15
15
  }
16
16
 
17
- const sortBroadcastsFirst = (toasts: ReadonlyArray<ToastProps>): ToastProps[] => (
18
- [...toasts].sort((a, b) => (
19
- Number(b.kind === "broadcast") - Number(a.kind === "broadcast")
20
- ))
17
+ const sortBroadcastsFirst = (toasts: readonly ToastProps[]): ToastProps[] => (
18
+ [...toasts].sort((a, b) => Number(b.kind === "broadcast") - Number(a.kind === "broadcast"))
21
19
  );
22
20
 
23
21
  const GlobalToasts = ({ allowedDomains }: Props) => {
@@ -29,12 +27,8 @@ const GlobalToasts = ({ allowedDomains }: Props) => {
29
27
  { channel: "BroadcastToastChannel" },
30
28
  {
31
29
  received: (data: BroadcastPayload) => {
32
- if (data.toasts) {
33
- data.toasts.forEach(t => toastStore.add({ ...t, kind: "broadcast" }));
34
- }
35
- if (typeof data.dismissToast === "number") {
36
- toastStore.remove(data.dismissToast);
37
- }
30
+ if (data.toasts) data.toasts.forEach(t => toastStore.add({ kind: "broadcast", ...t }));
31
+ if (typeof data.dismissToast === "number") toastStore.remove(data.dismissToast);
38
32
  },
39
33
  }
40
34
  );
@@ -42,19 +36,13 @@ const GlobalToasts = ({ allowedDomains }: Props) => {
42
36
 
43
37
  return () => {
44
38
  sub.unsubscribe();
45
- if (broadcastSubscriptionRef.current === sub) {
46
- broadcastSubscriptionRef.current = null;
47
- }
39
+ if (broadcastSubscriptionRef.current === sub) broadcastSubscriptionRef.current = null;
48
40
  };
49
41
  }, []);
50
42
 
51
- return (
52
- <Toasts
53
- allowedDomains={allowedDomains}
54
- dismiss={dismissToastGlobal}
55
- toasts={sortBroadcastsFirst(toasts)}
56
- />
57
- );
43
+ const sorted = sortBroadcastsFirst(toasts);
44
+
45
+ return <Toasts allowedDomains={allowedDomains} dismiss={dismissToastGlobal} toasts={sorted} />;
58
46
  };
59
47
 
60
48
  export default GlobalToasts;
package/Toasts/Toast.tsx CHANGED
@@ -155,7 +155,10 @@ const Toast = (props: Props) => {
155
155
  const opacityClass = dismissed ? classes.dismissed : classes.visible;
156
156
 
157
157
  return (
158
- <div className={classNames(classes.toast, statusClassName, opacityClass, isBroadcast && classes.broadcast)} key={`toast-${id}`}>
158
+ <div
159
+ className={classNames(classes.toast, statusClassName, opacityClass, isBroadcast && classes.broadcast)}
160
+ key={`toast-${id}`}
161
+ >
159
162
  <div className={classes.toastTitle}>
160
163
  <FontAwesomeIcon fa="fw" icon={icon} mode="duotone" />
161
164
  {isBroadcast && <span className={classes.broadcastTag}>Broadcast</span>}
package/Toasts/Toasts.tsx CHANGED
@@ -7,7 +7,7 @@ import { DismissFunc, ToastProps, ToastRemoveAppAction } from "./types";
7
7
  import { DispatchFunc } from "../";
8
8
 
9
9
  interface BaseProps {
10
- allowedDomains?: string[];
10
+ allowedDomains?: string[] | undefined;
11
11
  toasts?: ToastProps[];
12
12
  }
13
13
 
@@ -81,6 +81,6 @@ const subscribe = (listener: Listener): (() => void) => {
81
81
  return () => { listeners.delete(listener); };
82
82
  };
83
83
 
84
- const getSnapshot = (): ReadonlyArray<ToastProps> => toasts;
84
+ const getSnapshot = (): readonly ToastProps[] => toasts;
85
85
 
86
86
  export const toastStore = { add, clear, dismiss, getSnapshot, remove, subscribe };
@@ -8,6 +8,7 @@ export const useBroadcastChannel = (): BroadcastChannelHandle => ({
8
8
  send: (data: object) => {
9
9
  const sub = broadcastSubscriptionRef.current;
10
10
  if (!sub) {
11
+ // eslint-disable-next-line no-console
11
12
  console.warn("useBroadcastChannel: <GlobalToasts /> is not mounted; broadcast send ignored");
12
13
  return;
13
14
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@unitedstatespowersquadrons/components",
3
- "version": "1.4.0-1",
3
+ "version": "1.4.0-3",
4
4
  "description": "USPS shared React components library",
5
5
  "main": "index.tsx",
6
6
  "scripts": {