Skip to content

Commit

Permalink
Implement missing hotkeys for notifications (mastodon#9927)
Browse files Browse the repository at this point in the history
  • Loading branch information
ClearlyClaire authored and Gargron committed Jan 27, 2019
1 parent 54fc6f8 commit a02fb71
Show file tree
Hide file tree
Showing 2 changed files with 79 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,10 @@ class Notification extends ImmutablePureComponent {
onMoveUp: PropTypes.func.isRequired,
onMoveDown: PropTypes.func.isRequired,
onMention: PropTypes.func.isRequired,
onFavourite: PropTypes.func.isRequired,
onReblog: PropTypes.func.isRequired,
onToggleHidden: PropTypes.func.isRequired,
status: PropTypes.option,
intl: PropTypes.object.isRequired,
};

Expand Down Expand Up @@ -64,14 +68,32 @@ class Notification extends ImmutablePureComponent {
onMention(notification.get('account'), this.context.router.history);
}

handleHotkeyFavourite = () => {
const { status } = this.props;
if (status) this.props.onFavourite(status);
}

handleHotkeyBoost = e => {
const { status } = this.props;
if (status) this.props.onReblog(status, e);
}

handleHotkeyToggleHidden = () => {
const { status } = this.props;
if (status) this.props.onToggleHidden(status);
}

getHandlers () {
return {
moveUp: this.handleMoveUp,
moveDown: this.handleMoveDown,
reply: this.handleMention,
favourite: this.handleHotkeyFavourite,
boost: this.handleHotkeyBoost,
mention: this.handleMention,
open: this.handleOpen,
openProfile: this.handleOpenProfile,
mention: this.handleMention,
reply: this.handleMention,
moveUp: this.handleMoveUp,
moveDown: this.handleMoveDown,
toggleHidden: this.handleHotkeyToggleHidden,
};
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,31 @@
import { connect } from 'react-redux';
import { makeGetNotification } from '../../../selectors';
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';
import { boostModal } from '../../../initial_state';

const makeMapStateToProps = () => {
const getNotification = makeGetNotification();
const getStatus = makeGetStatus();

const mapStateToProps = (state, props) => ({
notification: getNotification(state, props.notification, props.accountId),
});
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') }) : null,
};
};

return mapStateToProps;
};
Expand All @@ -17,6 +34,38 @@ const mapDispatchToProps = dispatch => ({
onMention: (account, router) => {
dispatch(mentionCompose(account, router));
},

onModalReblog (status) {
dispatch(reblog(status));
},

onReblog (status, e) {
if (status.get('reblogged')) {
dispatch(unreblog(status));
} else {
if (e.shiftKey || !boostModal) {
this.onModalReblog(status);
} else {
dispatch(openModal('BOOST', { status, onReblog: this.onModalReblog }));
}
}
},

onFavourite (status) {
if (status.get('favourited')) {
dispatch(unfavourite(status));
} else {
dispatch(favourite(status));
}
},

onToggleHidden (status) {
if (status.get('hidden')) {
dispatch(revealStatus(status.get('id')));
} else {
dispatch(hideStatus(status.get('id')));
}
},
});

export default connect(makeMapStateToProps, mapDispatchToProps)(Notification);

0 comments on commit a02fb71

Please sign in to comment.