From a55a34d48f49aaabde655edc5a2907aeb6593b38 Mon Sep 17 00:00:00 2001 From: Andrew Prifer <2991360+AndrewPrifer@users.noreply.github.com> Date: Sun, 13 Nov 2022 14:37:24 +0100 Subject: [PATCH] Improve notifications UX (#337) Improve notification UX --- theatre/studio/src/notify.tsx | 70 ++++++++++--------- theatre/studio/src/toolbars/GlobalToolbar.tsx | 19 +++-- theatre/studio/src/toolbars/PinButton.tsx | 6 +- .../studio/src/uiComponents/icons/Bell.tsx | 3 +- 4 files changed, 59 insertions(+), 39 deletions(-) diff --git a/theatre/studio/src/notify.tsx b/theatre/studio/src/notify.tsx index 3f04436..b94971f 100644 --- a/theatre/studio/src/notify.tsx +++ b/theatre/studio/src/notify.tsx @@ -11,6 +11,8 @@ import type { import {useVal} from '@theatre/react' import getStudio from './getStudio' import {marked} from 'marked' +import useTooltip from './uiComponents/Popover/useTooltip' +import MinimalTooltip from './uiComponents/Popover/MinimalTooltip' /** * Creates a string key unique to a notification with a certain title and message. @@ -181,9 +183,9 @@ const COLORS = { const IndicatorDot = styled.div<{type: NotificationType}>` display: flex; - align-items: center; justify-content: center; margin-left: 12px; + padding-top: 21px; ::before { content: ''; @@ -308,7 +310,7 @@ const NotifierContainer = styled.div` flex-direction: column; gap: 8px; position: fixed; - right: 8px; + right: 92px; top: 50px; width: 500px; height: 85vh; @@ -330,27 +332,31 @@ const NotificationScroller = styled.div` ` const EmptyState = styled.div` - align-self: flex-end; width: fit-content; - padding: 12px; + padding: 8px; border-radius: 4px; display: flex; flex-direction: column; gap: 12px; - ${pointerEventsAutoInNormalMode}; - background-color: rgba(40, 43, 47, 0.8); - box-shadow: 0 1px 1px rgba(0, 0, 0, 0.25), 0 2px 6px rgba(0, 0, 0, 0.15); - backdrop-filter: blur(14px); color: #b4b4b4; font-size: 12px; line-height: 1.4; - - @supports not (backdrop-filter: blur()) { - background: rgba(40, 43, 47, 0.95); - } ` //endregion +export const useEmptyNotificationsTooltip = () => { + const {hasNotifications} = useNotifications() + + return useTooltip({enabled: !hasNotifications}, () => ( + + + No notifications + Notifications will appear here when you get them. + + + )) +} + /** * The component responsible for rendering the notifications. */ @@ -363,26 +369,26 @@ export const Notifier = () => { return ( - {!pinNotifications ? null : toasts.length > 0 ? ( - - - {toasts.map((toast) => { - return ( - - {/* message is always a function in our case */} - {/* @ts-ignore */} - {toast.message(toast)} - - ) - })} - - - ) : ( - - No notifications - Notifications will appear here when you get them. - - )} + {!pinNotifications + ? null + : toasts.length > 0 && ( + + + {toasts.map((toast) => { + return ( + + {/* message is always a function in our case */} + {/* @ts-ignore */} + {toast.message(toast)} + + ) + })} + + + )} {pinNotifications && toasts.length > 0 && ( { const {hasNotifications} = useNotifications() + const [notificationsTooltip, notificationsTriggerRef] = + useEmptyNotificationsTooltip() + return ( @@ -174,7 +180,9 @@ const GlobalToolbar: React.FC = () => { - { getStudio().transaction(({stateEditors, drafts}) => { stateEditors.studio.ahistoric.setPinNotifications( @@ -182,10 +190,13 @@ const GlobalToolbar: React.FC = () => { ) }) }} + icon={} + pinHintIcon={} + unpinHintIcon={} + pinned={useVal(getStudio().atomP.ahistoric.pinNotifications) ?? false} > - {hasNotifications && } - + {moreMenu.node} { } const PinButton = forwardRef( - ({hint, pinned, icon, pinHintIcon, unpinHintIcon, ...props}, ref) => { + ( + {children, hint, pinned, icon, pinHintIcon, unpinHintIcon, ...props}, + ref, + ) => { const [hovered, setHovered] = useState(false) const showHint = hovered || hint @@ -48,6 +51,7 @@ const PinButton = forwardRef( ? unpinHintIcon : icon} + {children} ) }, diff --git a/theatre/studio/src/uiComponents/icons/Bell.tsx b/theatre/studio/src/uiComponents/icons/Bell.tsx index 2e5a1e9..e5d93c8 100644 --- a/theatre/studio/src/uiComponents/icons/Bell.tsx +++ b/theatre/studio/src/uiComponents/icons/Bell.tsx @@ -12,8 +12,7 @@ function Bell(props: React.SVGProps) { > )