Skip to content

Commit

Permalink
fix(js): show loading when changing filters (#6277)
Browse files Browse the repository at this point in the history
  • Loading branch information
BiswaViraj authored Aug 7, 2024
1 parent 9c1e03c commit 0e177fb
Showing 1 changed file with 24 additions and 30 deletions.
54 changes: 24 additions & 30 deletions packages/js/src/ui/components/Notification/NotificationList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,10 @@ type NotificationListProps = {
filter?: NotificationFilter;
};

const NotificationListWrapper = (props: NotificationListProps) => {
/* This is also going to be exported as a separate component. Keep it pure. */
export const NotificationList = (props: NotificationListProps) => {
const options = createMemo(() => ({ ...props.filter, limit: props.limit }));
const { data, setEl, end, refetch } = useNotificationsInfiniteScroll({ options });
const { data, setEl, end, refetch, initialLoading } = useNotificationsInfiniteScroll({ options });
const { count, reset: resetNewMessagesCount } = useNewMessagesCount({ filter: { tags: props.filter?.tags ?? [] } });

const handleOnNewMessagesClick: JSX.EventHandlerUnion<HTMLButtonElement, MouseEvent> = async (e) => {
Expand All @@ -61,35 +62,28 @@ const NotificationListWrapper = (props: NotificationListProps) => {
return (
<>
<NewMessagesCta count={count()} onClick={handleOnNewMessagesClick} />
<Show when={data().length > 0} fallback={<EmptyNotificationList />}>
<NotificationListContainer>
<For each={data()}>
{(notification) => (
<Notification
notification={notification}
mountNotification={props.mountNotification}
onNotificationClick={props.onNotificationClick}
onPrimaryActionClick={props.onPrimaryActionClick}
onSecondaryActionClick={props.onSecondaryActionClick}
/>
)}
</For>
<Show when={!end()}>
<div ref={setEl}>
<For each={Array.from({ length: 3 })}>{() => <NotificationSkeleton />}</For>
</div>
</Show>
</NotificationListContainer>
<Show when={!initialLoading()} fallback={<NotificationListSkeleton count={8} />}>
<Show when={data().length > 0} fallback={<EmptyNotificationList />}>
<NotificationListContainer>
<For each={data()}>
{(notification) => (
<Notification
notification={notification}
mountNotification={props.mountNotification}
onNotificationClick={props.onNotificationClick}
onPrimaryActionClick={props.onPrimaryActionClick}
onSecondaryActionClick={props.onSecondaryActionClick}
/>
)}
</For>
<Show when={!end()}>
<div ref={setEl}>
<For each={Array.from({ length: 3 })}>{() => <NotificationSkeleton />}</For>
</div>
</Show>
</NotificationListContainer>
</Show>
</Show>
</>
);
};

/* This is also going to be exported as a separate component. Keep it pure. */
export const NotificationList = (props: NotificationListProps) => {
return (
<Suspense fallback={<NotificationListSkeleton count={8} />}>
<NotificationListWrapper {...props} />
</Suspense>
);
};

0 comments on commit 0e177fb

Please sign in to comment.