From cdf43438ccf40af273d7d4efb8c76b707c8c3994 Mon Sep 17 00:00:00 2001 From: Flo E Date: Sat, 6 Feb 2021 11:07:46 +0100 Subject: [PATCH] =?UTF-8?q?choix=20d'ordre=20fonctionne=20pour=20tous=20le?= =?UTF-8?q?s=20tris=20qui=20en=20demandent,=20changement=20des=20value=20d?= =?UTF-8?q?ans=20les=20options=20=C3=A0=20valider?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/js/Components/Sort.js | 8 ++++---- src/js/Views/Stock.js | 36 ++++++++++++++++++++++-------------- 2 files changed, 26 insertions(+), 18 deletions(-) diff --git a/src/js/Components/Sort.js b/src/js/Components/Sort.js index 38c2d2d..54d20be 100644 --- a/src/js/Components/Sort.js +++ b/src/js/Components/Sort.js @@ -20,10 +20,10 @@ class Sort extends Component {
diff --git a/src/js/Views/Stock.js b/src/js/Views/Stock.js index 699d758..195102d 100644 --- a/src/js/Views/Stock.js +++ b/src/js/Views/Stock.js @@ -68,7 +68,7 @@ export default class Stock extends React.Component { let sorted; //TRI PAR ORDRE ALPHABETIQUE OU PRIX if (sortType === "name"){ - this.setState({orderIsHidden: false}) + this.setState({orderIsHidden: false}) //choix d'ordre possible if (this.state.lowToHigh) { //ordre alphabétique croissant sorted = [...this.state.articles].sort((a, b) => a.name.localeCompare(b.name)) @@ -78,7 +78,7 @@ export default class Stock extends React.Component { } } else if (sortType === "price") { console.log('tri pix') - this.setState({orderIsHidden: false}) + this.setState({orderIsHidden: false}) //choix d'ordre possible if (this.state.lowToHigh) { //ordre croissant sorted = [...this.state.articles].sort((a, b) => a.price - b.price) @@ -167,26 +167,34 @@ export default class Stock extends React.Component { this.setState({onEditCategory:false}) } + // handleChangeSortType = (e) => { + // console.log(e.target.value) + // this.setState({sortType:e.target.value},()=>{ + // if (this.state.sortType === "Ordre Alphabétique"){ + // this.sortArticles("name") + // } else if(this.state.sortType === "Catégorie"){ + // this.sortArticles("category_id") + // } else if(this.state.sortType === "Quantité"){ + // this.sortArticles("quantity") + // } else if(this.state.sortType === "Prix"){ + // this.sortArticles("price"); + // } + + // }) + // } + handleChangeSortType = (e) => { console.log(e.target.value) - this.setState({sortType:e.target.value},()=>{ - if (this.state.sortType === "Ordre Alphabétique"){ - this.sortArticles("name") - } else if(this.state.sortType === "Catégorie"){ - this.sortArticles("category_id") - } else if(this.state.sortType === "Quantité"){ - this.sortArticles("quantity") - } else if(this.state.sortType === "Prix"){ - this.sortArticles("price"); - } - + this.setState({sortType: e.target.value}, () => { + this.sortArticles(this.state.sortType) }) } //Gère le choix de tri par ordre croissant ou décroissant quand c'est possible avec le tri actuel handleChangeSortOrder = e => { this.setState({lowToHigh: (this.state.lowToHigh + 1) % 2},() => { - this.sortArticles("name"); + console.log(this.state.sortType) + this.sortArticles(this.state.sortType); }); }