This commit is contained in:
Kongzibapt 2021-02-05 14:28:32 +01:00
commit 6d41983135
2 changed files with 11 additions and 16 deletions

View file

@ -26,9 +26,9 @@ class Sort extends Component {
</select> </select>
</div> </div>
</div> </div>
<div id="sortOrder" onClick={this.props.handleChangeSortOrder} hidden={this.props.orderIsVisible}> <p id="sortOrder" onClick={this.props.handleChangeSortOrder} hidden={this.props.orderIsVisible}>
A-Z {this.props.lowToHigh ? "A-Z" : "Z-A"}
</div> </p>
</div> </div>
</div> </div>
); );

View file

@ -36,7 +36,7 @@ export default class Stock extends React.Component {
categorySorted:false, categorySorted:false,
onSortedCategories:false, onSortedCategories:false,
onSearch:false, onSearch:false,
sortOrder: 0, lowToHigh: true,
selectedArticles:[], selectedArticles:[],
counter:0, counter:0,
code:'' code:''
@ -69,7 +69,7 @@ export default class Stock extends React.Component {
let sorted; let sorted;
if (sortType === "name"){ if (sortType === "name"){
this.setState({orderIsVisible: false}) this.setState({orderIsVisible: false})
if (this.state.sortOrder === 0) { if (this.state.lowToHigh) {
//ordre alphabétique croissant //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 {
@ -78,7 +78,7 @@ export default class Stock extends React.Component {
} }
} else { } else {
this.setState({orderIsVisible: true}) this.setState({orderIsVisible: true})
this.setState({sortOrder: 0}) 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]);
} }
@ -167,15 +167,10 @@ 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 //Gère le choix de tri par ordre croissant ou décroissant quand c'est possible avec le tri actuel
handleChangeSortOrder = (e) => { handleChangeSortOrder = e => {
this.setState({sortOrder: (this.state.sortOrder + 1) % 2}); this.setState({lowToHigh: (this.state.lowToHigh + 1) % 2},() => {
console.log(this.state.sortOrder) this.sortArticles("name");
if (this.state.sortOrder === 1) { });
e.target.innerHTML = "Z-A"
} else {
e.target.innerHTML = "A-Z"
}
this.sortArticles("name");
} }
searchArticles = () => { searchArticles = () => {
@ -241,7 +236,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} handleChangeSortOrder={this.handleChangeSortOrder} orderIsVisible={this.state.orderIsVisible}/> <Sort handleChangeSortType={this.handleChangeSortType} handleChangeSortOrder={this.handleChangeSortOrder} orderIsVisible={this.state.orderIsVisible} lowToHigh={this.state.lowToHigh}/>
</div> </div>
<div id="selectedBlock"> <div id="selectedBlock">
<Selected counter={this.state.counter}/> <Selected counter={this.state.counter}/>