Pass search query and handler in props

This commit is contained in:
LordMathis 2020-01-11 00:35:59 +01:00
parent a5ad47a4d8
commit d5eab71f3a
No known key found for this signature in database
GPG Key ID: 575849FD91CE470C
6 changed files with 23 additions and 17 deletions

View File

@ -9,7 +9,9 @@ import contentStyle from '../stylesheets/content.scss'
export default class Blog extends Component { export default class Blog extends Component {
static propTypes = { static propTypes = {
isLoading: PropTypes.bool.isRequired, isLoading: PropTypes.bool.isRequired,
posts: PropTypes.arrayOf(PropTypes.object).isRequired posts: PropTypes.arrayOf(PropTypes.object).isRequired,
searchString: PropTypes.string.isRequired,
handleChange: PropTypes.func.isRequired
} }
render () { render () {
@ -41,7 +43,7 @@ export default class Blog extends Component {
<div className={`${contentStyle.content}`} id="blog" role="region" aria-label="Blog posts"> <div className={`${contentStyle.content}`} id="blog" role="region" aria-label="Blog posts">
<div className={styles.headerContainer}> <div className={styles.headerContainer}>
<Header header={'Blog'} role="heading" aria-level="2"/> <Header header={'Blog'} role="heading" aria-level="2"/>
<SearchBox /> <SearchBox searchString={this.props.searchString} handleChange={this.props.handleChange} />
</div> </div>
<div className={`${styles.postsList}`} role="list"> <div className={`${styles.postsList}`} role="list">
{postsHTML} {postsHTML}

View File

@ -3,7 +3,7 @@ import { Navbar, Header } from '.'
import '../stylesheets/globals.scss' import '../stylesheets/globals.scss'
import contentStyle from '../stylesheets/content.scss' import contentStyle from '../stylesheets/content.scss'
export const NotFoundPage = (props) => { const NotFoundPage = (props) => {
return ( return (
<div> <div>
<Navbar config={props.config}/> <Navbar config={props.config}/>

View File

@ -5,14 +5,17 @@ import styles from './SearchBox.scss'
export default class SearchBox extends Component { export default class SearchBox extends Component {
static propTypes = { static propTypes = {
query: PropTypes.string handleChange: PropTypes.func.isRequired,
searchString: PropTypes.string
} }
render () { render () {
return ( return (
<div className={styles.container}> <div className={styles.container}>
<input placeholder='Search' className={styles.search} type="text" /> <input placeholder='Search' className={styles.search} type="text" value={this.props.searchString} onChange={this.props.handleChange}/>
<i className="fa fa-search"></i> <span>
<i className={`fa fa-search ${styles.icon}`}></i>
</span>
</div> </div>
) )
} }

View File

@ -6,7 +6,6 @@
justify-content: center; justify-content: center;
align-items: center; align-items: center;
box-sizing: border-box; box-sizing: border-box;
border: 2px $black;
} }
.search { .search {
@ -15,11 +14,10 @@
width: 20px; width: 20px;
color: $black; color: $black;
font-size: 16px; font-size: 16px;
font-weight: 100;
letter-spacing: 2px; letter-spacing: 2px;
border: none; border: none;
border-radius: 5px; border-radius: 5px;
background: $body; background: $white;
transition: width 0.4s ease; transition: width 0.4s ease;
outline: none; outline: none;
box-sizing: border-box; box-sizing: border-box;
@ -27,7 +25,7 @@
&:focus{ width: 300px; } &:focus{ width: 300px; }
} }
i{ .icon{
position: relative; position: relative;
left: -37px; left: -37px;
color: $black; color: $black;

View File

@ -12,13 +12,18 @@ export default class BlogContainer extends Component {
super(props) super(props)
this.state = { this.state = {
isLoading: false, isLoading: false,
posts: props.posts posts: props.posts,
searchString: ''
} }
} }
handleChange (event) {
this.setState({ searchString: event.target.value })
}
render () { render () {
return ( return (
<Blog isLoading={ this.state.isLoading } posts={ this.state.posts } /> <Blog isLoading={ this.state.isLoading } posts={ this.state.posts } searchString={this.state.searchString} handleChange={this.handleChange.bind(this)} />
) )
} }
} }

View File

@ -11,13 +11,11 @@ export default class NotFoundContainer extends Component {
constructor (props) { constructor (props) {
super(props) super(props)
let data let data
if (typeof window === 'undefined') {
// eslint-disable-next-line no-undef data = props.staticContext.context
if (__isBrowser__) { } else {
data = window.__INITIAL_DATA__ data = window.__INITIAL_DATA__
delete window.__INITIAL_DATA__ delete window.__INITIAL_DATA__
} else {
data = props.staticContext.context
} }
this.state = { this.state = {