Mise en forme tri categorie
This commit is contained in:
parent
3756e90ee5
commit
98c5bd6d81
4 changed files with 46 additions and 12 deletions
21
src/css/Components/articlesbycategory.css
Normal file
21
src/css/Components/articlesbycategory.css
Normal file
|
@ -0,0 +1,21 @@
|
||||||
|
#categoryName{
|
||||||
|
color : white;
|
||||||
|
text-align: left;
|
||||||
|
font-family: 'Wellfleet', cursive;
|
||||||
|
font-size:max(2.5vw,30px);
|
||||||
|
}
|
||||||
|
|
||||||
|
#categoryBlock{
|
||||||
|
width:60vw;
|
||||||
|
margin-bottom:5vh;
|
||||||
|
}
|
||||||
|
|
||||||
|
#bulles{
|
||||||
|
display:flex;
|
||||||
|
}
|
||||||
|
|
||||||
|
#underlinment{
|
||||||
|
background-color: white;
|
||||||
|
width:30%;
|
||||||
|
height:0.3vh;
|
||||||
|
}
|
|
@ -1,5 +1,5 @@
|
||||||
import React from 'react';
|
import React from 'react';
|
||||||
import '../../css/Components/articles.css'
|
import '../../css/Components/articlesbycategory.css'
|
||||||
import ArticleDetails from './ArticleDetails'
|
import ArticleDetails from './ArticleDetails'
|
||||||
|
|
||||||
class ArticlesByCategory extends React.Component {
|
class ArticlesByCategory extends React.Component {
|
||||||
|
@ -12,10 +12,16 @@ class ArticlesByCategory extends React.Component {
|
||||||
}
|
}
|
||||||
|
|
||||||
componentDidMount(){
|
componentDidMount(){
|
||||||
console.log(this.props.articles)
|
|
||||||
this.splitArticlesCategories()
|
this.splitArticlesCategories()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
componentDidUpdate(){
|
||||||
|
|
||||||
|
if (this.props.onSearch){
|
||||||
|
// implémenter une fonction de recherche en React sur articles
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
splitArticlesCategories = () => {
|
splitArticlesCategories = () => {
|
||||||
let counterTab = 0;
|
let counterTab = 0;
|
||||||
let divided = [];
|
let divided = [];
|
||||||
|
@ -36,17 +42,21 @@ class ArticlesByCategory extends React.Component {
|
||||||
|
|
||||||
|
|
||||||
render() {
|
render() {
|
||||||
|
console.log(this.state.articles)
|
||||||
return (
|
return (
|
||||||
<div id="articleContainer">
|
<div id="articleContainer">
|
||||||
<div id="articles">
|
<div id="articles">
|
||||||
{this.state.articles[0][0] &&
|
{this.state.articles[0][0] &&
|
||||||
this.state.articles.map((divided) =>
|
this.state.articles.map((divided) =>
|
||||||
<>
|
<div id="categoryBlock">
|
||||||
<p>{divided[0].category.name}</p>
|
<p id="categoryName">{divided[0].category.name}</p>
|
||||||
{divided.map((article) =>
|
<div id="underlinment"></div>
|
||||||
<ArticleDetails handleCategories={this.props.handleCategories} editArticle={this.props.editionArticle} key={article.id} id={article.id} name={article.name} img={article.image} desc={article.description} price={article.price} quantity={article.quantity} code={article.code} category={article.category}/>
|
<div id="bulles">
|
||||||
)}
|
{divided.map((article) =>
|
||||||
</>
|
<ArticleDetails handleCategories={this.props.handleCategories} editArticle={this.props.editionArticle} key={article.id} id={article.id} name={article.name} img={article.image} desc={article.description} price={article.price} quantity={article.quantity} code={article.code} category={article.category}/>
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
</div>
|
</div>
|
||||||
|
|
|
@ -19,7 +19,6 @@ class Sort extends Component {
|
||||||
<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}>
|
||||||
<option className="optionSort" value="Id"></option>
|
|
||||||
<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>
|
||||||
|
|
|
@ -33,12 +33,14 @@ export default class Stock extends React.Component {
|
||||||
categoryToModify:'',
|
categoryToModify:'',
|
||||||
categorySorted:false,
|
categorySorted:false,
|
||||||
dividedArticles:[],
|
dividedArticles:[],
|
||||||
onSortedCategories:false
|
onSortedCategories:false,
|
||||||
|
onSearch:false
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
componentDidMount() {
|
componentDidMount() {
|
||||||
this.getArticles()
|
this.getArticles()
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Implémenter la fonction sortArticles :
|
// Implémenter la fonction sortArticles :
|
||||||
|
@ -58,7 +60,7 @@ export default class Stock extends React.Component {
|
||||||
}else{
|
}else{
|
||||||
this.setState({articles:sorted},() => {
|
this.setState({articles:sorted},() => {
|
||||||
console.log(this.state.articles)
|
console.log(this.state.articles)
|
||||||
|
this.setState({onSortedCategories:false})
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -71,6 +73,7 @@ export default class Stock extends React.Component {
|
||||||
.then(res => {
|
.then(res => {
|
||||||
this.setState({articles : res.data}, () => {
|
this.setState({articles : res.data}, () => {
|
||||||
console.log(this.state.articles)
|
console.log(this.state.articles)
|
||||||
|
this.sortArticles("name")
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
.catch(error => {
|
.catch(error => {
|
||||||
|
@ -138,6 +141,7 @@ export default class Stock extends React.Component {
|
||||||
}
|
}
|
||||||
|
|
||||||
searchArticles = () => {
|
searchArticles = () => {
|
||||||
|
this.setState({onSearch:true})
|
||||||
let bodyFormData = new FormData()
|
let bodyFormData = new FormData()
|
||||||
bodyFormData.set('search',this.state.search)
|
bodyFormData.set('search',this.state.search)
|
||||||
axios.post('https://etud.insa-toulouse.fr/~proximo/v2/api/articles',bodyFormData)
|
axios.post('https://etud.insa-toulouse.fr/~proximo/v2/api/articles',bodyFormData)
|
||||||
|
@ -185,7 +189,7 @@ export default class Stock extends React.Component {
|
||||||
<div id="articleBlock">
|
<div id="articleBlock">
|
||||||
{this.state.articles && this.state.articles[0] ?
|
{this.state.articles && this.state.articles[0] ?
|
||||||
this.state.onSortedCategories ?
|
this.state.onSortedCategories ?
|
||||||
<ArticlesByCategory handleCategories={this.handleCategories} articles={this.state.articles} editionArticle={this.handleArticleEdition}/>
|
<ArticlesByCategory onSearch={this.state.onSearch} handleCategories={this.handleCategories} articles={this.state.articles} editionArticle={this.handleArticleEdition}/>
|
||||||
: <Articles handleCategories={this.handleCategories} articles={this.state.articles} editionArticle={this.handleArticleEdition}/>
|
: <Articles handleCategories={this.handleCategories} articles={this.state.articles} editionArticle={this.handleArticleEdition}/>
|
||||||
: <AppLoader/>
|
: <AppLoader/>
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue