@rpcbase/client 0.180.0-notifications.0 → 0.180.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.
@@ -13,7 +13,7 @@ import {flagValues} from "config/flags"
13
13
 
14
14
  import {POSTHOG_KEY} from "env"
15
15
  import { useAuthRouter } from "../auth/useAuthRouter"
16
- import { NotificationsProvider, NotificationsList } from "../notifications"
16
+ import { NotificationsProvider, NotificationsContainer } from "../notifications"
17
17
 
18
18
 
19
19
  const PostHogWrapper = ({children, ...props}) => {
@@ -62,7 +62,7 @@ const AppProvider = ({children, ...props}) => {
62
62
  {children}
63
63
  </div>
64
64
  {authComponent}
65
- <NotificationsList />
65
+ <NotificationsContainer />
66
66
  </NotificationsProvider>
67
67
  </HashStateProvider>
68
68
  </PostHogWrapper>
@@ -27,7 +27,7 @@ export const SignOut = ({
27
27
  }) => {
28
28
  const {t} = useTranslation("rb.sign_out", {useSuspense: false})
29
29
 
30
- const {addToast} = useNotifications()
30
+ const {addNotification} = useNotifications()
31
31
 
32
32
  const [isSignedOut, setIsSignedOut] = useState(false)
33
33
 
@@ -54,7 +54,7 @@ export const SignOut = ({
54
54
  signOut()
55
55
  setIsSignedOut(true)
56
56
 
57
- const toast = addToast({
57
+ const toast = addNotification({
58
58
  // id: `create-template-${Date.now()}`,
59
59
  loading: false,
60
60
  title: "Signed out",
@@ -2,7 +2,6 @@
2
2
  import assert from "assert"
3
3
  import {useRef} from "react"
4
4
  import Toast from "react-bootstrap/Toast"
5
- import {CSSTransition} from "react-transition-group"
6
5
 
7
6
  import {useNotifications} from "../NotificationsContext"
8
7
 
@@ -11,10 +10,10 @@ import HeaderStatus from "./HeaderStatus"
11
10
  // TODO: mv to rb server
12
11
  // import ack_notification from "rpc!server/notifications/ack_notification"
13
12
 
14
- import "./notification-toast.scss"
13
+ import "./notification-item.scss"
15
14
 
16
15
 
17
- const NotificationToast = ({ nodeRef, notification }) => {
16
+ export const NotificationItem = ({ nodeRef, notification }) => {
18
17
  const { setNotifications } = useNotifications()
19
18
 
20
19
  const { isLoading = false, status = "success", zIndex = 999 } = notification
@@ -46,7 +45,8 @@ const NotificationToast = ({ nodeRef, notification }) => {
46
45
  return (
47
46
  <Toast
48
47
  ref={nodeRef}
49
- className={cx("notifs-item mt-2 notification-toast", {"has-no-body": !hasBody})}
48
+ id={notification.id}
49
+ className={cx("notification-item mt-2 notification-toast", {"has-no-body": !hasBody})}
50
50
  style={{position: "relative", zIndex}}
51
51
  onClose={onClose}
52
52
  animation={false}
@@ -63,5 +63,3 @@ const NotificationToast = ({ nodeRef, notification }) => {
63
63
  </Toast>
64
64
  )
65
65
  }
66
-
67
- export default NotificationToast
@@ -1,6 +1,6 @@
1
1
  @import "helpers";
2
2
 
3
- .notification-toast.toast {
3
+ .notification-item.toast {
4
4
  max-width: 260px;
5
5
 
6
6
  .toast-header {
@@ -0,0 +1,37 @@
1
+ /* @flow */
2
+ import {createRef} from "react"
3
+ import {CSSTransition, TransitionGroup} from "react-transition-group"
4
+
5
+ import ToastContainer from "react-bootstrap/ToastContainer"
6
+
7
+ // import {useQuery} from "@rpcbase/client/rts"
8
+
9
+ import {useNotifications} from "../NotificationsContext"
10
+ import {NotificationItem} from "../NotificationItem"
11
+
12
+ // import useLLTs from "./useLLTs"
13
+
14
+ import "./notifications-container.scss"
15
+
16
+ export const NotificationsContainer = () => {
17
+ const {notifications} = useNotifications()
18
+
19
+ const renderNotification = (notification, i) => {
20
+ const key = notification.id
21
+ const nodeRef = createRef()
22
+
23
+ return (
24
+ <CSSTransition key={notification.id} nodeRef={nodeRef} timeout={200} classNames="notification-item">
25
+ <NotificationItem key={key} nodeRef={nodeRef} notification={notification} />
26
+ </CSSTransition>
27
+ )
28
+ }
29
+
30
+ return (
31
+ <ToastContainer id="notifications-container" position="bottom-end" className="pb-4 pe-3 ps-4">
32
+ <TransitionGroup className="transition-list">
33
+ {notifications.map(renderNotification)}
34
+ </TransitionGroup>
35
+ </ToastContainer>
36
+ )
37
+ }
@@ -2,7 +2,12 @@
2
2
 
3
3
  $transition-duration: 200ms;
4
4
 
5
- .notifications-list-wrapper {
5
+ #notifications-container {
6
+ position: absolute;
7
+ bottom: 0;
8
+ right: 0;
9
+ max-height: 100vh;
10
+ overflow-y: scroll;
6
11
 
7
12
  .action-notification {
8
13
  cursor: pointer;
@@ -12,20 +17,20 @@ $transition-duration: 200ms;
12
17
  transition: max-height $transition-duration ease-in-out;
13
18
  }
14
19
 
15
- .notifs-item-enter {
20
+ .notification-item-enter {
16
21
  opacity: 0;
17
22
  }
18
23
 
19
- .notifs-item-enter-active {
24
+ .notification-item-enter-active {
20
25
  opacity: 1;
21
26
  transition: opacity 400ms;
22
27
  }
23
28
 
24
- .notifs-item-exit {
29
+ .notification-item-exit {
25
30
  opacity: 1;
26
31
  }
27
32
 
28
- .notifs-item-exit-active {
33
+ .notification-item-exit-active {
29
34
  transform: translateX(390px);
30
35
 
31
36
  transition: all $transition-duration ease-out;
@@ -11,22 +11,9 @@ import {useNotificationsList} from "./useNotificationsList"
11
11
  export const NotificationsContext = createContext()
12
12
 
13
13
  export const NotificationsProvider = ({value, children}) => {
14
- const [notifications, setNotifications] = useNotificationsList([
15
- // WARNING: Debug only, this breaks unit tests
16
- {
17
- title: "Hello world",
18
- body: "helloooooo",
19
- timestamp: Date.now(),
20
- level: "error",
21
- icon: "error",
22
- },
23
- ])
14
+ const [notifications, setNotifications] = useNotificationsList([])
24
15
 
25
- // A toast is displayed with notifications, but it is ephemeral and in the UI only
26
- // they are used to provide feedback on an action that is a little longer than a simple form submit
27
- // they are gone when the page refreshes
28
- // toasts appear above modals
29
- const addToast = ({
16
+ const addNotification = ({
30
17
  id,
31
18
  title,
32
19
  body,
@@ -34,7 +21,7 @@ export const NotificationsProvider = ({value, children}) => {
34
21
  zIndex = 2000,
35
22
  isLoading = false,
36
23
  }) => {
37
- const toast = {
24
+ const notification = {
38
25
  id: id || `notif-${Date.now().toString()}`,
39
26
  title,
40
27
  body,
@@ -47,26 +34,26 @@ export const NotificationsProvider = ({value, children}) => {
47
34
 
48
35
  setNotifications((current) => {
49
36
  const next = [...current]
50
- next.push(toast)
37
+ next.push(notification)
51
38
  return next
52
39
  })
53
40
 
54
41
  const dismiss = () => {
55
42
  setNotifications((current) => {
56
43
  const next = [...current]
57
- return next.filter((notif) => notif.id !== id)
44
+ return next.filter((n) => n.id !== id)
58
45
  })
59
46
  }
60
47
 
61
48
  const update = (payload) => {
62
49
  setNotifications((current) => {
63
50
  const next = [...current]
64
- return next.map((notif) => {
65
- if (notif.id === id) {
66
- // notif.isLoading = false
67
- Object.assign(notif, payload)
51
+ return next.map((n) => {
52
+ if (n.id === id) {
53
+ // n.isLoading = false
54
+ Object.assign(n, payload)
68
55
  }
69
- return notif
56
+ return n
70
57
  })
71
58
  })
72
59
  }
@@ -75,7 +62,7 @@ export const NotificationsProvider = ({value, children}) => {
75
62
  }
76
63
 
77
64
  return (
78
- <NotificationsContext.Provider value={{notifications, setNotifications, addToast}}>
65
+ <NotificationsContext.Provider value={{notifications, setNotifications, addNotification}}>
79
66
  {children}
80
67
  </NotificationsContext.Provider>
81
68
  )
@@ -1,4 +1,4 @@
1
1
  export * from "./NotificationsContext"
2
- export * from "./NotificationsList"
2
+ export * from "./NotificationsContainer"
3
3
 
4
4
  export * from "./config"
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rpcbase/client",
3
- "version": "0.180.0-notifications.0",
3
+ "version": "0.180.0",
4
4
  "scripts": {
5
5
  "test": "../../node_modules/.bin/wireit"
6
6
  },
@@ -1,44 +0,0 @@
1
- /* @flow */
2
- import assert from "assert"
3
- import {useEffect, useState, createRef} from "react"
4
- import {CSSTransition, TransitionGroup} from "react-transition-group"
5
-
6
- import ToastContainer from "react-bootstrap/ToastContainer"
7
-
8
- import {formatDistance} from "date-fns/formatDistance"
9
-
10
- import {useQuery} from "@rpcbase/client/rts"
11
-
12
- import {useNotifications} from "../NotificationsContext"
13
- import NotificationToast from "../NotificationToast"
14
-
15
- import useLLTs from "./useLLTs"
16
-
17
- import "./notifications.scss"
18
-
19
- export const NotificationsList = () => {
20
- const {notifications, setNotifications} = useNotifications()
21
-
22
- const llts = useLLTs()
23
-
24
- const renderNotification = (notification, i) => {
25
- const key = notification.id
26
- const nodeRef = createRef()
27
-
28
- return (
29
- <CSSTransition key={notification.id} nodeRef={nodeRef} timeout={200} classNames="notifs-item">
30
- <NotificationToast key={key} nodeRef={nodeRef} notification={notification} />
31
- </CSSTransition>
32
- )
33
- }
34
-
35
- return (
36
- <ToastContainer position="bottom-end" className="pb-4 pe-3 ps-4" style={{position: "absolute", overflowY: "scroll", bottom: 0, right: 0}}>
37
- <div className="notifications-list-wrapper">
38
- <TransitionGroup className="transition-list">
39
- {notifications.map(renderNotification)}
40
- </TransitionGroup>
41
- </div>
42
- </ToastContainer>
43
- )
44
- }