mirror of
https://framagit.org/tykayn/mastodon.git
synced 2023-08-25 08:33:12 +02:00
![Thibaut Girka](/assets/img/avatar_default.png)
This is both for consistency with account timelines and to not mess with the logic used to decide whether going back in the browser's history is going to make us leave the WebUI.
60 lines
1.8 KiB
JavaScript
60 lines
1.8 KiB
JavaScript
import PropTypes from 'prop-types';
|
|
import React, { Component, Fragment } from 'react';
|
|
import { FormattedMessage } from 'react-intl';
|
|
import { NavLink } from 'react-router-dom';
|
|
|
|
export default class SectionHeadline extends Component {
|
|
|
|
static propTypes = {
|
|
timelineId: PropTypes.string.isRequired,
|
|
to: PropTypes.string.isRequired,
|
|
pinned: PropTypes.bool.isRequired,
|
|
onlyMedia: PropTypes.bool.isRequired,
|
|
onClick: PropTypes.func,
|
|
};
|
|
|
|
shouldComponentUpdate (nextProps) {
|
|
return (
|
|
this.props.onlyMedia !== nextProps.onlyMedia ||
|
|
this.props.pinned !== nextProps.pinned ||
|
|
this.props.to !== nextProps.to ||
|
|
this.props.timelineId !== nextProps.timelineId
|
|
);
|
|
}
|
|
|
|
handleClick = e => {
|
|
const { onClick } = this.props;
|
|
|
|
if (typeof onClick === 'function') {
|
|
e.preventDefault();
|
|
|
|
onClick.call(this, e);
|
|
}
|
|
}
|
|
|
|
render () {
|
|
const { timelineId, to, pinned, onlyMedia } = this.props;
|
|
|
|
return (
|
|
<div className={`${timelineId}-timeline__section-headline`}>
|
|
{pinned ? (
|
|
<Fragment>
|
|
<a href={to} className={!onlyMedia ? 'active' : undefined} onClick={this.handleClick}>
|
|
<FormattedMessage id='timeline.posts' defaultMessage='Toots' />
|
|
</a>
|
|
<a href={`${to}/media`} className={onlyMedia ? 'active' : undefined} onClick={this.handleClick}>
|
|
<FormattedMessage id='timeline.media' defaultMessage='Media' />
|
|
</a>
|
|
</Fragment>
|
|
) : (
|
|
<Fragment>
|
|
<NavLink exact to={to}><FormattedMessage id='timeline.posts' defaultMessage='Toots' /></NavLink>
|
|
<NavLink exact to={`${to}/media`}><FormattedMessage id='timeline.media' defaultMessage='Media' /></NavLink>
|
|
</Fragment>
|
|
)}
|
|
</div>
|
|
);
|
|
}
|
|
|
|
}
|