From c684a6a388ccd4499abbc3de6a5916010b0b2ec5 Mon Sep 17 00:00:00 2001 From: Kongzibapt <53861741+Kongzibapt@users.noreply.github.com> Date: Mon, 15 Feb 2021 00:06:13 +0100 Subject: [PATCH] pb Arrow Sort + Categorie Sort ok --- src/js/Components/ArticlesByCategory.js | 41 ++++++++----------------- src/js/Components/Sort.js | 2 +- src/js/Views/Stock.js | 38 +++++++++++++++++++++-- 3 files changed, 49 insertions(+), 32 deletions(-) diff --git a/src/js/Components/ArticlesByCategory.js b/src/js/Components/ArticlesByCategory.js index a18ca66..7e0fdec 100644 --- a/src/js/Components/ArticlesByCategory.js +++ b/src/js/Components/ArticlesByCategory.js @@ -6,51 +6,36 @@ class ArticlesByCategory extends React.Component { constructor(props){ super(props) this.state = { - articles:this.props.articles } } componentDidMount(){ - this.splitArticlesCategories() - } - - componentDidUpdate(){ - console.log(this.state.articles); - - } - - splitArticlesCategories = () => { - let counterTab = 0; - let divided = []; - divided.push([this.state.articles[0]]) - for (let i = 1; i{ - console.log(this.state.articles) - }) - - } + } + + render() { - console.log(this.state.articles) return (
- {this.state.articles[0][0] && - this.state.articles.map((divided) => + {this.props.articles[0][0] && + this.props.articles.map((divided) =>

{divided[0].category.name}

{divided.map((article) => - + )}
diff --git a/src/js/Components/Sort.js b/src/js/Components/Sort.js index bb8cd3f..164306d 100644 --- a/src/js/Components/Sort.js +++ b/src/js/Components/Sort.js @@ -93,7 +93,7 @@ class Sort extends Component {
- diff --git a/src/js/Views/Stock.js b/src/js/Views/Stock.js index 8044a7f..f20513c 100644 --- a/src/js/Views/Stock.js +++ b/src/js/Views/Stock.js @@ -39,7 +39,7 @@ export default class Stock extends React.Component { selectedArticles:[], counter:0, code:'', - + dividedArticles:[] } } @@ -297,6 +297,7 @@ updateArticle = (index,id) => { //TRI PAR CATEGORIE if (sortType === 'category_id'){ this.setState({articles:sorted},() => { + this.splitArticlesCategories() this.setState({onSortedCategories:true}) }) }else{ @@ -393,7 +394,9 @@ updateArticle = (index,id) => { axios.post('https://etud.insa-toulouse.fr/~proximo/v2/api/articles',bodyFormData) .then(res => { this.setState({articles : res.data}, () => { - console.log(this.state.articles) + if (this.state.sortType === "category_id"){ + this.splitArticlesCategories() + } }) }) .catch(error => { @@ -401,6 +404,35 @@ updateArticle = (index,id) => { }) } + splitArticlesCategories = () => { + let counterTab = 0; + let divided = []; + divided.push([this.state.articles[0]]) + for (let i = 1; i{ + this.getElementandColor() + }) + + } + + getElementandColor () { + let articles = document.getElementById("articles") + for (let i = 0; i { this.setState({search : event.target.value},()=> { @@ -451,7 +483,7 @@ updateArticle = (index,id) => {
{this.state.articles && this.state.articles[0] ? this.state.onSortedCategories ? - + : : }