bigbuffet-rw/app/soapbox/features/notifications/containers/notification_container.js

75 lines
2 KiB
JavaScript
Raw Normal View History

2020-03-27 13:59:38 -07:00
import { connect } from 'react-redux';
import { makeGetNotification, makeGetStatus } from '../../../selectors';
import Notification from '../components/notification';
import { openModal } from '../../../actions/modal';
import { mentionCompose } from '../../../actions/compose';
import {
reblog,
favourite,
unreblog,
unfavourite,
} from '../../../actions/interactions';
import {
hideStatus,
revealStatus,
} from '../../../actions/statuses';
2020-05-28 15:52:07 -07:00
import { getSettings } from 'soapbox/actions/settings';
2020-03-27 13:59:38 -07:00
const makeMapStateToProps = () => {
const getNotification = makeGetNotification();
const getStatus = makeGetStatus();
const mapStateToProps = (state, props) => {
const notification = getNotification(state, props.notification, props.accountId, props.targetId);
2020-03-27 13:59:38 -07:00
return {
notification: notification,
status: notification.get('status') ? getStatus(state, { id: notification.get('status') }) : null,
};
};
return mapStateToProps;
};
const mapDispatchToProps = dispatch => ({
onMention: (account, router) => {
dispatch(mentionCompose(account, router));
},
onModalReblog(status) {
2020-03-27 13:59:38 -07:00
dispatch(reblog(status));
},
onReblog(status, e) {
2020-04-21 12:41:13 -07:00
dispatch((_, getState) => {
const boostModal = getSettings(getState()).get('boostModal');
2020-04-21 12:41:13 -07:00
if (status.get('reblogged')) {
dispatch(unreblog(status));
2020-03-27 13:59:38 -07:00
} else {
2020-04-21 12:41:13 -07:00
if (e.shiftKey || !boostModal) {
this.onModalReblog(status);
} else {
dispatch(openModal('BOOST', { status, onReblog: this.onModalReblog }));
}
2020-03-27 13:59:38 -07:00
}
2020-04-21 12:41:13 -07:00
});
2020-03-27 13:59:38 -07:00
},
onFavourite(status) {
2020-03-27 13:59:38 -07:00
if (status.get('favourited')) {
dispatch(unfavourite(status));
} else {
dispatch(favourite(status));
}
},
onToggleHidden(status) {
2020-03-27 13:59:38 -07:00
if (status.get('hidden')) {
dispatch(revealStatus(status.get('id')));
} else {
dispatch(hideStatus(status.get('id')));
}
},
});
export default connect(makeMapStateToProps, mapDispatchToProps)(Notification);