Commit cee9c07a by FE

pull haozhe

parents 74b687a9 24451c4d
......@@ -22,28 +22,17 @@ export const fetchCoursesListIfNeeded = () => (dispatch, getState) => {
}
}
// 首次加载,初始化noMore状态
export const initIsMore = () => (dispatch) => {
dispatch(nomoreCourse({
noMore: false
}));
}
export const getMyCourses = payload => dispatch => {
dispatch(startFetchingCourses)
return http.get(`${API.home}/m/my_course/${payload.page}/${payload.num}`)
.then(res => {
const {data, code, msg} = res.data
if (data.length === 0) {
dispatch(nomoreCourse({
noMore: true
}))
if (code == 200 && data.length === 0) {
dispatch(nomoreCourse())
return
}
if (data.length % 10 !== 0) {
dispatch(nomoreCourse({
noMore: true
}))
if (code == 200 && data.length % 10 !== 0) {
dispatch(nomoreCourse())
}
dispatch(receiveMyCourses({
courseList: data,
......
......@@ -3,7 +3,7 @@ import VList from '@/common/v-list-base'
import './my-courses.scss'
import { isToday, format } from "date-fns"
import { connect } from "react-redux"
import { fetchCoursesListIfNeeded, switchTab, initIsMore } from "./actions"
import { fetchCoursesListIfNeeded, switchTab } from "./actions"
import InfiniteScroll from 'react-infinite-scroller'
import { debounce } from 'lodash'
import { Link } from 'react-router-dom'
......@@ -84,8 +84,6 @@ class MyCourses extends PureComponent {
}
componentDidMount() {
console.log(this.props);
this.props.initIsMore();
this.props.switchTab(false)
this.props.fetchCoursesListIfNeeded()
}
......@@ -101,15 +99,15 @@ class MyCourses extends PureComponent {
}, 200)
render() {
let list = this.props.courseList
let {courseList, user} = this.props
return <Loading isLoading={this.props.isLoading}>
{
list && list.length !== 0
courseList && courseList.length !== 0
?
<>
<div className="my-course-uid">
{`加群请备注您的学号:${this.props.user.data.uid}`}
{`加群请备注您的学号:${!user.hasError && this.props.user.data.uid}`}
</div>
<InfiniteScroll
pageStart={0}
......@@ -119,7 +117,7 @@ class MyCourses extends PureComponent {
>
<ul ref={el => this.list = el}>
{
list.map((item, index) => {
courseList.map((item, index) => {
const Info = (
<div className="info">
......@@ -161,7 +159,7 @@ class MyCourses extends PureComponent {
</ul>
</InfiniteScroll>
{
list.length % 10 !== 0 ?
courseList.length % 10 !== 0 ?
<AddCourse addCourseClick={this.addCourseClick}/>
: null
}
......@@ -188,6 +186,5 @@ export default connect(
}),
{
fetchCoursesListIfNeeded,
switchTab,
initIsMore
switchTab
})(MyCourses)
\ No newline at end of file
......@@ -4,6 +4,7 @@ import {
NOMORE_COURSE,
START_FETCHING_COURSES
} from './actions'
import { SET_CURRENT_USER } from '@/store/userAction'
const initialState = {
switchTab: false,
......@@ -31,7 +32,9 @@ export default function myCourses(state = initialState, action) {
case SWITCH_TAB:
return {...state, switchTab: payload}
case NOMORE_COURSE:
return Object.assign({}, state, payload);
return {...state, noMore: true}
case SET_CURRENT_USER:
return payload.hasError ? initialState : {...state, page: 0}
default:
return state
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment