-
-
Notifications
You must be signed in to change notification settings - Fork 212
Expand file tree
/
Copy pathHeader.component.jsx
More file actions
148 lines (135 loc) · 4.12 KB
/
Header.component.jsx
File metadata and controls
148 lines (135 loc) · 4.12 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
import React, {Fragment, useState} from 'react';
import {Link, useHistory} from 'react-router-dom';
import {connect} from 'react-redux';
import PropTypes from 'prop-types';
import {logout} from '../../redux/auth/auth.actions';
import {ReactComponent as Search} from '../../assets/Search.svg';
import {ReactComponent as Logo} from '../../assets/LogoMd.svg';
import {ReactComponent as SmallLogo} from '../../assets/LogoGlyphMd.svg';
import Spinner from '../Spinner/Spinner.component';
import LinkButton from '../LinkButton/LinkButton.component';
import MobileSideBar from '../MobileSideBar/MobileSideBar.component';
import './Header.styles.scss';
const Header = ({auth: {isAuthenticated, loading, user}, logout}) => {
let history = useHistory();
const [searchState, setSearchState] = useState(false);
const authLinks = (
<div className='btns'>
{loading || user === null ? (
<Spinner width='50px' height='50px' />
) : (
<Link to={`/users/${user.id}`} title={user.username}>
<img
alt='user-logo'
className='logo'
src={user.gravatar}
/>
</Link>
)}
<LinkButton
text={'Log out'}
link={'/login'}
type={'s-btn__filled'}
handleClick={logout}
/>
</div>
);
const authTabs = (
<div className='s-navigation'>
<Link to='/' className='s-navigation--item is-selected'>
Products
</Link>
</div>
);
const guestTabs = (
<div className='s-navigation'>
<Link to='/' className='s-navigation--item is-selected'>
Products
</Link>
<Link to='/' className='s-navigation--item not-selected'>
Customers
</Link>
<Link to='/' className='s-navigation--item not-selected'>
Use cases
</Link>
</div>
);
const guestLinks = (
<div className='btns'>
<LinkButton text={'Log in'} link={'/login'} type={'s-btn__primary'} />
<LinkButton text={'Sign up'} link={'/register'} type={'s-btn__filled'} />
</div>
);
const SearchBar = () => {
return (
<form
onSubmit={() => history.push('/questions')}
className='small-search-form'
autoComplete='off'
>
<input
className='small-search'
autoComplete='off'
type='text'
name='search'
maxLength='35'
placeholder='Search...'
/>
<Search className="small-search-icon" />
</form>
);
}
return loading ? (
''
) : (
<Fragment>
<nav className='navbar fixed-top navbar-expand-lg navbar-light bs-md'>
<div className="hamburger">
<MobileSideBar hasOverlay />
</div>
<div className='header-brand-div'>
<Link className='navbar-brand' to='/'>
<Logo className='full-logo' />
<SmallLogo className='glyph-logo' />
</Link>
{!loading && (
<Fragment>{isAuthenticated ? authTabs : guestTabs}</Fragment>
)}
</div>
<div className="header-search-div">
<form
id='search'
onSubmit={() => history.push('/questions')}
className={`grid--cell fl-grow1 searchbar px12 js-searchbar`}
autoComplete='off'
>
<div className='ps-relative search-frame'>
<input
className='s-input s-input__search h100 search-box'
autoComplete='off'
type='text'
name='search'
maxLength='35'
placeholder='Search...'
/>
<Search />
</div>
</form>
<Search className="search-icon" onClick={() => setSearchState(!searchState)} />
{!loading && (
<Fragment>{isAuthenticated ? authLinks : guestLinks}</Fragment>
)}
</div>
</nav>
{searchState && <SearchBar />}
</Fragment>
);
};
Header.propTypes = {
logout: PropTypes.func.isRequired,
auth: PropTypes.object.isRequired,
};
const mapStateToProps = (state) => ({
auth: state.auth,
});
export default connect(mapStateToProps, {logout})(Header);