Skip to content
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

Hamza/85369/clear button for notifications #7348

Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -92,9 +92,34 @@ const NotificationsList = ({ notifications, toggleDialog }) => {
</React.Fragment>
);
};
const NotificationListWrapper = React.forwardRef(({ notifications, toggleDialog }, ref) => {

const ClearAllFooter = ({ is_empty, clearNotifications }) => {
return (
<React.Fragment>
<div className='notifications-dialog__separator' />
<div
className={classNames('notifications-dialog__footer', {
'notifications-dialog__content--empty': is_empty,
'notifications-dialog__content--sticky': isMobile(),
})}
>
<Button
className={classNames('dc-btn--secondary', 'notifications-dialog__clear')}
onClick={clearNotifications}
>
<Text size='xxs' color='prominent' weight='bold'>
{localize('Clear All')}
</Text>
</Button>
</div>
</React.Fragment>
);
};

const NotificationListWrapper = React.forwardRef(({ notifications, toggleDialog, clearNotifications }, ref) => {
const is_empty = !notifications.length;
const { is_pre_appstore } = React.useContext(PlatformContext);

return (
<div
className={classNames('notifications-dialog', {
Expand Down Expand Up @@ -129,12 +154,20 @@ const NotificationListWrapper = React.forwardRef(({ notifications, toggleDialog
)}
</ThemedScrollbars>
</div>
<ClearAllFooter clearNotifications={clearNotifications} is_empty={is_empty} />
</div>
);
});
NotificationListWrapper.displayName = 'NotificationListWrapper';

const NotificationsDialog = ({ is_visible, notifications, toggleDialog }) => {
const NotificationsDialog = ({
is_visible,
notifications,
toggleDialog,
removeNotificationMessage,
removeNotificationMessageByKey,
removeNotifications,
}) => {
const wrapper_ref = React.useRef();

const handleClickOutside = event => {
Expand All @@ -144,6 +177,17 @@ const NotificationsDialog = ({ is_visible, notifications, toggleDialog }) => {
}
};

const clearNotifications = () => {
return notifications.map(item => {
removeNotificationMessageByKey(item.key);
removeNotificationMessage({
key: item.key,
should_show_again: false,
});
removeNotifications(true);
});
};

useOnClickOutside(wrapper_ref, handleClickOutside);

return (
Expand All @@ -160,6 +204,7 @@ const NotificationsDialog = ({ is_visible, notifications, toggleDialog }) => {
notifications={notifications}
ref={wrapper_ref}
toggleDialog={toggleDialog}
clearNotifications={clearNotifications}
/>
</MobileDialog>
</MobileWrapper>
Expand All @@ -178,6 +223,10 @@ const NotificationsDialog = ({ is_visible, notifications, toggleDialog }) => {
notifications={notifications}
ref={wrapper_ref}
toggleDialog={toggleDialog}
removeNotificationMessage={removeNotificationMessage}
removeNotifications={removeNotifications}
removeNotificationMessageByKey={removeNotificationMessageByKey}
clearNotifications={clearNotifications}
/>
</CSSTransition>
</DesktopWrapper>
Expand All @@ -189,11 +238,17 @@ NotificationsDialog.propTypes = {
is_visible: PropTypes.bool,
notifications: PropTypes.array,
toggleDialog: PropTypes.func,
removeNotificationMessage: PropTypes.func,
removeNotificationByKey: PropTypes.func,
removeNotificationMessageByKey: PropTypes.func,
removeNotifications: PropTypes.func,
};

export default connect(({ common, notifications }) => ({
notifications: notifications.notifications,
app_routing_history: common.app_routing_history,
removeNotificationByKey: notifications.removeNotificationByKey,
removeNotificationMessage: notifications.removeNotificationMessage,
removeNotifications: notifications.removeNotifications,
removeNotificationMessageByKey: notifications.removeNotificationMessageByKey,
}))(NotificationsDialog);
12 changes: 12 additions & 0 deletions packages/core/src/Stores/notification-store.js
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,7 @@ export default class NotificationStore extends BaseStore {
this.setClientNotifications();
this.handleClientNotifications();
this.filterNotificationMessages();
this.checkNotificationMessages();
}
}
);
Expand Down Expand Up @@ -226,6 +227,17 @@ export default class NotificationStore extends BaseStore {
}
}

// check for the already added keys in the notification_messages and don't display those notifications
checkNotificationMessages() {
const notifications_list = LocalStore.getObject('notification_messages');
const refined_list = notifications_list ? Object.values(notifications_list)[0] : [];
if (refined_list.length) {
refined_list.map(refined => {
this.removeNotificationByKey({ key: refined });
});
}
}

async handleClientNotifications() {
const {
account_settings,
Expand Down
35 changes: 33 additions & 2 deletions packages/core/src/sass/app/modules/notifications-dialog.scss
Original file line number Diff line number Diff line change
Expand Up @@ -70,15 +70,46 @@
display: none;
}
}
&__footer {
height: 37px;
hamza-deriv marked this conversation as resolved.
Show resolved Hide resolved
align-items: end;
display: flex;
justify-content: end;
padding-left: 1.3rem;
background: var(--general-main-2);
box-shadow: 0 4px 8px 2px var(--shadow-menu);
transition: transform 0.3s cubic-bezier(0.25, 0.1, 0.25, 1), opacity 0.25s linear;
border-bottom-right-radius: 0.5rem;
border-bottom-left-radius: 0.5rem;
}
&__separator {
border-bottom: 1px solid #f2f3f4;
hamza-deriv marked this conversation as resolved.
Show resolved Hide resolved
}
&__clear {
border: 1px solid #999999;
hamza-deriv marked this conversation as resolved.
Show resolved Hide resolved
height: 2.4rem;
width: auto;
bottom: 0.6rem;
right: 1.7rem;
padding: 7px;
hamza-deriv marked this conversation as resolved.
Show resolved Hide resolved

&:hover {
background: var(--button-secondary-hover);
}
}
&__content {
padding: 8px 0;
hamza-deriv marked this conversation as resolved.
Show resolved Hide resolved
height: calc(100% - 37px);
border-radius: $BORDER_RADIUS;

&--empty {
display: flex;
height: 100%;
max-height: 400px;
}

&--sticky {
display: flex;
position: sticky;
bottom: 0;
}
@include mobile {
height: calc(100vh - 40px);
Expand Down