diff --git a/src/views/Products/BreadCrumb/index.js b/src/views/Products/BreadCrumb/index.js index 94cd4c7..8575f2f 100644 --- a/src/views/Products/BreadCrumb/index.js +++ b/src/views/Products/BreadCrumb/index.js @@ -1,12 +1,12 @@ -import React from 'react'; -import Breadcrumbs from '@material-ui/core/Breadcrumbs'; -import {Link} from 'react-router-dom'; +import React from "react"; +import Breadcrumbs from "@material-ui/core/Breadcrumbs"; +import { Link } from "react-router-dom"; -import './index.scss'; +import "./index.scss"; function handleClick(event) { event.preventDefault(); - console.info('You clicked a breadcrumb.'); + console.info("You clicked a breadcrumb."); } const maxDesktopSize = 1250; @@ -14,19 +14,34 @@ const maxMobileSize = 650; const fontSize = { 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() { return ( - 1000 ? fontSize.desktop : fontSize.mobile}} to={'/'} onClick={handleClick}> - صفحه اصلی + 1000 ? fontSize.desktop : fontSize.mobile, + }} + onClick={handleClick} + > + صفحه اصلی - 1000 ? fontSize.desktop : fontSize.mobile, color: '#00CC69'}} to="/products" onClick={handleClick}> + 1000 ? fontSize.desktop : fontSize.mobile, + color: "#00CC69", + }} + + onClick={handleClick} + > محصولات ); } - diff --git a/src/views/Products/Filters/AppliedFilters/index.js b/src/views/Products/Filters/AppliedFilters/index.js index 2c65a73..8787a15 100644 --- a/src/views/Products/Filters/AppliedFilters/index.js +++ b/src/views/Products/Filters/AppliedFilters/index.js @@ -7,8 +7,26 @@ const maxDesktopSize = 1250; const fontSize = { h2 : window.innerWidth > maxDesktopSize ? 13 : window.innerWidth / 85, + button: window.innerWidth > maxDesktopSize ? 12 : window.innerWidth / 85, } 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() { const {data} = this.props; return( @@ -19,8 +37,13 @@ export default class AppliedFilters extends React.Component {
{ - data.map((item,i) => ( - + data.level.map((item,i) => ( + + )) + } + { + data.subject.map((item,i) => ( + )) }
@@ -30,11 +53,11 @@ export default class AppliedFilters extends React.Component { } const Item = (props) => { - const {data} = props; + const {data, name, parent} = props; return( - ); } \ No newline at end of file diff --git a/src/views/Products/Filters/AppliedFilters/index.scss b/src/views/Products/Filters/AppliedFilters/index.scss index c34368b..fa84878 100644 --- a/src/views/Products/Filters/AppliedFilters/index.scss +++ b/src/views/Products/Filters/AppliedFilters/index.scss @@ -23,5 +23,14 @@ border-radius: 8px; min-height: 30px; 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; + } } } diff --git a/src/views/Products/Filters/TypicalFilters/index.js b/src/views/Products/Filters/TypicalFilters/index.js index 08f2a2b..957013d 100644 --- a/src/views/Products/Filters/TypicalFilters/index.js +++ b/src/views/Products/Filters/TypicalFilters/index.js @@ -1,34 +1,55 @@ -import React from 'react'; -import FormControlLabel from '@material-ui/core/FormControlLabel'; -import Checkbox from '@material-ui/core/Checkbox'; +import React from "react"; +import FormControlLabel from "@material-ui/core/FormControlLabel"; +import Checkbox from "@material-ui/core/Checkbox"; -import CheckBoxOutlineBlankIcon from '@material-ui/icons/CheckBoxOutlineBlank'; -import CheckBoxIcon from '@material-ui/icons/CheckBox'; -import CloseIcon from '@material-ui/icons/Close'; +import CheckBoxOutlineBlankIcon from "@material-ui/icons/CheckBoxOutlineBlank"; +import CheckBoxIcon from "@material-ui/icons/CheckBox"; +import CloseIcon from "@material-ui/icons/Close"; -import './index.scss'; +import "./index.scss"; const maxDesktopSize = 1250; 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, -} +}; 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() { - const {data, title, theme} = this.props; - return( + const { data, title, theme, name, parent } = this.props; + return (
- -

{title}

+ +

{title}

- { - data.map((item,i) => ( - - )) - } + {data.map((item, i) => ( + + ))}
); @@ -36,14 +57,30 @@ export default class TypicalFilters extends React.Component { } const Item = (props) => { - const {data} = props; - return( + const { data, parent } = props; + 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 (
} checkedIcon={} name="checkedH" />} - label="" + control={ + } + checkedIcon={} + name="checkedH" + /> + } + checked={checkHandler(data,parent.props.name)} + onChange={() => parent.onChange(parent.props.name, data)} /> {data}
); -} \ No newline at end of file +}; diff --git a/src/views/Products/Filters/index.js b/src/views/Products/Filters/index.js index 102b859..f57428a 100644 --- a/src/views/Products/Filters/index.js +++ b/src/views/Products/Filters/index.js @@ -10,11 +10,11 @@ export default class Filtesrs extends React.Component { return(
{ - parent.state.selectedFilters.length !== 0 ? - : null + parent.state.selectedFilters.level.length !== 0 || parent.state.selectedFilters.subject.length !== 0 ? + : null } - - + +
); } diff --git a/src/views/Products/List/index.js b/src/views/Products/List/index.js index 6d7cc7d..f96a3c9 100644 --- a/src/views/Products/List/index.js +++ b/src/views/Products/List/index.js @@ -1,18 +1,34 @@ -import React from 'react'; -import Product from '../Product/index'; +import React from "react"; +import Product from "../Product/index"; -import './index.scss'; +import "./index.scss"; export default class List extends React.Component { + state = { + sortList: this.props.parent.props.products, + }; + render() { - const {parent} = this.props; - return( + const { parent } = this.props; + 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 (
- { - parent.props.products.map((item,i) => ( - - )) - } + {filterList.length > 0 + ? filterList.map((item, i) => ( + + )) + : null}
); } -} \ No newline at end of file +} + \ No newline at end of file diff --git a/src/views/Products/Sort/index.js b/src/views/Products/Sort/index.js index 9b16fdd..5d37e53 100644 --- a/src/views/Products/Sort/index.js +++ b/src/views/Products/Sort/index.js @@ -1,28 +1,26 @@ -import React from 'react'; -import SortIcon from '@material-ui/icons/Sort'; +import React from "react"; +import SortIcon from "@material-ui/icons/Sort"; -import './index.scss'; +import "./index.scss"; const maxDesktopSize = 1250; 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, -} +}; export default class Sort extends React.Component { render() { - const {parent} = this.props; - return( + const { parent } = this.props; + return (
- + مرتب سازی بر اساس
    - { - parent.props.sortItems.map((item, i) => ( - - )) - } + {parent.props.sortItems.map((item, i) => ( + + ))}
); @@ -30,7 +28,16 @@ export default class Sort extends React.Component { } const Item = (props) => { - return( -
  • {props.data}
  • + return ( +
  • props.parent.setState({ selectedSort : props.data })} + > + {props.data} +
  • ); -} \ No newline at end of file +}; diff --git a/src/views/Products/Sort/index.scss b/src/views/Products/Sort/index.scss index ef7e3a9..710b930 100644 --- a/src/views/Products/Sort/index.scss +++ b/src/views/Products/Sort/index.scss @@ -16,6 +16,8 @@ font-family: numeralLight; color: #373737; cursor: pointer; + padding: 5px 10px; + border-radius: 5px; } } } \ No newline at end of file diff --git a/src/views/Products/index.js b/src/views/Products/index.js index 24759aa..7e712e8 100644 --- a/src/views/Products/index.js +++ b/src/views/Products/index.js @@ -20,7 +20,11 @@ import book5 from "../../assets/images/book5.png"; import "./index.scss"; export default class Products extends Component { state = { - selectedFilters : [], + selectedSort : null, + selectedFilters : { + level : [], + subject : [], + }, firstFilters: [ { id: 0, value: "محبوب ترین" }, { id: 1, value: "جدیدترین" }, @@ -53,7 +57,7 @@ export default class Products extends Component {
    - +
    @@ -90,8 +94,8 @@ Products.defaultProps = { sortItems : [ 'پربازدیدترین', 'پرفروش ترین', - 'گران‌ترین', - 'ارزان‌ترین', + 'گران ‌ترین', + 'ارزان ‌ترین', 'جدیدترین', 'بزودی', ],