Skip to content

Commit aeae32f

Browse files
committed
fixup! feat: implement notification list component
1 parent 3a954b6 commit aeae32f

File tree

9 files changed

+24
-60
lines changed

9 files changed

+24
-60
lines changed

apps/browser-extension-wallet/src/components/NotificationsCenter/Notifications.tsx

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ import { SectionTitle } from '@components/Layout/SectionTitle';
1515
export const NotificationsCenter = (): React.ReactElement => {
1616
const { t } = useTranslation();
1717
const [isRemoveNotificationModalVisible, setIsRemoveNotificationModalVisible] = useState(false);
18-
const { notifications, loadMore, remove, unreadNotifications, isLoading } = useNotificationsCenter();
18+
const { notifications, remove, unreadNotifications } = useNotificationsCenter();
1919
const [notificationIdToRemove, setNotificationIdToRemove] = useState<string | undefined>();
2020
const history = useHistory();
2121

@@ -51,9 +51,7 @@ export const NotificationsCenter = (): React.ReactElement => {
5151
<div>
5252
{notifications?.length > 0 ? (
5353
<NotificationsList
54-
isLoading={isLoading}
5554
hasMore
56-
loadMore={loadMore}
5755
notifications={notifications}
5856
scrollableTarget="contentLayout"
5957
dataLength={notifications.length}

apps/browser-extension-wallet/src/components/NotificationsCenter/NotificationsBell.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import NotificationBellIcon from '../../assets/icons/notifications-bell.componen
88

99
const MAX_NOTIFICATION_COUNT = 9;
1010
const formatNotificationCount = (count: number) =>
11-
count < MAX_NOTIFICATION_COUNT ? count.toString() : `${MAX_NOTIFICATION_COUNT}+`;
11+
count <= MAX_NOTIFICATION_COUNT ? count.toString() : `${MAX_NOTIFICATION_COUNT}+`;
1212

1313
export interface NotificationsBellProps {
1414
onClick: () => void;

apps/browser-extension-wallet/src/components/NotificationsCenter/NotificationsCenter.tsx

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ export const NotificationsCenter = (): React.ReactElement => {
1818
const { t } = useTranslation();
1919
const history = useHistory();
2020
const [isRemoveNotificationModalVisible, setIsRemoveNotificationModalVisible] = useState(false);
21-
const { notifications, loadMore, markAsRead, remove, unreadNotifications, isLoading } = useNotificationsCenter();
21+
const { notifications, markAsRead, remove, unreadNotifications } = useNotificationsCenter();
2222
const [notificationIdToRemove, setNotificationIdToRemove] = useState<string | undefined>();
2323

2424
const onBack = () => {
@@ -82,9 +82,7 @@ export const NotificationsCenter = (): React.ReactElement => {
8282
notifications={notifications}
8383
scrollableTarget={LACE_APP_ID}
8484
dataLength={notifications.length}
85-
loadMore={loadMore}
8685
onRemove={onShowRemoveNotificationModal}
87-
isLoading={isLoading}
8886
/>
8987
) : (
9088
<Box mt="$120">

apps/browser-extension-wallet/src/components/NotificationsCenter/NotificationsDropDown.tsx

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ export interface NotificationsDropDownProps {
1818

1919
export const NotificationsDropDown = ({ onViewAll, popupView }: NotificationsDropDownProps): React.ReactElement => {
2020
const { t } = useTranslation();
21-
const { notifications, loadMore, isLoading, markAsRead, unreadNotifications } = useNotificationsCenter();
21+
const { notifications, markAsRead, unreadNotifications } = useNotificationsCenter();
2222

2323
return (
2424
<Menu className={classnames(styles.container, { [styles.popupView]: popupView })}>
@@ -32,8 +32,6 @@ export const NotificationsDropDown = ({ onViewAll, popupView }: NotificationsDro
3232
notifications={notifications}
3333
scrollableTarget="notifications-dropdown-content"
3434
dataLength={notifications.length}
35-
loadMore={loadMore}
36-
isLoading={isLoading}
3735
withBorder={false}
3836
withDivider
3937
popupView

apps/browser-extension-wallet/src/components/NotificationsCenter/NotificationsList.tsx

Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,12 @@ import { List, Skeleton } from 'antd';
33
import cn from 'classnames';
44
import React, { useState, useCallback, useMemo } from 'react';
55
import InfiniteScroll from 'react-infinite-scroll-component';
6-
import { NotificationListItem, NotificationListItemProps } from './NotificationListItem';
6+
import { NotificationListItem } from './NotificationListItem';
77
import styles from './NotificationsList.module.scss';
88
import isNumber from 'lodash/isNumber';
99
import Loader from '../../assets/icons/loader.component.svg';
1010
import { Flex } from '@input-output-hk/lace-ui-toolkit';
11+
import { LaceNotification } from '@src/types/notifications-center';
1112

1213
const ESTIMATED_MIN_ITEM_HEIGHT = 96;
1314

@@ -24,13 +25,14 @@ export const useItemsPageSize = (estimatedItemHeight = ESTIMATED_MIN_ITEM_HEIGHT
2425

2526
export interface NotificationsListProps {
2627
className?: string;
27-
notifications: NotificationListItemProps[];
28+
notifications: LaceNotification[];
2829
scrollableTarget: string;
2930
endMessage?: React.ReactNode;
3031
dataLength: number;
3132
popupView?: boolean;
32-
loadMore: () => void;
33+
loadMore?: () => void;
3334
hasMore?: boolean;
35+
onClick?: (id: string) => void;
3436
onRemove?: (id: string) => void;
3537
isLoading?: boolean;
3638
withBorder?: boolean;
@@ -45,14 +47,15 @@ export const NotificationsList = ({
4547
dataLength,
4648
popupView,
4749
loadMore,
48-
hasMore = true,
50+
onClick,
51+
hasMore = false,
4952
onRemove,
5053
isLoading = false,
5154
withBorder = true,
5255
withDivider
5356
}: NotificationsListProps): React.ReactElement => {
5457
const next = useCallback(() => {
55-
loadMore();
58+
loadMore?.();
5659
}, [loadMore]);
5760

5861
const loader = useMemo(
@@ -83,12 +86,20 @@ export const NotificationsList = ({
8386
data-testid="notifications-list"
8487
itemLayout="horizontal"
8588
dataSource={notifications}
86-
renderItem={(props: NotificationListItemProps) => (
89+
renderItem={(props: LaceNotification) => (
8790
<List.Item
8891
data-testid="notification-list-item"
8992
className={cn(styles.listItem, className, { [styles.withBorder]: withDivider })}
9093
>
91-
<NotificationListItem onRemove={onRemove} {...props} popupView={popupView} withBorder={withBorder} />
94+
<NotificationListItem
95+
onRemove={onRemove}
96+
popupView={popupView}
97+
withBorder={withBorder}
98+
id={props.message.id}
99+
title={props.message.title}
100+
publisher={props.message.topic}
101+
onClick={() => onClick?.(props.message.id)}
102+
/>
92103
</List.Item>
93104
)}
94105
/>

apps/browser-extension-wallet/src/hooks/useNotificationsCenter.ts

Lines changed: 2 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -31,34 +31,13 @@ export const useNotificationsCenter = () => {
3131
[notifications]
3232
);
3333

34-
const mappedNotifications = useMemo(
35-
() =>
36-
notifications?.map((template) => ({
37-
id: template.message.id,
38-
title: template.message.title,
39-
publisher: template.message.topic,
40-
isRead: template.read,
41-
onClick: () => {
42-
// eslint-disable-next-line no-console
43-
console.log(`Clicked notification ${template.message.id}`);
44-
}
45-
})),
46-
[notifications]
47-
);
48-
4934
return {
50-
notifications: mappedNotifications,
35+
notifications,
5136
unreadNotifications,
5237
topics,
5338
subscribe,
5439
unsubscribe,
5540
markAsRead,
56-
remove,
57-
// TODO: Implement loadMore and isLoading
58-
loadMore: () => {
59-
// eslint-disable-next-line no-console
60-
console.log('loadMore');
61-
},
62-
isLoading: false
41+
remove
6342
};
6443
};

packages/core/src/ui/assets/icons/happy-face.component.svg

Lines changed: 0 additions & 9 deletions
This file was deleted.

packages/core/src/ui/assets/icons/notifications-bell.component.svg

Lines changed: 0 additions & 9 deletions
This file was deleted.

packages/translation/src/lib/translations/browser-extension-wallet/en.json

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -783,8 +783,6 @@
783783
"multiWallet.errorDialog.notDetectedError.trezorDescription": "Please make sure your device is unlocked.",
784784
"multiWallet.popupHwAccountEnable": "Hardware wallets require the <0>expanded view</0> to enable accounts",
785785
"multiWallet.walletAlreadyExists": "Wallet already exists",
786-
"notificationsCenter.allClear.title": "All clear",
787-
"notificationsCenter.allClear.description": "You don't have any notifications currently",
788786
"notificationsCenter.manageSubscriptions": "Manage subscriptions",
789787
"notificationsCenter.markAllAsRead": "Mark all as read",
790788
"notificationsCenter.title": "Notifications",

0 commit comments

Comments
 (0)