gab-social/app/javascript/gabsocial/features/notifications/containers/notification_container.js

75 lines
1.9 KiB
JavaScript
Raw Normal View History

2020-03-04 03:45:16 +00:00
import { openModal } from '../../../actions/modal'
import { mentionCompose } from '../../../actions/compose'
2019-07-02 08:10:25 +01:00
import {
reblog,
2020-03-04 22:26:01 +00:00
favorite,
2019-07-02 08:10:25 +01:00
unreblog,
2020-03-04 22:26:01 +00:00
unfavorite,
2020-03-04 03:45:16 +00:00
} from '../../../actions/interactions'
2019-07-02 08:10:25 +01:00
import {
hideStatus,
revealStatus,
2020-03-04 03:45:16 +00:00
} from '../../../actions/statuses'
import { boostModal, me } from '../../../initial_state'
import { makeGetNotification, makeGetStatus } from '../../../selectors'
import Notification from '../components/notification/notification-alt'
2019-07-02 08:10:25 +01:00
const makeMapStateToProps = () => {
2020-03-04 03:45:16 +00:00
const getNotification = makeGetNotification()
const getStatus = makeGetStatus()
2019-07-02 08:10:25 +01:00
const mapStateToProps = (state, props) => {
2020-03-04 03:45:16 +00:00
const notification = getNotification(state, props.notification, props.accountId)
const account = state.getIn(['accounts', me])
2019-07-02 08:10:25 +01:00
return {
2020-03-04 03:45:16 +00:00
accounts: [account, account, account],
2019-07-02 08:10:25 +01:00
notification: notification,
status: notification.get('status') ? getStatus(state, { id: notification.get('status') }) : null,
2020-03-04 03:45:16 +00:00
}
}
2019-07-02 08:10:25 +01:00
2020-03-04 03:45:16 +00:00
return mapStateToProps
}
2019-07-02 08:10:25 +01:00
const mapDispatchToProps = dispatch => ({
onMention: (account, router) => {
2020-03-04 03:45:16 +00:00
dispatch(mentionCompose(account, router))
2019-07-02 08:10:25 +01:00
},
2020-03-04 22:26:01 +00:00
onModalRepost (status) {
dispatch(repost(status))
2019-07-02 08:10:25 +01:00
},
2020-03-04 22:26:01 +00:00
onRepost (status, e) {
2019-07-02 08:10:25 +01:00
if (status.get('reblogged')) {
2020-03-04 22:26:01 +00:00
dispatch(unrepost(status))
2019-07-02 08:10:25 +01:00
} else {
if (e.shiftKey || !boostModal) {
2020-03-04 22:26:01 +00:00
this.onModalRepost(status)
2019-07-02 08:10:25 +01:00
} else {
2020-03-04 22:26:01 +00:00
dispatch(openModal('BOOST', { status, onRepost: this.onModalRepost }))
2019-07-02 08:10:25 +01:00
}
}
},
2020-03-04 22:26:01 +00:00
onFavorite (status) {
if (status.get('favorited')) {
dispatch(unfavorite(status))
2019-07-02 08:10:25 +01:00
} else {
2020-03-04 22:26:01 +00:00
dispatch(favorite(status))
2019-07-02 08:10:25 +01:00
}
},
onToggleHidden (status) {
if (status.get('hidden')) {
2020-03-04 03:45:16 +00:00
dispatch(revealStatus(status.get('id')))
2019-07-02 08:10:25 +01:00
} else {
2020-03-04 03:45:16 +00:00
dispatch(hideStatus(status.get('id')))
2019-07-02 08:10:25 +01:00
}
},
2020-03-04 03:45:16 +00:00
})
2019-07-02 08:10:25 +01:00
2020-03-04 03:45:16 +00:00
export default connect(makeMapStateToProps, mapDispatchToProps)(Notification)