diff --git a/src/Redux/reducers/book.js b/src/Redux/reducers/book.js index f97bccf..ccb2049 100644 --- a/src/Redux/reducers/book.js +++ b/src/Redux/reducers/book.js @@ -5,14 +5,47 @@ const initialState = { info: null, searchResult: [], filterResult: [], + subjects: [], + levels: [], + sortFilters: ["مرتب سازی", "محبوب ترین", "جدیدترین"], }; + +const grades = [ + "اول", + "دوم", + "سوم", + "چهارم", + "پنجم", + "ششم", + "هفتم", + "هشتم", + "نهم", + "دهم", + "یازدهم", + "دوازدهم", +]; export default function book(state = initialState, action) { let { type, data } = action; switch (type) { case "book/list": - return { ...state, loading: false, list: data, error: null }; + let itemsSubject = data.map((item, index) => item.name); + if (window.innerWidth < 1000) { + itemsSubject.unshift("نام کتاب"); + } + let itemsLevel = data.map((item) => grades[item.gradeId]); + if (window.innerWidth < 1000) { + itemsLevel.unshift("پایه تحصیلی"); + } + return { + ...state, + loading: false, + list: data, + subjects: [...new Set(itemsSubject)], + levels: [...new Set(itemsLevel)], + error: null, + }; case "book/info": - return { ...state, loading: false, list: null, info: data, error: null }; + return { ...state, loading: false, info: data, error: null }; case "book/update": return { ...state, loading: false, error: null }; case "book/add": @@ -22,8 +55,7 @@ export default function book(state = initialState, action) { case "book/search": return { ...state }; case "book/filter": - const realList = - state.searchResult.length > 0 ? state.searchResult : state.list; + const realList = state.list; const level = data.level; const subject = data.subject; const sort = data.sort; @@ -32,21 +64,38 @@ export default function book(state = initialState, action) { localStorage.setItem("filter", "ON"); } let finalSort; - const byLevelFilter = - level.length > 0 - ? realList.filter( - (item) => item.name.indexOf(level.map((item) => item)) !== -1 - ) - : realList; - const bySubjectFilter = - subject.length > 0 - ? byLevelFilter.filter( - (item) => item.name.indexOf(subject.map((item) => item)) !== -1 - ) - : byLevelFilter; + let byLevelFilter = []; + if (level.length > 0) { + level.map((item1) => { + for (let i = 0; i < realList.length; i++) { + if (grades[realList[i].gradeId] === item1) { + byLevelFilter.push(realList[i]); + } + } + }); + } else { + byLevelFilter = realList; + } + + let bySubjectFilter = []; + if (subject.length > 0) { + subject.map((item1) => { + for (let i = 0; i < byLevelFilter.length; i++) { + if (byLevelFilter[i].name === item1) { + bySubjectFilter.push(byLevelFilter[i]); + } + } + }); + } else { + bySubjectFilter = byLevelFilter; + } + const bySearchFilter = search - ? bySubjectFilter.filter((item) => item.name.indexOf(search) !== -1) + ? bySubjectFilter.filter((item1) => item1.name.indexOf(search) !== -1) : bySubjectFilter; + + console.log(bySearchFilter); + if (sort === "گران ترین") { finalSort = bySearchFilter.sort((item1, item2) => { return item1.product[0].price - item2.product[0].price; diff --git a/src/views/Home/SingleBlog/index.js b/src/views/Home/SingleBlog/index.js index 7370f1c..d47ac2b 100644 --- a/src/views/Home/SingleBlog/index.js +++ b/src/views/Home/SingleBlog/index.js @@ -1,5 +1,7 @@ import React, { Component } from "react"; import { Link } from "react-router-dom"; +import VideoBox from "../../QR/VideoBox/index.js"; +import VoiceBox from "../../QR/VoiceBox/index.js"; import "./index.scss"; @@ -10,6 +12,11 @@ const fontSize = { h1: window.innerWidth > maxDesktopSize ? 28 : window.innerWidth / 45, p: window.innerWidth > maxDesktopSize ? 14 : window.innerWidth / 85, a: window.innerWidth > maxDesktopSize ? 16 : window.innerWidth / 70, + content: { + h1: window.innerWidth > maxDesktopSize ? 18 : window.innerWidth / 75, + p: window.innerWidth > maxDesktopSize ? 14 : window.innerWidth / 90, + h2: window.innerWidth > maxDesktopSize ? 14 : window.innerWidth / 90, + }, }, }; @@ -23,21 +30,37 @@ export default class SingleBlog extends Component {
{data.text}
بیشتر -