reza added sort and fillter

master
Reza_ashrafi 3 years ago
parent e2c5bb9eb8
commit 14aed3c7b3
  1. 33
      src/views/Products/BreadCrumb/index.js
  2. 35
      src/views/Products/Filters/AppliedFilters/index.js
  3. 9
      src/views/Products/Filters/AppliedFilters/index.scss
  4. 83
      src/views/Products/Filters/TypicalFilters/index.js
  5. 8
      src/views/Products/Filters/index.js
  6. 32
      src/views/Products/List/index.js
  7. 39
      src/views/Products/Sort/index.js
  8. 2
      src/views/Products/Sort/index.scss
  9. 12
      src/views/Products/index.js

@ -1,12 +1,12 @@
import React from 'react'; import React from "react";
import Breadcrumbs from '@material-ui/core/Breadcrumbs'; import Breadcrumbs from "@material-ui/core/Breadcrumbs";
import {Link} from 'react-router-dom'; import { Link } from "react-router-dom";
import './index.scss'; import "./index.scss";
function handleClick(event) { function handleClick(event) {
event.preventDefault(); event.preventDefault();
console.info('You clicked a breadcrumb.'); console.info("You clicked a breadcrumb.");
} }
const maxDesktopSize = 1250; const maxDesktopSize = 1250;
@ -14,19 +14,34 @@ const maxMobileSize = 650;
const fontSize = { const fontSize = {
desktop: window.innerWidth > maxDesktopSize ? 12 : window.innerWidth / 90, desktop: window.innerWidth > maxDesktopSize ? 12 : window.innerWidth / 90,
mobile : window.innerWidth > maxDesktopSize ? 14 : window.innerWidth / 25, mobile: window.innerWidth > maxDesktopSize ? 14 : window.innerWidth / 25,
}; };
export default function ActiveLastBreadcrumb() { export default function ActiveLastBreadcrumb() {
return ( return (
<Breadcrumbs aria-label="breadcrumb"> <Breadcrumbs aria-label="breadcrumb">
<Link style={{ fontSize: window.innerWidth > 1000 ? fontSize.desktop : fontSize.mobile}} to={'/'} onClick={handleClick}> <Link
to={""}
style={{
fontSize:
window.innerWidth > 1000 ? fontSize.desktop : fontSize.mobile,
}}
onClick={handleClick}
>
صفحه اصلی صفحه اصلی
</Link> </Link>
<Link style={{ fontSize: window.innerWidth > 1000 ? fontSize.desktop : fontSize.mobile, color: '#00CC69'}} to="/products" onClick={handleClick}> <Link
to={"/products"}
style={{
fontSize:
window.innerWidth > 1000 ? fontSize.desktop : fontSize.mobile,
color: "#00CC69",
}}
onClick={handleClick}
>
محصولات محصولات
</Link> </Link>
</Breadcrumbs> </Breadcrumbs>
); );
} }

@ -7,8 +7,26 @@ const maxDesktopSize = 1250;
const fontSize = { const fontSize = {
h2 : window.innerWidth > maxDesktopSize ? 13 : window.innerWidth / 85, h2 : window.innerWidth > maxDesktopSize ? 13 : window.innerWidth / 85,
button: window.innerWidth > maxDesktopSize ? 12 : window.innerWidth / 85,
} }
export default class AppliedFilters extends React.Component { export default class AppliedFilters extends React.Component {
delete = (name, data) => {
if (name === "subject") {
this.props.parent.setState((prevState) => ({
selectedFilters: {
...prevState.selectedFilters,
subject: prevState.selectedFilters.subject.filter(item => item !== data),
},
}));
}else if(name === "level"){
this.props.parent.setState((prevState) => ({
selectedFilters: {
...prevState.selectedFilters,
level: prevState.selectedFilters.level.filter(item => item !== data),
},
}));
}
};
render() { render() {
const {data} = this.props; const {data} = this.props;
return( return(
@ -19,8 +37,13 @@ export default class AppliedFilters extends React.Component {
</header> </header>
<div className="products-filters-applied__items d-flex flex-wrap"> <div className="products-filters-applied__items d-flex flex-wrap">
{ {
data.map((item,i) => ( data.level.map((item,i) => (
<Item data={item} key={i} /> <Item name={"level"} data={item} key={i} parent={this} />
))
}
{
data.subject.map((item,i) => (
<Item name={"subject"} data={item} key={i} parent={this} />
)) ))
} }
</div> </div>
@ -30,11 +53,11 @@ export default class AppliedFilters extends React.Component {
} }
const Item = (props) => { const Item = (props) => {
const {data} = props; const {data, name, parent} = props;
return( return(
<button className="d-flex align-items-center"> <button className="d-flex align-items-center" onClick={() => parent.delete(name, data)}>
<span>{data.name}</span> <span style={{ fontSize: fontSize.button }}>{data}</span>
<CloseIcon style={{ fontSize: 20 }} /> <CloseIcon style={{ fontSize: 12, marginRight: 10, borderRadius : '50%', border: '1px solid #b5b5b5' }} />
</button> </button>
); );
} }

@ -23,5 +23,14 @@
border-radius: 8px; border-radius: 8px;
min-height: 30px; min-height: 30px;
padding: 10px 5px; padding: 10px 5px;
button {
background-color: white;
border : 1px solid #d4d4d4;
border-radius: 7px;
margin: 3px 4px;
font-family: numeralLight;
color: #4d4d4d;
padding: 2px 7px;
}
} }
} }

@ -1,34 +1,55 @@
import React from 'react'; import React from "react";
import FormControlLabel from '@material-ui/core/FormControlLabel'; import FormControlLabel from "@material-ui/core/FormControlLabel";
import Checkbox from '@material-ui/core/Checkbox'; import Checkbox from "@material-ui/core/Checkbox";
import CheckBoxOutlineBlankIcon from '@material-ui/icons/CheckBoxOutlineBlank'; import CheckBoxOutlineBlankIcon from "@material-ui/icons/CheckBoxOutlineBlank";
import CheckBoxIcon from '@material-ui/icons/CheckBox'; import CheckBoxIcon from "@material-ui/icons/CheckBox";
import CloseIcon from '@material-ui/icons/Close'; import CloseIcon from "@material-ui/icons/Close";
import './index.scss'; import "./index.scss";
const maxDesktopSize = 1250; const maxDesktopSize = 1250;
const fontSize = { const fontSize = {
h2 : window.innerWidth > maxDesktopSize ? 13 : window.innerWidth / 85, h2: window.innerWidth > maxDesktopSize ? 13 : window.innerWidth / 85,
strong: window.innerWidth > maxDesktopSize ? 12 : window.innerWidth / 90, strong: window.innerWidth > maxDesktopSize ? 12 : window.innerWidth / 90,
} };
export default class TypicalFilters extends React.Component { export default class TypicalFilters extends React.Component {
onChange = (name, data) => {
if (name === "subject") {
this.props.parent.setState((prevState) => ({
selectedFilters: {
...prevState.selectedFilters,
subject:
prevState.selectedFilters.subject.indexOf(data) !== -1
? prevState.selectedFilters.subject.filter(item => item !== data)
: [...new Set([...prevState.selectedFilters.subject, data])],
},
}));
}else if(name === "level"){
this.props.parent.setState((prevState) => ({
selectedFilters: {
...prevState.selectedFilters,
level:
prevState.selectedFilters.level.indexOf(data) !== -1
? prevState.selectedFilters.level.filter(item => item !== data)
: [...new Set([...prevState.selectedFilters.level, data])],
},
}));
}
};
render() { render() {
const {data, title, theme} = this.props; const { data, title, theme, name, parent } = this.props;
return( return (
<div className="products-filters-typical d-flex flex-column"> <div className="products-filters-typical d-flex flex-column">
<header className="products-filters-typical__header d-flex align-items-center"> <header className="products-filters-typical__header d-flex align-items-center">
<span style={{ background : theme }}></span> <span style={{ background: theme }}></span>
<h2 style={{ fontSize : fontSize.h2 }}>{title}</h2> <h2 style={{ fontSize: fontSize.h2 }}>{title}</h2>
</header> </header>
<div className="products-filters-typical__items d-flex flex-column"> <div className="products-filters-typical__items d-flex flex-column">
{ {data.map((item, i) => (
data.map((item,i) => ( <Item data={item} key={i} parent={this} />
<Item data={item} key={i} /> ))}
))
}
</div> </div>
</div> </div>
); );
@ -36,14 +57,30 @@ export default class TypicalFilters extends React.Component {
} }
const Item = (props) => { const Item = (props) => {
const {data} = props; const { data, parent } = props;
return( const checkHandler = (data, name) => {
var available;
if(name === "subject"){
available = props.parent.props.parent.state.selectedFilters.subject.indexOf(data) !== -1 ? true : false;
}else if(name === "level"){
available = props.parent.props.parent.state.selectedFilters.level.indexOf(data) !== -1 ? true : false;
}
return available;
}
return (
<div className="d-flex align-items-center mt-2"> <div className="d-flex align-items-center mt-2">
<FormControlLabel <FormControlLabel
control={<Checkbox icon={<CheckBoxOutlineBlankIcon style={{ color: '#EAEAEA' }} />} checkedIcon={<CheckBoxIcon style={{ color: '#00CC69' }} />} name="checkedH" />} control={
label="" <Checkbox
icon={<CheckBoxOutlineBlankIcon style={{ color: "#EAEAEA" }} />}
checkedIcon={<CheckBoxIcon style={{ color: "#00CC69" }} />}
name="checkedH"
/>
}
checked={checkHandler(data,parent.props.name)}
onChange={() => parent.onChange(parent.props.name, data)}
/> />
<strong style={{ fontSize: fontSize.strong }}>{data}</strong> <strong style={{ fontSize: fontSize.strong }}>{data}</strong>
</div> </div>
); );
} };

@ -10,11 +10,11 @@ export default class Filtesrs extends React.Component {
return( return(
<div className="products-filters d-flex flex-column"> <div className="products-filters d-flex flex-column">
{ {
parent.state.selectedFilters.length !== 0 ? parent.state.selectedFilters.level.length !== 0 || parent.state.selectedFilters.subject.length !== 0 ?
<AppliedFiltesrs data={parent.state.selectedFilters} />: null <AppliedFiltesrs parent={parent} data={parent.state.selectedFilters} />: null
} }
<TypicalFilters data={parent.props.subjects} title="دسته بندی موضوعی" theme="#D7FF17" /> <TypicalFilters name ="subject" parent={parent} data={parent.props.subjects} title="دسته بندی موضوعی" theme="#D7FF17" />
<TypicalFilters data={parent.props.levels} title="پایه تحصیلی" theme="#FF8917" /> <TypicalFilters name="level" parent={parent} data={parent.props.levels} title="پایه تحصیلی" theme="#FF8917" />
</div> </div>
); );
} }

@ -1,18 +1,34 @@
import React from 'react'; import React from "react";
import Product from '../Product/index'; import Product from "../Product/index";
import './index.scss'; import "./index.scss";
export default class List extends React.Component { export default class List extends React.Component {
state = {
sortList: this.props.parent.props.products,
};
render() { render() {
const {parent} = this.props; const { parent } = this.props;
return( var sortList = parent.props.products;
if(parent.state.selectedSort === 'گران ترین') {
sortList = sortList.sort((a, b) => (a.price > b.price ? -1 : 1));
}else if(parent.state.selectedSort === 'ارزان ترین'){
sortList = sortList.sort((a, b) => (a.price < b.price && ( a.price !== '' || b.price !== '' ) ? -1 : 1));
}
var filterList;
for(let j = 0; j <= parent.state.selectedFilters.subject.length; j++) {
filterList = sortList.filter(item => parent.state.selectedFilters.subject.indexOf(item.title) === -1);
};
return (
<div className="products-list d-flex flex-wrap"> <div className="products-list d-flex flex-wrap">
{ {filterList.length > 0
parent.props.products.map((item,i) => ( ? filterList.map((item, i) => (
<Product product={item} key={i} /> <Product product={item} key={i} />
)) ))
} : null}
</div> </div>
); );
} }
} }

@ -1,28 +1,26 @@
import React from 'react'; import React from "react";
import SortIcon from '@material-ui/icons/Sort'; import SortIcon from "@material-ui/icons/Sort";
import './index.scss'; import "./index.scss";
const maxDesktopSize = 1250; const maxDesktopSize = 1250;
const fontSize = { const fontSize = {
span : window.innerWidth > maxDesktopSize ? 14 : window.innerWidth / 90, span: window.innerWidth > maxDesktopSize ? 14 : window.innerWidth / 90,
li: window.innerWidth > maxDesktopSize ? 13 : window.innerWidth / 95, li: window.innerWidth > maxDesktopSize ? 13 : window.innerWidth / 95,
} };
export default class Sort extends React.Component { export default class Sort extends React.Component {
render() { render() {
const {parent} = this.props; const { parent } = this.props;
return( return (
<div className="products-sort d-flex align-items-center"> <div className="products-sort d-flex align-items-center">
<SortIcon style={{ fontSize: 30, color : '#A5A5A5', marginLeft : 10}} /> <SortIcon style={{ fontSize: 30, color: "#A5A5A5", marginLeft: 10 }} />
<span style={{ fontSize: fontSize.span }}>مرتب سازی بر اساس</span> <span style={{ fontSize: fontSize.span }}>مرتب سازی بر اساس</span>
<ul className="d-flex justify-content-between align-items-center mr-2"> <ul className="d-flex justify-content-between align-items-center mr-2">
{ {parent.props.sortItems.map((item, i) => (
parent.props.sortItems.map((item, i) => ( <Item data={item} key={i} parent={parent} />
<Item data={item} key={i} /> ))}
))
}
</ul> </ul>
</div> </div>
); );
@ -30,7 +28,16 @@ export default class Sort extends React.Component {
} }
const Item = (props) => { const Item = (props) => {
return( return (
<li style={{ fontSize: fontSize.li }}>{props.data}</li> <li
style={{
fontSize: fontSize.li,
backgroundColor:
props.parent.state.selectedSort === props.data ? "#4CE1BE73" : "white",
}}
onClick={() => props.parent.setState({ selectedSort : props.data })}
>
{props.data}
</li>
); );
} };

@ -16,6 +16,8 @@
font-family: numeralLight; font-family: numeralLight;
color: #373737; color: #373737;
cursor: pointer; cursor: pointer;
padding: 5px 10px;
border-radius: 5px;
} }
} }
} }

@ -20,7 +20,11 @@ import book5 from "../../assets/images/book5.png";
import "./index.scss"; import "./index.scss";
export default class Products extends Component { export default class Products extends Component {
state = { state = {
selectedFilters : [], selectedSort : null,
selectedFilters : {
level : [],
subject : [],
},
firstFilters: [ firstFilters: [
{ id: 0, value: "محبوب ترین" }, { id: 0, value: "محبوب ترین" },
{ id: 1, value: "جدیدترین" }, { id: 1, value: "جدیدترین" },
@ -53,7 +57,7 @@ export default class Products extends Component {
<div className="products__body d-flex"> <div className="products__body d-flex">
<Filters parent={this} /> <Filters parent={this} />
<div className="products__body--left d-flex flex-column"> <div className="products__body--left d-flex flex-column">
<Sort parent={this} /> <Sort parent={this} selectedSort={this.state.selectedSort} />
<List parent={this} /> <List parent={this} />
</div> </div>
</div> </div>
@ -90,8 +94,8 @@ Products.defaultProps = {
sortItems : [ sortItems : [
'پربازدیدترین', 'پربازدیدترین',
'پرفروش ترین', 'پرفروش ترین',
'گرانترین', 'گران ترین',
'ارزانترین', 'ارزان ترین',
'جدیدترین', 'جدیدترین',
'بزودی', 'بزودی',
], ],

Loading…
Cancel
Save