From cbb2ef80bb977ca1a7ce441321d96a151add6c9a Mon Sep 17 00:00:00 2001 From: Flo E Date: Wed, 3 Feb 2021 16:39:00 +0100 Subject: [PATCH] corrections apres merge --- src/js/Views/Stock.js | 79 ++++++++++++++++++++++--------------------- 1 file changed, 40 insertions(+), 39 deletions(-) diff --git a/src/js/Views/Stock.js b/src/js/Views/Stock.js index 0f30bd3..4e1e5c6 100644 --- a/src/js/Views/Stock.js +++ b/src/js/Views/Stock.js @@ -42,38 +42,38 @@ export default class Stock extends React.Component { componentDidMount() { this.getArticles() -} + } -// Implémenter la fonction sortArticles : -sortArticles = (sortType) => { - - let sorted; - 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)) + // Implémenter la fonction sortArticles : + sortArticles = (sortType) => { + + let sorted; + 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)) + } else { + //ordre alphabétique décroissant + sorted = [...this.state.articles].sort((a, b) => b.name.localeCompare(a.name)) + } } else { - //ordre alphabétique décroissant - sorted = [...this.state.articles].sort((a, b) => b.name.localeCompare(a.name)) + this.setState({orderIsVisible: true}) + this.setState({sortOrder: 0}) + sorted = [...this.state.articles].sort((a, b) => b[sortType] - a[sortType]); } - } else { - this.setState({orderIsVisible: true}) - this.setState({sortOrder: 0}) - sorted = [...this.state.articles].sort((a, b) => b[sortType] - a[sortType]); - } - if (sortType === 'category_id'){ + if (sortType === 'category_id'){ + this.setState({articles:sorted},() => { + this.setState({onSortedCategories:true}) + }) + }else{ this.setState({articles:sorted},() => { - this.setState({onSortedCategories:true}) + console.log(this.state.articles) + this.setState({onSortedCategories:false}) }) - }else{ - this.setState({articles:sorted},() => { - console.log(this.state.articles) - this.setState({onSortedCategories:false}) - }) + } } -} getArticles = () => { axios.get('https://etud.insa-toulouse.fr/~proximo/v2/api/articles') @@ -188,23 +188,24 @@ sortArticles = (sortType) => { closeWithEscape = (e) => { if (e.keyCode === 27){ - if (this.state.onEditArticle){ - this.handleCloseEditArticle() - } else if(this.state.onNewArticle){ - this.handleCloseNewArticle() - } else if(this.state.onNewCategory){ - this.handleCloseNewCategory() - } else if(this.state.onEditCategory){ - this.handleCloseEditCategory() - } else if(this.state.onCategories){ - this.handleCloseCategories() + if (this.state.onEditArticle){ + this.handleCloseEditArticle() + } else if(this.state.onNewArticle){ + this.handleCloseNewArticle() + } else if(this.state.onNewCategory){ + this.handleCloseNewCategory() + } else if(this.state.onEditCategory){ + this.handleCloseEditCategory() + } else if(this.state.onCategories){ + this.handleCloseCategories() + } } } - render() { - if (!sessionStorage.getItem('token')){ - return (
ERREUR

Vous n'êtes pas connecté

Retourner à l'Accueil
) - } else { + render() { + if (!sessionStorage.getItem('token')){ + return (
ERREUR

Vous n'êtes pas connecté

Retourner à l'Accueil
) + } else { return (