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

74 lines
1.7 KiB
JavaScript
Raw Normal View History

2020-03-27 13:59:38 -07:00
import { connect } from 'react-redux';
2022-01-10 14:01:24 -08:00
import { getSettings } from 'soapbox/actions/settings';
2020-03-27 13:59:38 -07:00
import { mentionCompose } from '../../../actions/compose';
import {
reblog,
favourite,
unreblog,
unfavourite,
} from '../../../actions/interactions';
import { openModal } from '../../../actions/modal';
2020-03-27 13:59:38 -07:00
import {
hideStatus,
revealStatus,
} from '../../../actions/statuses';
import { makeGetNotification } from '../../../selectors';
import Notification from '../components/notification';
2020-03-27 13:59:38 -07:00
const makeMapStateToProps = () => {
const getNotification = makeGetNotification();
const mapStateToProps = (state, props) => {
return {
notification: getNotification(state, props.notification),
2020-03-27 13:59:38 -07:00
};
};
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);