Added buttons and menu items to dismiss individual notifications (#76)
* Added DELETE verb for notifications * Added notification dismiss button to status dropdown * Added reveal-on-hover notif dismiss button, added FollowNotification component
This commit is contained in:
@@ -6,6 +6,7 @@ import { makeGetNotification } from '../../../mastodon/selectors';
|
||||
|
||||
// Our imports //
|
||||
import Notification from '.';
|
||||
import { deleteNotification } from '../../../mastodon/actions/notifications';
|
||||
|
||||
const makeMapStateToProps = () => {
|
||||
const getNotification = makeGetNotification();
|
||||
@@ -18,4 +19,10 @@ const makeMapStateToProps = () => {
|
||||
return mapStateToProps;
|
||||
};
|
||||
|
||||
export default connect(makeMapStateToProps)(Notification);
|
||||
const mapDispatchToProps = (dispatch) => ({
|
||||
onDeleteNotification (id) {
|
||||
dispatch(deleteNotification(id));
|
||||
},
|
||||
});
|
||||
|
||||
export default connect(makeMapStateToProps, mapDispatchToProps)(Notification);
|
||||
|
@@ -0,0 +1,78 @@
|
||||
// Package imports //
|
||||
import React from 'react';
|
||||
import ImmutablePropTypes from 'react-immutable-proptypes';
|
||||
import PropTypes from 'prop-types';
|
||||
import { defineMessages, FormattedMessage, injectIntl } from 'react-intl';
|
||||
import escapeTextContentForBrowser from 'escape-html';
|
||||
import ImmutablePureComponent from 'react-immutable-pure-component';
|
||||
|
||||
// Mastodon imports //
|
||||
import emojify from '../../../mastodon/emoji';
|
||||
import Permalink from '../../../mastodon/components/permalink';
|
||||
import AccountContainer from '../../../mastodon/containers/account_container';
|
||||
|
||||
const messages = defineMessages({
|
||||
deleteNotification: { id: 'status.dismiss_notification', defaultMessage: 'Dismiss notification' },
|
||||
});
|
||||
|
||||
|
||||
@injectIntl
|
||||
export default class FollowNotification extends ImmutablePureComponent {
|
||||
|
||||
static contextTypes = {
|
||||
router: PropTypes.object,
|
||||
};
|
||||
|
||||
static propTypes = {
|
||||
notificationId: PropTypes.number.isRequired,
|
||||
onDeleteNotification: PropTypes.func.isRequired,
|
||||
account: ImmutablePropTypes.map.isRequired,
|
||||
intl: PropTypes.object.isRequired,
|
||||
};
|
||||
|
||||
// Avoid checking props that are functions (and whose equality will always
|
||||
// evaluate to false. See react-immutable-pure-component for usage.
|
||||
updateOnProps = [
|
||||
'account',
|
||||
]
|
||||
|
||||
handleNotificationDeleteClick = () => {
|
||||
this.props.onDeleteNotification(this.props.notificationId);
|
||||
}
|
||||
|
||||
render () {
|
||||
const { account, intl } = this.props;
|
||||
|
||||
const dismissTitle = intl.formatMessage(messages.deleteNotification);
|
||||
const dismiss = (
|
||||
<button
|
||||
aria-label={dismissTitle}
|
||||
title={dismissTitle}
|
||||
onClick={this.handleNotificationDeleteClick}
|
||||
className='status__prepend-dismiss-button'
|
||||
>
|
||||
<i className='fa fa-eraser' />
|
||||
</button>
|
||||
);
|
||||
|
||||
const displayName = account.get('display_name').length > 0 ? account.get('display_name') : account.get('username');
|
||||
const displayNameHTML = { __html: emojify(escapeTextContentForBrowser(displayName)) };
|
||||
const link = <Permalink className='notification__display-name' href={account.get('url')} title={account.get('acct')} to={`/accounts/${account.get('id')}`} dangerouslySetInnerHTML={displayNameHTML} />;
|
||||
return (
|
||||
<div className='notification notification-follow'>
|
||||
<div className='notification__message'>
|
||||
<div className='notification__favourite-icon-wrapper'>
|
||||
<i className='fa fa-fw fa-user-plus' />
|
||||
</div>
|
||||
|
||||
<FormattedMessage id='notification.follow' defaultMessage='{name} followed you' values={{ name: link }} />
|
||||
|
||||
{dismiss}
|
||||
</div>
|
||||
|
||||
<AccountContainer id={account.get('id')} withNote={false} />
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
}
|
@@ -1,42 +1,30 @@
|
||||
// Package imports //
|
||||
import React from 'react';
|
||||
import ImmutablePropTypes from 'react-immutable-proptypes';
|
||||
import { FormattedMessage } from 'react-intl';
|
||||
import escapeTextContentForBrowser from 'escape-html';
|
||||
import ImmutablePureComponent from 'react-immutable-pure-component';
|
||||
import PropTypes from 'prop-types';
|
||||
|
||||
// Mastodon imports //
|
||||
import AccountContainer from '../../../mastodon/containers/account_container';
|
||||
import Permalink from '../../../mastodon/components/permalink';
|
||||
import emojify from '../../../mastodon/emoji';
|
||||
|
||||
// Our imports //
|
||||
import StatusContainer from '../status/container';
|
||||
import FollowNotification from './follow_notification';
|
||||
|
||||
export default class Notification extends ImmutablePureComponent {
|
||||
|
||||
static propTypes = {
|
||||
notification: ImmutablePropTypes.map.isRequired,
|
||||
settings: ImmutablePropTypes.map.isRequired,
|
||||
onDeleteNotification: PropTypes.func.isRequired,
|
||||
};
|
||||
|
||||
renderFollow (notification) {
|
||||
const account = notification.get('account');
|
||||
const displayName = account.get('display_name').length > 0 ? account.get('display_name') : account.get('username');
|
||||
const displayNameHTML = { __html: emojify(escapeTextContentForBrowser(displayName)) };
|
||||
const link = <Permalink className='notification__display-name' href={account.get('url')} title={account.get('acct')} to={`/accounts/${account.get('id')}`} dangerouslySetInnerHTML={displayNameHTML} />;
|
||||
return (
|
||||
<div className='notification notification-follow'>
|
||||
<div className='notification__message'>
|
||||
<div className='notification__favourite-icon-wrapper'>
|
||||
<i className='fa fa-fw fa-user-plus' />
|
||||
</div>
|
||||
|
||||
<FormattedMessage id='notification.follow' defaultMessage='{name} followed you' values={{ name: link }} />
|
||||
</div>
|
||||
|
||||
<AccountContainer id={account.get('id')} withNote={false} />
|
||||
</div>
|
||||
<FollowNotification
|
||||
notificationId={notification.get('id')}
|
||||
account={notification.get('account')}
|
||||
onDeleteNotification={this.props.onDeleteNotification}
|
||||
/>
|
||||
);
|
||||
}
|
||||
|
||||
@@ -44,6 +32,7 @@ export default class Notification extends ImmutablePureComponent {
|
||||
return (
|
||||
<StatusContainer
|
||||
id={notification.get('status')}
|
||||
notificationId={notification.get('id')}
|
||||
withDismiss
|
||||
/>
|
||||
);
|
||||
@@ -56,6 +45,7 @@ export default class Notification extends ImmutablePureComponent {
|
||||
account={notification.get('account')}
|
||||
prepend='favourite'
|
||||
muted
|
||||
notificationId={notification.get('id')}
|
||||
withDismiss
|
||||
/>
|
||||
);
|
||||
@@ -68,6 +58,7 @@ export default class Notification extends ImmutablePureComponent {
|
||||
account={notification.get('account')}
|
||||
prepend='reblog'
|
||||
muted
|
||||
notificationId={notification.get('id')}
|
||||
withDismiss
|
||||
/>
|
||||
);
|
||||
|
Reference in New Issue
Block a user