Fix routing issues, especially keyboards shortcuts changing location

pull/602/head
Thibaut Girka 2018-07-24 20:33:17 +02:00 committed by ThibG
parent 1aa253c41d
commit 037228cf03
1 changed files with 19 additions and 18 deletions

View File

@ -109,8 +109,9 @@ export default class UI extends React.Component {
navbarUnder: PropTypes.bool, navbarUnder: PropTypes.bool,
isComposing: PropTypes.bool, isComposing: PropTypes.bool,
hasComposingText: PropTypes.bool, hasComposingText: PropTypes.bool,
location: PropTypes.object, match: PropTypes.object.isRequired,
router: PropTypes.object, location: PropTypes.object.isRequired,
history: PropTypes.object.isRequired,
intl: PropTypes.object.isRequired, intl: PropTypes.object.isRequired,
dropdownMenuIsOpen: PropTypes.bool, dropdownMenuIsOpen: PropTypes.bool,
}; };
@ -198,7 +199,7 @@ export default class UI extends React.Component {
handleServiceWorkerPostMessage = ({ data }) => { handleServiceWorkerPostMessage = ({ data }) => {
if (data.type === 'navigate') { if (data.type === 'navigate') {
this.props.router.history.push(data.path); this.props.history.push(data.path);
} else { } else {
console.warn('Unknown message type:', data.type); console.warn('Unknown message type:', data.type);
} }
@ -306,9 +307,9 @@ export default class UI extends React.Component {
handleHotkeyBack = () => { handleHotkeyBack = () => {
// if history is exhausted, or we would leave mastodon, just go to root. // if history is exhausted, or we would leave mastodon, just go to root.
if (window.history.state) { if (window.history.state) {
this.context.router.history.goBack(); this.props.history.goBack();
} else { } else {
this.context.router.history.push('/'); this.props.history.push('/');
} }
} }
@ -318,54 +319,54 @@ export default class UI extends React.Component {
handleHotkeyToggleHelp = () => { handleHotkeyToggleHelp = () => {
if (this.props.location.pathname === '/keyboard-shortcuts') { if (this.props.location.pathname === '/keyboard-shortcuts') {
this.props.router.history.goBack(); this.props.history.goBack();
} else { } else {
this.props.router.history.push('/keyboard-shortcuts'); this.props.history.push('/keyboard-shortcuts');
} }
} }
handleHotkeyGoToHome = () => { handleHotkeyGoToHome = () => {
this.props.router.history.push('/timelines/home'); this.props.history.push('/timelines/home');
} }
handleHotkeyGoToNotifications = () => { handleHotkeyGoToNotifications = () => {
this.props.router.history.push('/notifications'); this.props.history.push('/notifications');
} }
handleHotkeyGoToLocal = () => { handleHotkeyGoToLocal = () => {
this.props.router.history.push('/timelines/public/local'); this.props.history.push('/timelines/public/local');
} }
handleHotkeyGoToFederated = () => { handleHotkeyGoToFederated = () => {
this.props.router.history.push('/timelines/public'); this.props.history.push('/timelines/public');
} }
handleHotkeyGoToDirect = () => { handleHotkeyGoToDirect = () => {
this.props.router.history.push('/timelines/direct'); this.props.history.push('/timelines/direct');
} }
handleHotkeyGoToStart = () => { handleHotkeyGoToStart = () => {
this.props.router.history.push('/getting-started'); this.props.history.push('/getting-started');
} }
handleHotkeyGoToFavourites = () => { handleHotkeyGoToFavourites = () => {
this.props.router.history.push('/favourites'); this.props.history.push('/favourites');
} }
handleHotkeyGoToPinned = () => { handleHotkeyGoToPinned = () => {
this.props.router.history.push('/pinned'); this.props.history.push('/pinned');
} }
handleHotkeyGoToProfile = () => { handleHotkeyGoToProfile = () => {
this.props.router.history.push(`/accounts/${me}`); this.props.history.push(`/accounts/${me}`);
} }
handleHotkeyGoToBlocked = () => { handleHotkeyGoToBlocked = () => {
this.props.router.history.push('/blocks'); this.props.history.push('/blocks');
} }
handleHotkeyGoToMuted = () => { handleHotkeyGoToMuted = () => {
this.props.router.history.push('/mutes'); this.props.history.push('/mutes');
} }
render () { render () {