Search bar no hace search y correccion de bug en makelink

This commit is contained in:
Daniel Cortes
2020-06-04 21:22:15 -04:00
parent 964df61284
commit b5e0d85b3b
3 changed files with 38 additions and 37 deletions

View File

@@ -85,7 +85,7 @@ class SearchSongs extends React.Component {
}
};
makeLink = page => `/search/song?query=${this.state.query}&page=${page}`;
makeLink = page => `/search/song?query=${this.props.query}&page=${page}`;
handlePageChange = page => {
this.setState({songs: null, page: page})
@@ -173,7 +173,7 @@ class SearchDiscs extends React.Component {
}
};
makeLink = page => `/search/disc?query=${this.state.query}&page=${page}`;
makeLink = page => `/search/disc?query=${this.props.query}&page=${page}`;
handlePageChange = page => {
this.setState({discs: null, page: page})
@@ -253,7 +253,7 @@ class SearchArtists extends React.Component {
}
};
makeLink = page => `/search/artist?query=${this.state.query}&page=${page}`;
makeLink = page => `/search/artist?query=${this.props.query}&page=${page}`;
handlePageChange = page => {
this.setState({artists: null, page: page})
@@ -376,7 +376,9 @@ export class Search extends React.Component {
<Fragment>
<h1>Búsqueda</h1>
<SearchBar query={this.state.query} onQueryChanged={this.handleQueryChange} history={this.props.history}/>
{this.state.query &&
<SearchTabs query={this.state.query} onTabChanged={this.handleTabChange} onPageChange={this.handlePageChange} selected={this.state.who} page={this.state.page}/>
}
</Fragment>
);
}

View File

@@ -7,32 +7,27 @@ export default class SearchBar extends React.Component {
this.state = {
query: this.props.query ? this.props.query : ''
};
this.handleChange = this.handleChange.bind(this);
this.handleSubmit = this.handleSubmit.bind(this);
}
handleChange(event) {
handleChange = event => {
const query = event.target.value;
this.setState({query: query});
}
};
handleSubmit(event, who) {
if (event.key === 'Enter' || who === 'button') {
handleSubmit = (who) => (event) => {
const query = this.state.query;
const onQueryChanged = this.props.onQueryChanged;
if (!query) return;
this.props.history.push(`/search?query=${query}`)
if (event.key === 'Enter' || who === 'button') {
const onQueryChanged = this.props.onQueryChanged;
if (onQueryChanged) onQueryChanged(query)
}
}
};
render() {
return (
render = () => (
<div className='input-with-icon'>
<input className='full-width' value={this.state.query} onKeyUp={this.handleSubmit} onChange={this.handleChange}/>
<button onClick={(e) => this.handleSubmit(e, 'button')}><FaSearch/></button>
<input className='full-width' value={this.state.query} onKeyUp={this.handleSubmit('input')} onChange={this.handleChange}/>
<button onClick={this.handleSubmit('button')}><FaSearch/></button>
</div>
);
}
}

View File

@@ -10,12 +10,16 @@ import {Nav} from "./components/Nav";
import {BrowserRouter, Switch, Route} from "react-router-dom";
const Main = (props) => (
const Main = (props) => {
const navigate = (query) => props.history.push(`/search?query=${query}`);
return (
<Fragment>
<h1>Busca la musica que te gusta!</h1>
<SearchBar history={props.history}/>
<SearchBar history={props.history} onQueryChanged={navigate}/>
</Fragment>
)
}
const NoRoute = (props) => {
return (