From 038720cc53499da7c15e2acec7e9f4bb06de9f92 Mon Sep 17 00:00:00 2001 From: Carson Full Date: Mon, 21 Oct 2024 11:49:13 -0500 Subject: [PATCH] Add loading state --- .../Root/Notifications/Notifications.tsx | 6 +++ .../Root/Notifications/ReadIndicator.tsx | 3 +- src/scenes/Root/Notifications/Views/Base.tsx | 39 ++++++++++++++----- 3 files changed, 38 insertions(+), 10 deletions(-) diff --git a/src/scenes/Root/Notifications/Notifications.tsx b/src/scenes/Root/Notifications/Notifications.tsx index fe99558ca..389045983 100644 --- a/src/scenes/Root/Notifications/Notifications.tsx +++ b/src/scenes/Root/Notifications/Notifications.tsx @@ -21,6 +21,7 @@ import { Notification } from './Notification'; import { NotificationListDocument } from './NotificationList.graphql'; import { ReadNotificationDocument } from './ReadNotification.graphql'; import { NotificationFragment } from './Views'; +import { BaseView } from './Views/Base'; export const Notifications = () => { const enabled = useFeatureEnabled('notifications'); @@ -113,6 +114,11 @@ export const Notifications = () => { } sx={{ p: 1, pt: 0.5, gap: 0.5 }}> + {loading && !data + ? Array.from({ length: 5 }).map((_, i) => ( + + )) + : null} {data?.items.map((notification) => ( { - props: NotificationProp & ChildrenProp & StyleProps & AdditionalProps; + props: (NotificationProp | { notification: 'loading' }) & + ChildrenProp & + StyleProps & + AdditionalProps; defaultComponent: RootComponent; } export const BaseView: OverridableComponent = ( props: NotificationTypeMap['props'] & { component?: ElementType } ) => { - const { component: Root = Box, notification, children, ...rest } = props; - const { unread, createdAt } = notification; + const { + component: Root = Box, + notification: notificationIn, + children, + ...rest + } = props; + const notification = + notificationIn !== 'loading' ? notificationIn : undefined; return ( = ( sx={[ (theme: Theme) => ({ width: 1, - backgroundColor: unread + backgroundColor: notification?.unread ? alpha(theme.palette.primary.light, 0.1) : undefined, borderRadius: 1, @@ -48,13 +57,25 @@ export const BaseView: OverridableComponent = ( ]} > - {children} + {notification ? ( + children + ) : ( + + )} - + {notification ? ( + + ) : ( + + )} - {/* Just to reserve layout */} - + {notification ? ( + // Just to reserve layout + + ) : ( + + )} ); };