chinwagsocial/app/javascript/mastodon/features/notifications/containers/notification_container.js

55 lines
1.6 KiB
JavaScript
Raw Normal View History

2016-11-21 05:39:18 +11:00
import { connect } from 'react-redux';
import { mentionCompose } from '../../../actions/compose';
import {
toggleFavourite,
toggleReblog,
} from '../../../actions/interactions';
import {
hideStatus,
revealStatus,
} from '../../../actions/statuses';
import { makeGetNotification, makeGetStatus, makeGetReport } from '../../../selectors';
import Notification from '../components/notification';
2016-11-21 05:39:18 +11:00
const makeMapStateToProps = () => {
const getNotification = makeGetNotification();
const getStatus = makeGetStatus();
const getReport = makeGetReport();
2016-11-21 05:39:18 +11:00
const mapStateToProps = (state, props) => {
const notification = getNotification(state, props.notification, props.accountId);
return {
notification: notification,
status: notification.get('status') ? getStatus(state, { id: notification.get('status'), contextType: 'notifications' }) : null,
report: notification.get('report') ? getReport(state, notification.get('report'), notification.getIn(['report', 'target_account', 'id'])) : null,
};
};
2016-11-21 05:39:18 +11:00
return mapStateToProps;
};
const mapDispatchToProps = dispatch => ({
onMention: (account) => {
dispatch(mentionCompose(account));
},
onReblog (status, e) {
dispatch(toggleReblog(status.get('id'), e.shiftKey));
},
onFavourite (status) {
dispatch(toggleFavourite(status.get('id')));
},
onToggleHidden (status) {
if (status.get('hidden')) {
dispatch(revealStatus(status.get('id')));
} else {
dispatch(hideStatus(status.get('id')));
}
},
});
export default connect(makeMapStateToProps, mapDispatchToProps)(Notification);