|
|
|
@ -1,11 +1,17 @@ |
|
|
|
|
import React, { useState, useEffect, useRef } from "react"; |
|
|
|
|
import { connect } from "react-redux"; |
|
|
|
|
import { book } from "../../redux/actions"; |
|
|
|
|
import _ from 'lodash'; |
|
|
|
|
import _ from "lodash"; |
|
|
|
|
import dropdown from "../../assets/icons/dropdown.png"; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
function GradeFilter({selectedGrade, gradeFilter, grades, gradeDropdown, setGradeDropdown, theme}: any) { |
|
|
|
|
function GradeFilter({ |
|
|
|
|
selectedGrade, |
|
|
|
|
gradeFilter, |
|
|
|
|
grades, |
|
|
|
|
gradeDropdown, |
|
|
|
|
setGradeDropdown, |
|
|
|
|
theme, |
|
|
|
|
}: any) { |
|
|
|
|
const [arrowTop, setArrowTop] = useState(false); |
|
|
|
|
|
|
|
|
|
useEffect(() => { |
|
|
|
@ -14,20 +20,28 @@ function GradeFilter({selectedGrade, gradeFilter, grades, gradeDropdown, setGrad |
|
|
|
|
|
|
|
|
|
const mobileList = useRef<HTMLUListElement>(null); |
|
|
|
|
|
|
|
|
|
const setDropdown = (e : any) => { |
|
|
|
|
const setDropdown = (e: any) => { |
|
|
|
|
e.stopPropagation(); |
|
|
|
|
setGradeDropdown(!gradeDropdown); |
|
|
|
|
} |
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
return ( |
|
|
|
|
<section className={_.join(["grade-filter d-flex align-items-center", theme === 'light' ? 'grade-filter__light' : 'grade-filter__dark']," ")}> |
|
|
|
|
<section |
|
|
|
|
className={_.join( |
|
|
|
|
[ |
|
|
|
|
"grade-filter d-flex align-items-center", |
|
|
|
|
theme === "light" ? "grade-filter-light" : "grade-filter-dark", |
|
|
|
|
], |
|
|
|
|
" " |
|
|
|
|
)} |
|
|
|
|
> |
|
|
|
|
<h1 className="d-flex align-items-center"> |
|
|
|
|
پایه تحصیلی |
|
|
|
|
<span className="desktop"></span> |
|
|
|
|
</h1> |
|
|
|
|
<div |
|
|
|
|
className="grade-filter__box mobile" |
|
|
|
|
onClick={(e : any) => setDropdown(e)} |
|
|
|
|
onClick={(e: any) => setDropdown(e)} |
|
|
|
|
> |
|
|
|
|
{selectedGrade ? ( |
|
|
|
|
<h2>{grades[selectedGrade - 1].name}</h2> |
|
|
|
@ -45,10 +59,10 @@ function GradeFilter({selectedGrade, gradeFilter, grades, gradeDropdown, setGrad |
|
|
|
|
{grades.map((item: any, i: any) => ( |
|
|
|
|
<li |
|
|
|
|
key={i} |
|
|
|
|
onClick={() => |
|
|
|
|
gradeFilter(item.value) |
|
|
|
|
onClick={() => gradeFilter(item.value)} |
|
|
|
|
className={ |
|
|
|
|
selectedGrade === item.value ? "grade-filter__list--active" : "" |
|
|
|
|
} |
|
|
|
|
className={selectedGrade === item.value ? "grade-filter__list--active" : ""} |
|
|
|
|
> |
|
|
|
|
{item.name} |
|
|
|
|
</li> |
|
|
|
@ -56,8 +70,16 @@ function GradeFilter({selectedGrade, gradeFilter, grades, gradeDropdown, setGrad |
|
|
|
|
</ul> |
|
|
|
|
) : null} |
|
|
|
|
|
|
|
|
|
<ul className="desktop align-items-center" ref={mobileList}> |
|
|
|
|
{ selectedGrade && <figure style={{ right : (mobileList as any).current?.offsetWidth / 12 * (selectedGrade - 1) }}></figure> } |
|
|
|
|
<ul className="desktop align-items-center" ref={mobileList}> |
|
|
|
|
{selectedGrade && ( |
|
|
|
|
<figure |
|
|
|
|
style={{ |
|
|
|
|
right: |
|
|
|
|
((mobileList as any).current?.offsetWidth / 12) * |
|
|
|
|
(selectedGrade - 1), |
|
|
|
|
}} |
|
|
|
|
></figure> |
|
|
|
|
)} |
|
|
|
|
{grades.map((item: any, i: any) => ( |
|
|
|
|
<li |
|
|
|
|
key={i} |
|
|
|
@ -75,7 +97,7 @@ function GradeFilter({selectedGrade, gradeFilter, grades, gradeDropdown, setGrad |
|
|
|
|
export default connect( |
|
|
|
|
(state: any) => ({ |
|
|
|
|
selectedGrade: state.book.selectedGrade, |
|
|
|
|
theme : state.publicApi.theme, |
|
|
|
|
theme: state.publicApi.theme, |
|
|
|
|
}), |
|
|
|
|
{ gradeFilter: book.gradeFilter } |
|
|
|
|
)(GradeFilter); |
|
|
|
|