Les tris ordre croissant/decroissant fonctionnent indépendamment, il faut rendre ça generique
This commit is contained in:
parent
4f47f96b4c
commit
1de84726e0
2 changed files with 16 additions and 7 deletions
|
@ -23,7 +23,7 @@ class Sort extends Component {
|
||||||
<option className="optionSort" value="Ordre Alphabétique">Ordre Alphabétique</option>
|
<option className="optionSort" value="Ordre Alphabétique">Ordre Alphabétique</option>
|
||||||
<option className="optionSort" value="Catégorie">Catégorie</option>
|
<option className="optionSort" value="Catégorie">Catégorie</option>
|
||||||
<option className="optionSort" value="Quantité">Quantité</option>
|
<option className="optionSort" value="Quantité">Quantité</option>
|
||||||
<option className="optionSort" value="Quantité">Prix</option>
|
<option className="optionSort" value="Prix">Prix</option>
|
||||||
</select>
|
</select>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
|
@ -66,7 +66,7 @@ export default class Stock extends React.Component {
|
||||||
sortArticles = (sortType) => {
|
sortArticles = (sortType) => {
|
||||||
|
|
||||||
let sorted;
|
let sorted;
|
||||||
//TRI PAR ORDRE ALPHABETIQUE
|
//TRI PAR ORDRE ALPHABETIQUE OU PRIX
|
||||||
if (sortType === "name"){
|
if (sortType === "name"){
|
||||||
this.setState({orderIsHidden: false})
|
this.setState({orderIsHidden: false})
|
||||||
if (this.state.lowToHigh) {
|
if (this.state.lowToHigh) {
|
||||||
|
@ -76,7 +76,19 @@ export default class Stock extends React.Component {
|
||||||
//ordre alphabétique décroissant
|
//ordre alphabétique décroissant
|
||||||
sorted = [...this.state.articles].sort((a, b) => b.name.localeCompare(a.name))
|
sorted = [...this.state.articles].sort((a, b) => b.name.localeCompare(a.name))
|
||||||
}
|
}
|
||||||
|
} else if (sortType === "price") {
|
||||||
|
console.log('tri pix')
|
||||||
|
this.setState({orderIsHidden: false})
|
||||||
|
if (this.state.lowToHigh) {
|
||||||
|
//ordre croissant
|
||||||
|
sorted = [...this.state.articles].sort((a, b) => a.price - b.price)
|
||||||
|
} else {
|
||||||
|
//ordre décroissant
|
||||||
|
sorted = [...this.state.articles].sort((a, b) => b.price - a.price)
|
||||||
|
}
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
|
console.log('autre 1')
|
||||||
this.setState({orderIsHidden: true})
|
this.setState({orderIsHidden: true})
|
||||||
this.setState({lowToHigh: false})
|
this.setState({lowToHigh: false})
|
||||||
sorted = [...this.state.articles].sort((a, b) => b[sortType] - a[sortType]);
|
sorted = [...this.state.articles].sort((a, b) => b[sortType] - a[sortType]);
|
||||||
|
@ -88,16 +100,12 @@ export default class Stock extends React.Component {
|
||||||
this.setState({onSortedCategories:true})
|
this.setState({onSortedCategories:true})
|
||||||
})
|
})
|
||||||
}else{
|
}else{
|
||||||
|
console.log('autre 2')
|
||||||
this.setState({articles:sorted},() => {
|
this.setState({articles:sorted},() => {
|
||||||
console.log(this.state.articles)
|
console.log(this.state.articles)
|
||||||
this.setState({onSortedCategories:false})
|
this.setState({onSortedCategories:false})
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
//TRI PAR PRIX
|
|
||||||
if (sortType === 'price') {
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
getArticles = () => {
|
getArticles = () => {
|
||||||
|
@ -160,6 +168,7 @@ export default class Stock extends React.Component {
|
||||||
}
|
}
|
||||||
|
|
||||||
handleChangeSortType = (e) => {
|
handleChangeSortType = (e) => {
|
||||||
|
console.log(e.target.value)
|
||||||
this.setState({sortType:e.target.value},()=>{
|
this.setState({sortType:e.target.value},()=>{
|
||||||
if (this.state.sortType === "Ordre Alphabétique"){
|
if (this.state.sortType === "Ordre Alphabétique"){
|
||||||
this.sortArticles("name")
|
this.sortArticles("name")
|
||||||
|
|
Loading…
Reference in a new issue