|
|
|
@ -1,7 +1,7 @@ |
|
|
|
|
import location from '../../utils/location'; |
|
|
|
|
import location from "../../utils/location"; |
|
|
|
|
|
|
|
|
|
const initialState = { |
|
|
|
|
theme : localStorage.getItem('theme') || 'light', |
|
|
|
|
theme: localStorage.getItem("theme") || "light", |
|
|
|
|
homeData: [], |
|
|
|
|
newProducts: [], |
|
|
|
|
levels: [], |
|
|
|
@ -35,6 +35,21 @@ const initialState = { |
|
|
|
|
activeCategory: null, |
|
|
|
|
categories: null, |
|
|
|
|
bookSection: null, |
|
|
|
|
grades: { |
|
|
|
|
0: "پیش دبستان", |
|
|
|
|
1: "اول", |
|
|
|
|
2: "دوم", |
|
|
|
|
3: "سوم", |
|
|
|
|
4: "چهارم", |
|
|
|
|
5: "پنجم", |
|
|
|
|
6: "ششم", |
|
|
|
|
7: "هفتم", |
|
|
|
|
8: "هشتم", |
|
|
|
|
9: "نهم", |
|
|
|
|
10: "دهم", |
|
|
|
|
11: "یازدهم", |
|
|
|
|
12: "دوازدهم", |
|
|
|
|
}, |
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
const grades = [ |
|
|
|
@ -57,7 +72,7 @@ export default function publicApi(state = initialState, action) { |
|
|
|
|
switch (type) { |
|
|
|
|
case "public/setTheme": |
|
|
|
|
localStorage.setItem("theme", data); |
|
|
|
|
return { ...state, location: false, error : null, theme: data }; |
|
|
|
|
return { ...state, location: false, error: null, theme: data }; |
|
|
|
|
case "active/video": |
|
|
|
|
return { |
|
|
|
|
...state, |
|
|
|
@ -79,15 +94,13 @@ export default function publicApi(state = initialState, action) { |
|
|
|
|
loading: false, |
|
|
|
|
bookSection: data, |
|
|
|
|
error: null, |
|
|
|
|
selectedVideo: data.vods?.filter((item) => item.id !== videoId)[0] |
|
|
|
|
selectedVideo: data.vods?.filter((item) => item.id !== videoId)[0], |
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
case "public/vod/bookCourse": |
|
|
|
|
let allCats; |
|
|
|
|
allCats = Array.from( |
|
|
|
|
new Set( |
|
|
|
|
data.vods.map((item) => item.categoryId && item.categoryId) |
|
|
|
|
) |
|
|
|
|
new Set(data.vods.map((item) => item.categoryId && item.categoryId)) |
|
|
|
|
); |
|
|
|
|
return { |
|
|
|
|
...state, |
|
|
|
@ -102,7 +115,9 @@ export default function publicApi(state = initialState, action) { |
|
|
|
|
categories: allCats.map((item) => |
|
|
|
|
data.vods.filter((item1) => item1.categoryId === item) |
|
|
|
|
), |
|
|
|
|
selectedVideo: data.vods.filter((item ) => item.id !== location.getId())[0], |
|
|
|
|
selectedVideo: data.vods.filter( |
|
|
|
|
(item) => item.id !== location.getId() |
|
|
|
|
)[0], |
|
|
|
|
}; |
|
|
|
|
case "public/homePage": |
|
|
|
|
let itemsLevel; |
|
|
|
@ -124,101 +139,9 @@ export default function publicApi(state = initialState, action) { |
|
|
|
|
error: null, |
|
|
|
|
homeData: data, |
|
|
|
|
}; |
|
|
|
|
// case "public/filter":
|
|
|
|
|
// const realList =
|
|
|
|
|
// state.newProducts.length === 0
|
|
|
|
|
// ? state.homeData.filter(
|
|
|
|
|
// (item) => item.title === "جدیدترین کتابهای دانوین"
|
|
|
|
|
// )[0].data
|
|
|
|
|
// : state.newProducts;
|
|
|
|
|
// if (state.newProducts.length === 0) {
|
|
|
|
|
// state = {
|
|
|
|
|
// ...state,
|
|
|
|
|
// newProducts: realList,
|
|
|
|
|
// };
|
|
|
|
|
// console.log("here1");
|
|
|
|
|
// }
|
|
|
|
|
// const level = data.levels;
|
|
|
|
|
// const search = data.search;
|
|
|
|
|
// if (level.length > 0 || search) {
|
|
|
|
|
// localStorage.setItem("filter", "ON");
|
|
|
|
|
// } else {
|
|
|
|
|
// return {
|
|
|
|
|
// ...state,
|
|
|
|
|
// loading: false,
|
|
|
|
|
// error: null,
|
|
|
|
|
// homeData: state.homeData.map((item) =>
|
|
|
|
|
// item.title === "جدیدترین کتابهای دانوین"
|
|
|
|
|
// ? { ...item, data: state.newProducts }
|
|
|
|
|
// : { ...item }
|
|
|
|
|
// ),
|
|
|
|
|
// newProducts: [],
|
|
|
|
|
// };
|
|
|
|
|
// }
|
|
|
|
|
// let byLevelFilter = [];
|
|
|
|
|
// if (level.length > 0) {
|
|
|
|
|
// level.map((item1) => {
|
|
|
|
|
// for (let i = 0; i < realList.length; i++) {
|
|
|
|
|
// if (grades[realList[i].book.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
|
|
|
|
|
// ? byLevelFilter.filter((item1) => item1.name.indexOf(search) !== -1)
|
|
|
|
|
// : byLevelFilter;
|
|
|
|
|
// // if (sort === "گران ترین") {
|
|
|
|
|
// // finalSort = bySearchFilter.sort((item1, item2) => {
|
|
|
|
|
// // return item1.product[0].price - item2.product[0].price;
|
|
|
|
|
// // });
|
|
|
|
|
// // } else {
|
|
|
|
|
// // finalSort = bySearchFilter;
|
|
|
|
|
// // }
|
|
|
|
|
|
|
|
|
|
// return {
|
|
|
|
|
// ...state,
|
|
|
|
|
// loading: false,
|
|
|
|
|
// error: null,
|
|
|
|
|
// homeData: state.homeData.map((item) =>
|
|
|
|
|
// item.title === "جدیدترین کتابهای دانوین"
|
|
|
|
|
// ? { ...item, data: bySearchFilter }
|
|
|
|
|
// : { ...item }
|
|
|
|
|
// ),
|
|
|
|
|
// };
|
|
|
|
|
// case "faq/list":
|
|
|
|
|
// return { ...state, loading: false, error: null, faqList: data };
|
|
|
|
|
// case "public/faq/search":
|
|
|
|
|
// return {
|
|
|
|
|
// ...state,
|
|
|
|
|
// loading: false,
|
|
|
|
|
// error: null,
|
|
|
|
|
// searchResult: state.faqList.filter(
|
|
|
|
|
// (item) =>
|
|
|
|
|
// item.title.indexOf(data) !== -1 ||
|
|
|
|
|
// item.description.indexOf(data) !== -1
|
|
|
|
|
// ),
|
|
|
|
|
// };
|
|
|
|
|
case "public/contact": |
|
|
|
|
return { ...state, loading: false, error: null, contactData: data }; |
|
|
|
|
// case "public/ar":
|
|
|
|
|
// return { ...state, loading: false, error: null, arList: data };
|
|
|
|
|
case "public/blogList": |
|
|
|
|
return { ...state, loading: false, error: null, blogList: data }; |
|
|
|
|
case "public/blogInfo": |
|
|
|
|