-
Notifications
You must be signed in to change notification settings - Fork 13
feat: implement notification list component #2009
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
@import '../../../../../packages/core/src/ui/styles/theme.scss'; | ||
@import '../../../../../packages/common/src/ui/styles/theme.scss'; | ||
|
||
.icon { | ||
width: size_unit(10.5); | ||
height: size_unit(10.5); | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
import React from 'react'; | ||
import { Flex, Text } from '@input-output-hk/lace-ui-toolkit'; | ||
import { useTranslation } from 'react-i18next'; | ||
import styles from './EmptyState.module.scss'; | ||
import SmileyFaceIcon from '../../assets/icons/smiley-face.component.svg'; | ||
|
||
export const EmptyState = (): React.ReactElement => { | ||
const { t } = useTranslation(); | ||
|
||
return ( | ||
<Flex flexDirection="column" gap="$20" alignItems="center" justifyContent="center" data-testid="empty-state"> | ||
<SmileyFaceIcon className={styles.icon} /> | ||
<Flex alignItems="center" flexDirection="column" gap="$0"> | ||
<Text.Body.Large>{t('notificationsCenter.emptyState.title')}</Text.Body.Large> | ||
<Text.Body.Small color="secondary">{t('notificationsCenter.emptyState.description')}</Text.Body.Small> | ||
</Flex> | ||
</Flex> | ||
); | ||
}; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
/* eslint-disable unicorn/no-useless-undefined */ | ||
/* eslint-disable @typescript-eslint/explicit-module-boundary-types, promise/catch-or-return, sonarjs/cognitive-complexity, no-magic-numbers, unicorn/no-null */ | ||
import React, { useState } from 'react'; | ||
import { ContentLayout } from '@src/components/Layout'; | ||
import { useTranslation } from 'react-i18next'; | ||
import { WarningModal } from '@src/views/browser-view/components'; | ||
import { useNotificationsCenter } from '@hooks/useNotificationsCenter'; | ||
import { NotificationsList } from './NotificationsList'; | ||
import { EmptyState } from './EmptyState'; | ||
import { Box, Flex } from '@input-output-hk/lace-ui-toolkit'; | ||
import { NavigationButton } from '@lace/common'; | ||
import { useHistory } from 'react-router'; | ||
import { SectionTitle } from '@components/Layout/SectionTitle'; | ||
|
||
export const NotificationsCenter = (): React.ReactElement => { | ||
const { t } = useTranslation(); | ||
const [isRemoveNotificationModalVisible, setIsRemoveNotificationModalVisible] = useState(false); | ||
const { notifications, loadMore, remove, unreadNotifications, isLoading } = useNotificationsCenter(); | ||
const [notificationIdToRemove, setNotificationIdToRemove] = useState<string | undefined>(); | ||
const history = useHistory(); | ||
|
||
const onShowRemoveNotificationModal = (id: string) => { | ||
setNotificationIdToRemove(id); | ||
setIsRemoveNotificationModalVisible(true); | ||
}; | ||
|
||
const onHideRemoveNotificationModal = () => { | ||
setNotificationIdToRemove(undefined); | ||
setIsRemoveNotificationModalVisible(false); | ||
}; | ||
|
||
const isInitialLoad = typeof notifications === 'undefined'; | ||
|
||
return ( | ||
<ContentLayout | ||
title={ | ||
<SectionTitle | ||
isPopup | ||
title={ | ||
<Flex alignItems="center" gap="$8"> | ||
<NavigationButton icon="arrow" onClick={() => history.goBack()} /> | ||
{t('notificationsCenter.title')} | ||
</Flex> | ||
} | ||
sideText={`(${unreadNotifications})`} | ||
data-testid="notifications-center-title" | ||
/> | ||
} | ||
isLoading={isInitialLoad} | ||
> | ||
<div> | ||
{notifications?.length > 0 ? ( | ||
<NotificationsList | ||
isLoading={isLoading} | ||
hasMore | ||
loadMore={loadMore} | ||
notifications={notifications} | ||
scrollableTarget="contentLayout" | ||
dataLength={notifications.length} | ||
onRemove={onShowRemoveNotificationModal} | ||
popupView | ||
/> | ||
) : ( | ||
<Box mt="$96"> | ||
<EmptyState /> | ||
</Box> | ||
)} | ||
</div> | ||
<WarningModal | ||
visible={isRemoveNotificationModalVisible} | ||
header={t('notificationsCenter.removeNotification')} | ||
content={t('notificationsCenter.removeNotification.description')} | ||
onCancel={onHideRemoveNotificationModal} | ||
cancelLabel={t('notificationsCenter.removeNotification.cancel')} | ||
confirmLabel={t('notificationsCenter.removeNotification.confirm')} | ||
onConfirm={() => { | ||
remove(notificationIdToRemove); | ||
onHideRemoveNotificationModal(); | ||
}} | ||
isPopupView | ||
/> | ||
</ContentLayout> | ||
); | ||
}; |
This file was deleted.
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -4,10 +4,11 @@ import { Button } from '@lace/common'; | |||||
|
||||||
import styles from './NotificationsBell.module.scss'; | ||||||
|
||||||
import NotificationBellIcon from '@lace/core/src/ui/assets/icons/notifications-bell.component.svg'; | ||||||
import NotificationBellIcon from '../../assets/icons/notifications-bell.component.svg'; | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @mirceahasegan asked me to put icons in the core package. Anyway if there are good reasons to keep them in this package, please remove the other ones (also the happy face). |
||||||
|
||||||
// eslint-disable-next-line no-magic-numbers | ||||||
const formatNotificationCount = (count: number) => (count < 10 ? count.toString() : '9+'); | ||||||
const MAX_NOTIFICATION_COUNT = 9; | ||||||
const formatNotificationCount = (count: number) => | ||||||
count < MAX_NOTIFICATION_COUNT ? count.toString() : `${MAX_NOTIFICATION_COUNT}+`; | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
|
||||||
export interface NotificationsBellProps { | ||||||
onClick: () => void; | ||||||
|
@@ -16,7 +17,7 @@ export interface NotificationsBellProps { | |||||
|
||||||
export const NotificationsBell = ({ onClick, unreadNotifications }: NotificationsBellProps): React.ReactElement => ( | ||||||
<Button className={styles.btn} block color="gradient" data-testid="notifications-bell" onClick={onClick}> | ||||||
<NotificationBellIcon /> | ||||||
<NotificationBellIcon className={styles.icon} /> | ||||||
{unreadNotifications > 0 && <span className={styles.badge}>{formatNotificationCount(unreadNotifications)}</span>} | ||||||
</Button> | ||||||
); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Two component with the same name and purpose?
I'd suggest a refactor to have only one component with that purpose.