Premiere version du tri alphabétique ordre croissant/décroissant
This commit is contained in:
parent
98c5bd6d81
commit
b934e694de
3 changed files with 99 additions and 60 deletions
|
|
@ -2,7 +2,7 @@
|
||||||
display:flex;
|
display:flex;
|
||||||
flex:1;
|
flex:1;
|
||||||
justify-content: center;
|
justify-content: center;
|
||||||
align-items: center;
|
align-items: flex-start;
|
||||||
}
|
}
|
||||||
|
|
||||||
#sortTxt{
|
#sortTxt{
|
||||||
|
|
@ -12,6 +12,19 @@
|
||||||
margin-right:1vw;
|
margin-right:1vw;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#selectAndOrder{
|
||||||
|
display: flex;
|
||||||
|
flex-direction: column;
|
||||||
|
align-items: center;
|
||||||
|
}
|
||||||
|
|
||||||
|
#sortOrder{
|
||||||
|
color: white;
|
||||||
|
font-family:'Wellfleet',cursive;
|
||||||
|
font-size: 1.2vw;
|
||||||
|
cursor: pointer;
|
||||||
|
}
|
||||||
|
|
||||||
#selectBlock{
|
#selectBlock{
|
||||||
background:#057B26;
|
background:#057B26;
|
||||||
margin-left:1vw;
|
margin-left:1vw;
|
||||||
|
|
|
||||||
|
|
@ -16,6 +16,7 @@ class Sort extends Component {
|
||||||
<div id="sortTxt">
|
<div id="sortTxt">
|
||||||
Trier par
|
Trier par
|
||||||
</div>
|
</div>
|
||||||
|
<div id="selectAndOrder">
|
||||||
<div id="selectBlock">
|
<div id="selectBlock">
|
||||||
<div id="selectBox">
|
<div id="selectBox">
|
||||||
<select id="sortSelect" onChange={this.props.handleChangeSortType}>
|
<select id="sortSelect" onChange={this.props.handleChangeSortType}>
|
||||||
|
|
@ -25,6 +26,10 @@ class Sort extends Component {
|
||||||
</select>
|
</select>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
<div id="sortOrder" onClick={this.props.handleChangeSortOrder} hidden={this.props.orderIsVisible}>
|
||||||
|
A-Z
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -34,7 +34,8 @@ export default class Stock extends React.Component {
|
||||||
categorySorted:false,
|
categorySorted:false,
|
||||||
dividedArticles:[],
|
dividedArticles:[],
|
||||||
onSortedCategories:false,
|
onSortedCategories:false,
|
||||||
onSearch:false
|
onSearch:false,
|
||||||
|
sortOrder: 0
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -45,11 +46,19 @@ export default class Stock extends React.Component {
|
||||||
|
|
||||||
// Implémenter la fonction sortArticles :
|
// Implémenter la fonction sortArticles :
|
||||||
sortArticles = (sortType) => {
|
sortArticles = (sortType) => {
|
||||||
|
|
||||||
let sorted;
|
let sorted;
|
||||||
if (sortType === "name"){
|
if (sortType === "name"){
|
||||||
|
this.setState({orderIsVisible: false})
|
||||||
|
if (this.state.sortOrder === 0) {
|
||||||
|
//ordre alphabétique croissant
|
||||||
sorted = [...this.state.articles].sort((a, b) => a.name.localeCompare(b.name))
|
sorted = [...this.state.articles].sort((a, b) => a.name.localeCompare(b.name))
|
||||||
} else {
|
} else {
|
||||||
|
//ordre alphabétique décroissant
|
||||||
|
sorted = [...this.state.articles].sort((a, b) => b.name.localeCompare(a.name))
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
this.setState({orderIsVisible: true})
|
||||||
|
this.setState({sortOrder: 0})
|
||||||
sorted = [...this.state.articles].sort((a, b) => b[sortType] - a[sortType]);
|
sorted = [...this.state.articles].sort((a, b) => b[sortType] - a[sortType]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -127,7 +136,7 @@ export default class Stock extends React.Component {
|
||||||
this.setState({onEditCategory:false})
|
this.setState({onEditCategory:false})
|
||||||
}
|
}
|
||||||
|
|
||||||
handleChangeSortType = e => {
|
handleChangeSortType = (e) => {
|
||||||
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")
|
||||||
|
|
@ -140,6 +149,18 @@ export default class Stock extends React.Component {
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//Gère le choix de tri par ordre croissant ou décroissant quand c'est possible avec le tri actuel
|
||||||
|
handleChangeSortOrder = (e) => {
|
||||||
|
this.setState({sortOrder: (this.state.sortOrder + 1) % 2});
|
||||||
|
console.log(this.state.sortOrder)
|
||||||
|
if (this.state.sortOrder === 1) {
|
||||||
|
e.target.innerHTML = "Z-A"
|
||||||
|
} else {
|
||||||
|
e.target.innerHTML = "A-Z"
|
||||||
|
}
|
||||||
|
this.sortArticles("name");
|
||||||
|
}
|
||||||
|
|
||||||
searchArticles = () => {
|
searchArticles = () => {
|
||||||
this.setState({onSearch:true})
|
this.setState({onSearch:true})
|
||||||
let bodyFormData = new FormData()
|
let bodyFormData = new FormData()
|
||||||
|
|
@ -184,7 +205,7 @@ export default class Stock extends React.Component {
|
||||||
: null}
|
: null}
|
||||||
<SearchBar handleSubmit={this.handleSubmit} handleSearchChange={this.handleSearchChange}/>
|
<SearchBar handleSubmit={this.handleSubmit} handleSearchChange={this.handleSearchChange}/>
|
||||||
<div id="sortBlock">
|
<div id="sortBlock">
|
||||||
<Sort handleChangeSortType={this.handleChangeSortType}/>
|
<Sort handleChangeSortType={this.handleChangeSortType} handleChangeSortOrder={this.handleChangeSortOrder} orderIsVisible={this.state.orderIsVisible}/>
|
||||||
</div>
|
</div>
|
||||||
<div id="articleBlock">
|
<div id="articleBlock">
|
||||||
{this.state.articles && this.state.articles[0] ?
|
{this.state.articles && this.state.articles[0] ?
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue