You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
90 lines
2.1 KiB
90 lines
2.1 KiB
const initialState = { |
|
loading: false, |
|
error: null, |
|
list: [], |
|
info: null, |
|
searchResult: [], |
|
filterResult: [], |
|
subjects: [], |
|
levels: [], |
|
sortFilters: ["مرتب سازی", "محبوب ترین", "جدیدترین"], |
|
selectedVideo: null, |
|
gradeFilterBooks: null, |
|
sortFilterCourse: null, |
|
selectedGrade: null, |
|
selectedSort: "پربازدید ترین ها", |
|
filterOptions: { |
|
grade: "", |
|
subject: "", |
|
productType: '', |
|
available: false, |
|
sort: null, |
|
search: "", |
|
}, |
|
productTypes: [ |
|
"کتاب فیزیکی", |
|
"کتاب دیجیتال", |
|
"دوره ویدئویی", |
|
"بسته های آموزشی", |
|
], |
|
}; |
|
|
|
const grades = [ |
|
"پیش دبستان", |
|
"اول", |
|
"دوم", |
|
"سوم", |
|
"چهارم", |
|
"پنجم", |
|
"ششم", |
|
"هفتم", |
|
"هشتم", |
|
"نهم", |
|
"دهم", |
|
"یازدهم", |
|
"دوازدهم", |
|
]; |
|
|
|
export default function book(state = initialState, action) { |
|
let { type, data } = action; |
|
switch (type) { |
|
case "book/list": |
|
let itemsSubject = (Array.isArray(data) ? data : []).map( |
|
(item, index) => item.name |
|
); |
|
itemsSubject.unshift("نام کتاب"); |
|
|
|
let itemsLevel = (Array.isArray(data) ? data : []) |
|
.map((item) => item.gradeId * 1) |
|
.sort((a, b) => a - b) |
|
.map((e) => grades[e]); |
|
itemsLevel.unshift("پایه تحصیلی"); |
|
|
|
return { |
|
...state, |
|
loading: false, |
|
list: data, |
|
subjects: Array.from(new Set(itemsSubject)), |
|
levels: Array.from(new Set(itemsLevel)), |
|
error: null, |
|
}; |
|
case "book/info": |
|
return { ...state, loading: false, info: data, error: null }; |
|
case "book/lesson/active": |
|
return { |
|
...state, |
|
loading: false, |
|
error: null, |
|
}; |
|
|
|
case "book/setFilterOptions": |
|
return { ...state, loading: false, error: null, filterOptions: data }; |
|
case "book/loading": |
|
return { ...state, loading: true }; |
|
case "book/error": |
|
// toast.error(data.message); |
|
return { ...state, loading: false, error: data.message }; |
|
default: |
|
return state; |
|
} |
|
}
|
|
|