Improve trends layout (#7700)
* Allow collapsing trends, responsively hide trends * Add trends column
This commit is contained in:
parent
69b45350fe
commit
73c0c36e7b
8 changed files with 124 additions and 8 deletions
|
@ -5,6 +5,7 @@ import PropTypes from 'prop-types';
|
|||
import ImmutablePropTypes from 'react-immutable-proptypes';
|
||||
import { FormattedMessage, defineMessages } from 'react-intl';
|
||||
import Hashtag from '../../../components/hashtag';
|
||||
import { Link } from 'react-router-dom';
|
||||
|
||||
const messages = defineMessages({
|
||||
refresh_trends: { id: 'trends.refresh', defaultMessage: 'Refresh' },
|
||||
|
@ -19,6 +20,9 @@ export default class Trends extends ImmutablePureComponent {
|
|||
static propTypes = {
|
||||
trends: ImmutablePropTypes.list,
|
||||
loading: PropTypes.bool.isRequired,
|
||||
showTrends: PropTypes.bool.isRequired,
|
||||
fetchTrends: PropTypes.func.isRequired,
|
||||
toggleTrends: PropTypes.func.isRequired,
|
||||
};
|
||||
|
||||
componentDidMount () {
|
||||
|
@ -29,8 +33,12 @@ export default class Trends extends ImmutablePureComponent {
|
|||
this.props.fetchTrends();
|
||||
}
|
||||
|
||||
handleToggle = () => {
|
||||
this.props.toggleTrends(!this.props.showTrends);
|
||||
}
|
||||
|
||||
render () {
|
||||
const { intl, trends, loading } = this.props;
|
||||
const { intl, trends, loading, showTrends } = this.props;
|
||||
|
||||
if (!trends || trends.size < 1) {
|
||||
return null;
|
||||
|
@ -44,13 +52,18 @@ export default class Trends extends ImmutablePureComponent {
|
|||
<i className='fa fa-fire fa-fw' />
|
||||
<FormattedMessage id='trends.header' defaultMessage='Trending now' />
|
||||
</button>
|
||||
|
||||
<div className='column-header__buttons'>
|
||||
<button onClick={this.handleRefreshTrends} className='column-header__button' title={intl.formatMessage(messages.refresh_trends)} aria-label={intl.formatMessage(messages.refresh_trends)} disabled={loading}><i className={classNames('fa', 'fa-refresh', { 'fa-spin': loading })} /></button>
|
||||
{showTrends && <button onClick={this.handleRefreshTrends} className='column-header__button' title={intl.formatMessage(messages.refresh_trends)} aria-label={intl.formatMessage(messages.refresh_trends)} disabled={loading}><i className={classNames('fa', 'fa-refresh', { 'fa-spin': loading })} /></button>}
|
||||
<button onClick={this.handleToggle} className='column-header__button'><i className={classNames('fa', showTrends ? 'fa-chevron-down' : 'fa-chevron-up')} /></button>
|
||||
</div>
|
||||
</h1>
|
||||
</div>
|
||||
|
||||
<div className='getting-started__scrollable'>{trends.take(3).map(hashtag => <Hashtag key={hashtag.get('name')} hashtag={hashtag} />)}</div>
|
||||
{showTrends && <div className='getting-started__scrollable'>
|
||||
{trends.take(3).map(hashtag => <Hashtag key={hashtag.get('name')} hashtag={hashtag} />)}
|
||||
<Link to='/trends' className='load-more'><FormattedMessage id='status.load_more' defaultMessage='Load more' /></Link>
|
||||
</div>}
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
|
|
@ -2,14 +2,17 @@ import { connect } from 'react-redux';
|
|||
import { injectIntl } from 'react-intl';
|
||||
import { fetchTrends } from '../../../actions/trends';
|
||||
import Trends from '../components/trends';
|
||||
import { changeSetting } from '../../../actions/settings';
|
||||
|
||||
const mapStateToProps = state => ({
|
||||
trends: state.getIn(['trends', 'items']),
|
||||
loading: state.getIn(['trends', 'isLoading']),
|
||||
showTrends: state.getIn(['settings', 'trends', 'show']),
|
||||
});
|
||||
|
||||
const mapDispatchToProps = dispatch => ({
|
||||
fetchTrends: () => dispatch(fetchTrends()),
|
||||
toggleTrends: show => dispatch(changeSetting(['trends', 'show'], show)),
|
||||
});
|
||||
|
||||
export default injectIntl(connect(mapStateToProps, mapDispatchToProps)(Trends));
|
||||
|
|
|
@ -80,6 +80,7 @@ export default class GettingStarted extends ImmutablePureComponent {
|
|||
|
||||
const navItems = [];
|
||||
let i = 1;
|
||||
let height = 0;
|
||||
|
||||
if (multiColumn) {
|
||||
navItems.push(
|
||||
|
@ -88,6 +89,8 @@ export default class GettingStarted extends ImmutablePureComponent {
|
|||
<ColumnLink key={i++} icon='globe' text={intl.formatMessage(messages.public_timeline)} to='/timelines/public' />,
|
||||
<ColumnSubheading key={i++} text={intl.formatMessage(messages.personal)} />
|
||||
);
|
||||
|
||||
height += 34*2 + 48*2;
|
||||
}
|
||||
|
||||
navItems.push(
|
||||
|
@ -96,8 +99,11 @@ export default class GettingStarted extends ImmutablePureComponent {
|
|||
<ColumnLink key={i++} icon='bars' text={intl.formatMessage(messages.lists)} to='/lists' />
|
||||
);
|
||||
|
||||
height += 48*3;
|
||||
|
||||
if (myAccount.get('locked')) {
|
||||
navItems.push(<ColumnLink key={i++} icon='users' text={intl.formatMessage(messages.follow_requests)} badge={badgeDisplay(unreadFollowRequests, 40)} to='/follow_requests' />);
|
||||
height += 48;
|
||||
}
|
||||
|
||||
if (!multiColumn) {
|
||||
|
@ -106,6 +112,8 @@ export default class GettingStarted extends ImmutablePureComponent {
|
|||
<ColumnLink key={i++} icon='gears' text={intl.formatMessage(messages.preferences)} href='/settings/preferences' />,
|
||||
<ColumnLink key={i++} icon='lock' text={intl.formatMessage(messages.security)} href='/auth/edit' />
|
||||
);
|
||||
|
||||
height += 34 + 48*2;
|
||||
}
|
||||
|
||||
return (
|
||||
|
@ -119,7 +127,7 @@ export default class GettingStarted extends ImmutablePureComponent {
|
|||
</h1>
|
||||
</div>}
|
||||
|
||||
<div className='getting-started__wrapper'>
|
||||
<div className='getting-started__wrapper' style={{ height }}>
|
||||
{!multiColumn && <NavigationBar account={myAccount} />}
|
||||
{navItems}
|
||||
</div>
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue