mirror of
https://github.com/mastodon/mastodon.git
synced 2024-11-15 19:31:42 +00:00
cc396f085d
So far, glitch-soc used history.length to decide whether to call `goBack()` or go to / in order to not leave the webUI. This made clicking the “Back” button go to the “Getting started” column instead of going back in the browser's history when such an action would leave the web UI, but also when: - The WebUI is refreshed (F5) - A tab is restored - The history length reaches its maximum (e.g., 50 in Firefox) This commit fixes these shortcomings by checking `window.history.state`. Indeed, we only want to go back in the browser's history when the current location has been reached from within the WebUI, which only happens via `pushState` as far as I know. Since browser store the serialized state in the browser history, this also survives page reload and session restoration.
32 lines
902 B
JavaScript
32 lines
902 B
JavaScript
import React from 'react';
|
|
import { FormattedMessage } from 'react-intl';
|
|
import PropTypes from 'prop-types';
|
|
|
|
export default class ColumnBackButtonSlim extends React.PureComponent {
|
|
|
|
static contextTypes = {
|
|
router: PropTypes.object,
|
|
};
|
|
|
|
handleClick = () => {
|
|
// if history is exhausted, or we would leave mastodon, just go to root.
|
|
if (window.history.state) {
|
|
this.context.router.history.goBack();
|
|
} else {
|
|
this.context.router.history.push('/');
|
|
}
|
|
}
|
|
|
|
render () {
|
|
return (
|
|
<div className='column-back-button--slim'>
|
|
<div role='button' tabIndex='0' onClick={this.handleClick} className='column-back-button column-back-button--slim-button'>
|
|
<i className='fa fa-fw fa-chevron-left column-back-button__icon' />
|
|
<FormattedMessage id='column_back_button.label' defaultMessage='Back' />
|
|
</div>
|
|
</div>
|
|
);
|
|
}
|
|
|
|
}
|