Fix(nav): clicking on points should not hit server
Refactor(nav): fccnavitem is now points-nav-item
This commit is contained in:
@ -10,7 +10,7 @@ import {
|
||||
} from 'react-bootstrap';
|
||||
|
||||
import navLinks from './links.json';
|
||||
import FCCNavItem from './NavItem.jsx';
|
||||
import PointsNavItem from './Points-Nav-Item.jsx';
|
||||
import AvatarNavItem from './Avatar-Nav-Item.jsx';
|
||||
|
||||
const fCClogo = 'https://s3.amazonaws.com/freecodecamp/freecodecamp_logo.svg';
|
||||
@ -176,9 +176,10 @@ export default class extends React.Component {
|
||||
key='points'
|
||||
to='/settings'
|
||||
>
|
||||
<FCCNavItem className='brownie-points-nav'>
|
||||
[ { points } ]
|
||||
</FCCNavItem>
|
||||
<PointsNavItem
|
||||
className='brownie-points-nav'
|
||||
points={ points }
|
||||
/>
|
||||
</LinkContainer>
|
||||
);
|
||||
}
|
||||
|
@ -1,91 +0,0 @@
|
||||
import React from 'react';
|
||||
import classNames from 'classnames';
|
||||
|
||||
export default React.createClass({
|
||||
displayName: 'FCCNavItem',
|
||||
|
||||
propTypes: {
|
||||
active: React.PropTypes.bool,
|
||||
'aria-controls': React.PropTypes.string,
|
||||
children: React.PropTypes.node,
|
||||
className: React.PropTypes.string,
|
||||
disabled: React.PropTypes.bool,
|
||||
eventKey: React.PropTypes.any,
|
||||
href: React.PropTypes.string,
|
||||
linkId: React.PropTypes.string,
|
||||
onSelect: React.PropTypes.func,
|
||||
role: React.PropTypes.string,
|
||||
target: React.PropTypes.string,
|
||||
title: React.PropTypes.node
|
||||
},
|
||||
|
||||
getDefaultProps() {
|
||||
return {
|
||||
href: '#'
|
||||
};
|
||||
},
|
||||
|
||||
handleClick(e) {
|
||||
if (this.props.onSelect) {
|
||||
e.preventDefault();
|
||||
|
||||
if (!this.props.disabled) {
|
||||
this.props.onSelect(
|
||||
this.props.eventKey,
|
||||
this.props.href,
|
||||
this.props.target
|
||||
);
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
render() {
|
||||
let {
|
||||
role,
|
||||
linkId,
|
||||
disabled,
|
||||
active,
|
||||
href,
|
||||
title,
|
||||
target,
|
||||
children,
|
||||
'aria-controls': ariaControls, // eslint-disable-line react/prop-types
|
||||
className
|
||||
} = this.props;
|
||||
|
||||
const linkClassName = classNames(className, {
|
||||
// 'active': active, we don't actually use the active class
|
||||
// but it is used for a11y below
|
||||
disabled: disabled
|
||||
});
|
||||
|
||||
let linkProps = {
|
||||
role,
|
||||
href,
|
||||
title,
|
||||
target,
|
||||
id: linkId,
|
||||
onClick: this.handleClick,
|
||||
ref: 'anchor'
|
||||
};
|
||||
|
||||
if (!role && href === '#') {
|
||||
linkProps.role = 'button';
|
||||
}
|
||||
|
||||
return (
|
||||
<li
|
||||
role='presentation'
|
||||
>
|
||||
<a
|
||||
{ ...linkProps }
|
||||
aria-controls={ ariaControls }
|
||||
aria-selected={ active }
|
||||
className={ linkClassName }
|
||||
>
|
||||
{ children }
|
||||
</a>
|
||||
</li>
|
||||
);
|
||||
}
|
||||
});
|
40
common/app/components/Nav/Points-Nav-Item.jsx
Normal file
40
common/app/components/Nav/Points-Nav-Item.jsx
Normal file
@ -0,0 +1,40 @@
|
||||
import React from 'react';
|
||||
|
||||
export default React.createClass({
|
||||
displayName: 'Points',
|
||||
|
||||
propTypes: {
|
||||
'aria-controls': React.PropTypes.string,
|
||||
className: React.PropTypes.string,
|
||||
href: React.PropTypes.string,
|
||||
onClick: React.PropTypes.func.isRequired,
|
||||
points: React.PropTypes.func,
|
||||
title: React.PropTypes.node
|
||||
},
|
||||
|
||||
render() {
|
||||
let {
|
||||
href,
|
||||
title,
|
||||
points,
|
||||
'aria-controls': ariaControls, // eslint-disable-line react/prop-types
|
||||
className,
|
||||
onClick
|
||||
} = this.props;
|
||||
|
||||
let linkProps = {
|
||||
title,
|
||||
href,
|
||||
onClick,
|
||||
className,
|
||||
ref: 'anchor',
|
||||
'aria-controls': ariaControls
|
||||
};
|
||||
|
||||
return (
|
||||
<li role='presentation'>
|
||||
<a { ...linkProps }>[ { points || 1 } ]</a>
|
||||
</li>
|
||||
);
|
||||
}
|
||||
});
|
Reference in New Issue
Block a user