mirror of
https://git.kescher.at/CatCatNya/catstodon.git
synced 2024-11-25 02:48:06 +01:00
d6eacb79c6
Port 1b70d7ed7c
to glitch-soc
Co-authored-by: Claire <claire.github-309c@sitedethib.com>
Signed-off-by: Claire <claire.github-309c@sitedethib.com>
60 lines
1.7 KiB
JavaScript
60 lines
1.7 KiB
JavaScript
import PropTypes from 'prop-types';
|
|
import { PureComponent } from 'react';
|
|
import { createPortal } from 'react-dom';
|
|
|
|
import { FormattedMessage } from 'react-intl';
|
|
|
|
import { withRouter } from 'react-router-dom';
|
|
|
|
import { Icon } from 'flavours/glitch/components/icon';
|
|
import { WithRouterPropTypes } from 'flavours/glitch/utils/react_router';
|
|
|
|
class ColumnBackButton extends PureComponent {
|
|
|
|
static propTypes = {
|
|
multiColumn: PropTypes.bool,
|
|
...WithRouterPropTypes,
|
|
};
|
|
|
|
handleClick = () => {
|
|
const { history } = this.props;
|
|
|
|
if (history.location?.state?.fromMastodon) {
|
|
history.goBack();
|
|
} else {
|
|
history.push('/');
|
|
}
|
|
};
|
|
|
|
render () {
|
|
const { multiColumn } = this.props;
|
|
|
|
const component = (
|
|
<button onClick={this.handleClick} className='column-back-button'>
|
|
<Icon id='chevron-left' className='column-back-button__icon' fixedWidth />
|
|
<FormattedMessage id='column_back_button.label' defaultMessage='Back' />
|
|
</button>
|
|
);
|
|
|
|
if (multiColumn) {
|
|
return component;
|
|
} else {
|
|
// The portal container and the component may be rendered to the DOM in
|
|
// the same React render pass, so the container might not be available at
|
|
// the time `render()` is called.
|
|
const container = document.getElementById('tabs-bar__portal');
|
|
if (container === null) {
|
|
// The container wasn't available, force a re-render so that the
|
|
// component can eventually be inserted in the container and not scroll
|
|
// with the rest of the area.
|
|
this.forceUpdate();
|
|
return component;
|
|
} else {
|
|
return createPortal(component, container);
|
|
}
|
|
}
|
|
}
|
|
|
|
}
|
|
|
|
export default withRouter(ColumnBackButton);
|