Commit 2a362582 authored by CodeDuSoir's avatar CodeDuSoir
Browse files

add toobib 98, correct bug: searchresult appears only after two submit

parent 43cd3d77
......@@ -7,17 +7,34 @@ import error from './components/error';
const urlAPI = 'https://annuaire.interhop.org/providers?search='
const urlAPIToobib = 'https://annuaire.interhop.org/provider/'
export default class App extends Component {
state = {
'searchValue': 'Paris',
'lastSearchTitle': '',
'searchResult': '',
'page': '1'
'page': '1',
'toobibId': '3054146',
'toobibData': null,
'setToobibData': null,
'loading': false,
'setLoading':false
}
async toobibDataFetch() {
const response = await fetch(urlAPIToobib + this.state.toobibId, { header: {'Access-Control-Allow-Origin': '*'}})
const json = await response.json();
this.setState({ 'toobibData': json });
}
toobibDataFunction = () => e => {
this.toobibDataFetch();
}
async fetchData() {
const response = await fetch(urlAPI + this.state.lastSearchTitle + '&page=' + this.state.page + '&origin=*', { header: {'Access-Control-Allow-Origin': '*'}})
const response = await fetch(urlAPI + this.state.searchValue + '&page=' + this.state.page + '&origin=*', { header: {'Access-Control-Allow-Origin': '*'}})
const json = await response.json();
this.setState({ 'searchResult': json });
}
......@@ -48,8 +65,8 @@ export default class App extends Component {
return (
<Router>
<Switch>
<Route exact path="/" render={(props) => <Body {...props} searchResult={searchResult} page={page} handleIndentation={this.handleIndentation} lastSearchTitle={lastSearchTitle} searchResult={searchResult} fetchData={this.fetchData} handleChange={this.handleChange} searchValue={searchValue} searchFunction={this.searchFunction} /> } />
<Route path="/toobibPage/:Id" component={ToobibPage} />
<Route exact path="/" render={(props) => <Body {...props} fetchData={this.fetchData} searchResult={searchResult} page={page} toobibDataFunction={this.toobibDataFunction} handleIndentation={this.handleIndentation} lastSearchTitle={lastSearchTitle} searchResult={searchResult} handleChange={this.handleChange} searchValue={searchValue} searchFunction={this.searchFunction} /> } />
<Route path="/toobibPage/:Id" render={(props) => <ToobibPage {...props} toobibData={this.state.toobibData} /> } />
<Route exact path="/404" component={error} />
<Redirect to="/404" />
</Switch>
......
......@@ -5,7 +5,47 @@ export default class Pagination extends Component {
render() {
const { handleIndentation, page, searchResult } = this.props;
if(page === '1') {
/* if(!searchResult.providers[0]) {
return(
<nav aria-label="Pagination" className="columns is-centered">
<button value="-1" onClick={handleIndentation("page")} className="pagination-previous" disabled>
<span className="screen-reader-text">Page précédente</span>
<svg className="icon icon-arrow-left-mini" width="14" height="14" viewBox="-100.9 99.1 61.9 105.9">
<path d="M-98.2 158.8l43.5 43.5c1.7 1.7 4 2.7 6.5 2.7s4.8-1 6.5-2.7c1.7-1.7 2.7-4 2.7-6.5s-1-4.8-2.7-6.5l-37.2-37.2 37.2-37.2c1.7-1.7 2.7-4 2.7-6.5s-1-4.8-2.6-6.5c-1.8-1.9-4.2-2.8-6.6-2.8-2.3 0-4.6.9-6.5 2.6-11.5 11.4-41.2 41-43.3 43l-.2.2c-3.6 3.6-3.6 10.3 0 13.9z"></path>
</svg>
Précédente
</button>
<button value="1" onClick={handleIndentation("page")} className="pagination-next" disabled>
<span className="screen-reader-text">Page suivante</span>
Suivante
<svg width="14" height="14" viewBox="-100.9 99.1 61.9 105.9" className=" icon icon-arrow-right-mini">
<path d="M-41.7 145.3l-43.5-43.5c-1.7-1.7-4-2.7-6.5-2.7s-4.8 1-6.5 2.7c-1.7 1.7-2.7 4-2.7 6.5s1 4.8 2.7 6.5L-61 152l-37.2 37.2c-1.7 1.7-2.7 4-2.7 6.5s1 4.8 2.6 6.5c1.8 1.9 4.2 2.8 6.6 2.8 2.3 0 4.6-.9 6.5-2.6 11.5-11.4 41.2-41 43.3-43l.2-.2c3.6-3.6 3.6-10.4 0-13.9z"></path>
</svg>
</button>
</nav>
)
} else */ if(page === '1' && (!searchResult.providers || !searchResult.providers[0])) {
return(
<nav aria-label="Pagination" className="columns is-centered">
<button value="-1" onClick={handleIndentation("page")} className="pagination-previous" disabled>
<span className="screen-reader-text">Page précédente</span>
<svg className="icon icon-arrow-left-mini" width="14" height="14" viewBox="-100.9 99.1 61.9 105.9">
<path d="M-98.2 158.8l43.5 43.5c1.7 1.7 4 2.7 6.5 2.7s4.8-1 6.5-2.7c1.7-1.7 2.7-4 2.7-6.5s-1-4.8-2.7-6.5l-37.2-37.2 37.2-37.2c1.7-1.7 2.7-4 2.7-6.5s-1-4.8-2.6-6.5c-1.8-1.9-4.2-2.8-6.6-2.8-2.3 0-4.6.9-6.5 2.6-11.5 11.4-41.2 41-43.3 43l-.2.2c-3.6 3.6-3.6 10.3 0 13.9z"></path>
</svg>
Précédente
</button>
<button value="1" onClick={handleIndentation("page")} className="pagination-next" disabled>
<span className="screen-reader-text">Page suivante</span>
Suivante
<svg width="14" height="14" viewBox="-100.9 99.1 61.9 105.9" className=" icon icon-arrow-right-mini">
<path d="M-41.7 145.3l-43.5-43.5c-1.7-1.7-4-2.7-6.5-2.7s-4.8 1-6.5 2.7c-1.7 1.7-2.7 4-2.7 6.5s1 4.8 2.7 6.5L-61 152l-37.2 37.2c-1.7 1.7-2.7 4-2.7 6.5s1 4.8 2.6 6.5c1.8 1.9 4.2 2.8 6.6 2.8 2.3 0 4.6-.9 6.5-2.6 11.5-11.4 41.2-41 43.3-43l.2-.2c3.6-3.6 3.6-10.4 0-13.9z"></path>
</svg>
</button>
</nav>
)
} else if(page === '1') {
return(
<nav aria-label="Pagination" className="columns is-centered">
<button value="-1" onClick={handleIndentation("page")} className="pagination-previous" disabled>
......
......@@ -13,6 +13,13 @@ export default class ResultCards extends Component {
</React.Fragment>
)
}
else if(!searchResult.providers[0]) {
return(
<React.Fragment>
<h2>Il n'y a pas de résultat pour la recherche: "{lastSearchTitle}"</h2>
</React.Fragment>
)
}
else
{
......
......@@ -14,7 +14,7 @@ export default class SearchBar extends Component {
<input className="input" value={searchValue} onChange={handleChange('searchValue')} placeholder="search" name="q" type="text"/>
</div>
<div className="control">
<input type="submit" className="button is-link" onClick={searchFunction(fetchData)} value="Rechercher"></input>
<input type="submit" className="button is-link" onClick={searchFunction()} value="Rechercher"></input>
</div>
</div>
</form>
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment