fix: show profile link when user signed in on landing page (#39983)

This commit is contained in:
Ahmad Abdolsaheb
2020-10-22 01:20:22 +03:00
committed by GitHub
parent 0caa2fe782
commit 7b6e32ca7c
5 changed files with 17 additions and 39 deletions

View File

@ -23,14 +23,9 @@ describe('<UniversalNav />', () => {
}); });
describe('<NavLinks />', () => { describe('<NavLinks />', () => {
it('shows Curriculum and Sign In buttons on landing page', () => { it('shows Curriculum and Sign In buttons when not signed in', () => {
const landingPageProps = { const landingPageProps = {
user: { pending: false
username: 'test-user',
picture: 'https://freecodecamp.org/image.png'
},
pending: false,
pathName: '/'
}; };
const shallow = new ShallowRenderer(); const shallow = new ShallowRenderer();
shallow.render(<AuthOrProfile {...landingPageProps} />); shallow.render(<AuthOrProfile {...landingPageProps} />);
@ -48,11 +43,9 @@ describe('<NavLinks />', () => {
const defaultUserProps = { const defaultUserProps = {
user: { user: {
username: 'test-user', username: 'test-user',
picture: 'https://freecodecamp.org/image.png', picture: 'https://freecodecamp.org/image.png'
isDonating: true
}, },
pending: false, pending: false
pathName: '/learn'
}; };
const shallow = new ShallowRenderer(); const shallow = new ShallowRenderer();
shallow.render(<AuthOrProfile {...defaultUserProps} />); shallow.render(<AuthOrProfile {...defaultUserProps} />);
@ -68,8 +61,7 @@ describe('<NavLinks />', () => {
username: 'test-user', username: 'test-user',
picture: 'https://freecodecamp.org/image.png' picture: 'https://freecodecamp.org/image.png'
}, },
pending: false, pending: false
pathName: '/learn'
}; };
const componentTree = renderer const componentTree = renderer
@ -86,8 +78,7 @@ describe('<NavLinks />', () => {
picture: 'https://freecodecamp.org/image.png', picture: 'https://freecodecamp.org/image.png',
isDonating: true isDonating: true
}, },
pending: false, pending: false
pathName: '/learn'
}; };
const componentTree = renderer const componentTree = renderer
.create(<AuthOrProfile {...donatingUserProps} />) .create(<AuthOrProfile {...donatingUserProps} />)
@ -103,8 +94,7 @@ describe('<NavLinks />', () => {
picture: 'https://freecodecamp.org/image.png', picture: 'https://freecodecamp.org/image.png',
yearsTopContributor: [2020] yearsTopContributor: [2020]
}, },
pending: false, pending: false
pathName: '/learn'
}; };
const componentTree = renderer const componentTree = renderer
@ -121,8 +111,7 @@ describe('<NavLinks />', () => {
isDonating: true, isDonating: true,
yearsTopContributor: [2020] yearsTopContributor: [2020]
}, },
pending: false, pending: false
pathName: '/learn'
}; };
const componentTree = renderer const componentTree = renderer
.create(<AuthOrProfile {...topDonatingContributorUserProps} />) .create(<AuthOrProfile {...topDonatingContributorUserProps} />)

View File

@ -6,23 +6,22 @@ import Login from '../components/Login';
const propTypes = { const propTypes = {
displayMenu: PropTypes.bool, displayMenu: PropTypes.bool,
fetchState: PropTypes.shape({ pending: PropTypes.bool }), fetchState: PropTypes.shape({ pending: PropTypes.bool }),
pathName: PropTypes.string.isRequired,
user: PropTypes.object user: PropTypes.object
}; };
export function AuthOrProfile({ user, pathName, pending }) { export function AuthOrProfile({ user, pending }) {
const isUserDonating = user && user.isDonating; const isUserDonating = user && user.isDonating;
const isUserSignedIn = user && user.username; const isUserSignedIn = user && user.username;
const isTopContributor = const isTopContributor =
user && user.yearsTopContributor && user.yearsTopContributor.length > 0; user && user.yearsTopContributor && user.yearsTopContributor.length > 0;
if (pending && pathName !== '/') { if (pending) {
return ( return (
<div className='nav-skeleton'> <div className='nav-skeleton'>
<SkeletonSprite /> <SkeletonSprite />
</div> </div>
); );
} else if (pathName === '/' || !isUserSignedIn) { } else if (!isUserSignedIn) {
return ( return (
<> <>
<li> <li>
@ -57,12 +56,12 @@ export function AuthOrProfile({ user, pathName, pending }) {
} }
} }
export function NavLinks({ displayMenu, pathName, user, fetchState }) { export function NavLinks({ displayMenu, user, fetchState }) {
const { pending } = fetchState; const { pending } = fetchState;
return ( return (
<div className='main-nav-group'> <div className='main-nav-group'>
<ul className={'nav-list' + (displayMenu ? ' display-flex' : '')}> <ul className={'nav-list' + (displayMenu ? ' display-flex' : '')}>
<AuthOrProfile pathName={pathName} pending={pending} user={user} /> <AuthOrProfile pending={pending} user={user} />
</ul> </ul>
</div> </div>
); );

View File

@ -13,7 +13,6 @@ export const UniversalNav = ({
toggleDisplayMenu, toggleDisplayMenu,
menuButtonRef, menuButtonRef,
searchBarRef, searchBarRef,
pathName,
user, user,
fetchState fetchState
}) => ( }) => (
@ -33,12 +32,7 @@ export const UniversalNav = ({
</Link> </Link>
</div> </div>
<div className='universal-nav-right main-nav'> <div className='universal-nav-right main-nav'>
<NavLinks <NavLinks displayMenu={displayMenu} fetchState={fetchState} user={user} />
displayMenu={displayMenu}
fetchState={fetchState}
pathName={pathName}
user={user}
/>
</div> </div>
<MenuButton <MenuButton
displayMenu={displayMenu} displayMenu={displayMenu}
@ -55,7 +49,6 @@ UniversalNav.propTypes = {
displayMenu: PropTypes.bool, displayMenu: PropTypes.bool,
fetchState: PropTypes.shape({ pending: PropTypes.bool }), fetchState: PropTypes.shape({ pending: PropTypes.bool }),
menuButtonRef: PropTypes.object, menuButtonRef: PropTypes.object,
pathName: PropTypes.string.isRequired,
searchBarRef: PropTypes.object, searchBarRef: PropTypes.object,
toggleDisplayMenu: PropTypes.func, toggleDisplayMenu: PropTypes.func,
user: PropTypes.object user: PropTypes.object

View File

@ -9,7 +9,6 @@ import './header.css';
const propTypes = { const propTypes = {
fetchState: PropTypes.shape({ pending: PropTypes.bool }), fetchState: PropTypes.shape({ pending: PropTypes.bool }),
pathName: PropTypes.string.isRequired,
user: PropTypes.object user: PropTypes.object
}; };
@ -54,7 +53,7 @@ export class Header extends React.Component {
} }
render() { render() {
const { displayMenu } = this.state; const { displayMenu } = this.state;
const { fetchState, pathName, user } = this.props; const { fetchState, user } = this.props;
return ( return (
<> <>
<Helmet> <Helmet>
@ -65,7 +64,6 @@ export class Header extends React.Component {
displayMenu={displayMenu} displayMenu={displayMenu}
fetchState={fetchState} fetchState={fetchState}
menuButtonRef={this.menuButtonRef} menuButtonRef={this.menuButtonRef}
pathName={pathName}
searchBarRef={this.searchBarRef} searchBarRef={this.searchBarRef}
toggleDisplayMenu={this.toggleDisplayMenu} toggleDisplayMenu={this.toggleDisplayMenu}
user={user} user={user}

View File

@ -159,8 +159,7 @@ class DefaultLayout extends Component {
showFooter = true, showFooter = true,
theme = 'default', theme = 'default',
user, user,
useTheme = true, useTheme = true
pathname
} = this.props; } = this.props;
return ( return (
@ -226,7 +225,7 @@ class DefaultLayout extends Component {
<style>{fontawesome.dom.css()}</style> <style>{fontawesome.dom.css()}</style>
</Helmet> </Helmet>
<WithInstantSearch> <WithInstantSearch>
<Header fetchState={fetchState} pathName={pathname} user={user} /> <Header fetchState={fetchState} user={user} />
<div className={`default-layout`}> <div className={`default-layout`}>
<OfflineWarning isOnline={isOnline} isSignedIn={isSignedIn} /> <OfflineWarning isOnline={isOnline} isSignedIn={isSignedIn} />
{hasMessage && flashMessage ? ( {hasMessage && flashMessage ? (