Commit dbfb701d by zhanghaozhe

study redux

parent 437fc544
import { api } from '@/utils' import { api } from '@/utils'
export const RECEIVE_MY_COURSES = 'RECEIVE_MY_COURSES' export const RECEIVE_MY_COURSES = 'RECEIVE_MY_COURSES'
export const receiveMyCourses = payload => ({ export const receiveMyCourses = payload => ({
type: RECEIVE_MY_COURSES, type: RECEIVE_MY_COURSES,
...@@ -14,6 +15,18 @@ export const getMyCourses = payload => dispatch => { ...@@ -14,6 +15,18 @@ export const getMyCourses = payload => dispatch => {
}) })
} }
const fetchCoursesListIfNeeded = payload => {
const NUM_INTERVAL = 10
export const fetchCoursesListIfNeeded = payload => (dispatch, getState) => {
const {shouldFetch, currentPage, currentNum} = getState().myCourses
if(!shouldFetch){
dispatch(getMyCourses)
}
} }
export const INVALIDATE_COURSEDATA = 'INVALIDATE_COURSEDATA'
export const invalidateCourseDate = () => ({
type: INVALIDATE_COURSEDATA
})
import React, { PureComponent } from "react" import React, { PureComponent } from "react"
import { VList } from '../../../common' import { VList } from '@/common'
import './my-courses.scss' import './my-courses.scss'
import { api } from '@/utils'
import { isToday, format } from "date-fns" import { isToday, format } from "date-fns"
import { connect } from "react-redux" import { connect } from "react-redux"
import { getMyCourses } from "./actions" import { getMyCourses } from "./actions"
const mockData = [
{
title: '三月面试求职班',
imgUrl: 'https://julyedu-img-public.oss-cn-beijing.aliyuncs.com/Public/Image/4c5ccac604.jpg',
contact: 'QQ群:449141326',
time: '03月12日',
record: '学习到第2课2分33秒'
},
{
title: '三月面试求职班',
imgUrl: 'https://julyedu-img-public.oss-cn-beijing.aliyuncs.com/Public/Image/4c5ccac604.jpg',
contact: 'QQ群:449141326',
time: '03月12日',
record: '学习到第2课2分33秒'
},
{
title: '三月面试求职班',
imgUrl: 'https://julyedu-img-public.oss-cn-beijing.aliyuncs.com/Public/Image/4c5ccac604.jpg',
contact: 'QQ群:449141326',
time: '03月12日',
record: '学习到第2课2分33秒'
},
{
title: '三月面试求职班',
imgUrl: 'https://julyedu-img-public.oss-cn-beijing.aliyuncs.com/Public/Image/4c5ccac604.jpg',
contact: 'QQ群:449141326',
time: '03月12日',
record: '学习到第2课2分33秒'
},
{
title: '三月面试求职班',
imgUrl: 'https://julyedu-img-public.oss-cn-beijing.aliyuncs.com/Public/Image/4c5ccac604.jpg',
contact: 'QQ群:449141326',
time: '03月12日',
record: '学习到第2课2分33秒'
},
]
function getStudyTime(seconds) { function getStudyTime(seconds) {
return { return {
hour: Math.floor(seconds / (60 * 60)), hour: Math.floor(seconds / (60 * 60)),
...@@ -93,7 +52,7 @@ function Record({record: {seconds, lesson_name}}) { ...@@ -93,7 +52,7 @@ function Record({record: {seconds, lesson_name}}) {
class MyCourses extends PureComponent { class MyCourses extends PureComponent {
state = { state = {
courseList: this.props.courseList.data addVisible: false
} }
handleClick = () => { handleClick = () => {
...@@ -104,23 +63,11 @@ class MyCourses extends PureComponent { ...@@ -104,23 +63,11 @@ class MyCourses extends PureComponent {
} }
componentDidMount() { componentDidMount() {
console.log(this.props.courseList)
/*api.get('/m/my_course/1/10')
.then(res => {
if (res.data.code == 200) {
this.setState({
courseList: res.data.data
});
} else {
console.log(res.data.msg)
}
})*/
this.props.getMyCourses({page: 1, num: 10}); this.props.getMyCourses({page: 1, num: 10});
} }
render() { render() {
let { data } = this.props.courseList let {data} = this.props.courseData
console.log(data)
if (data && data.length !== 0) { if (data && data.length !== 0) {
return ( return (
<> <>
...@@ -144,19 +91,24 @@ class MyCourses extends PureComponent { ...@@ -144,19 +91,24 @@ class MyCourses extends PureComponent {
return ( return (
<VList img={item.image_name} <VList img={item.image_name}
handleClick={this.handleClick} handleClick={this.handleClick}
{...item} key={index} {...item}
key={index}
info={Info}/> info={Info}/>
) )
}) })
} }
</ul> </ul>
<AddCourse addCourseClick={this.addCourseClick}/> {
this.state.addVisible ?
<AddCourse addCourseClick={this.addCourseClick}/>
: null
}
</> </>
) )
} else { } else {
return ( return (
<div className="empty"> <div className="empty">
<p><i className='iconfont iconfish'></i></p> <p><i className='iconfont iconfish'/></p>
<p className='empty-prompt'>还是咸鱼一条,快去翻身~</p> <p className='empty-prompt'>还是咸鱼一条,快去翻身~</p>
<p> <p>
<button>去选课</button> <button>去选课</button>
...@@ -169,9 +121,9 @@ class MyCourses extends PureComponent { ...@@ -169,9 +121,9 @@ class MyCourses extends PureComponent {
} }
const mapStateToProps = state => ({ const mapStateToProps = state => ({
courseList: state.myCourses.courseList courseData: state.myCourses.courseData
}) })
const mapDispatchToProps = {getMyCourses} const mapDispatchToProps = {getMyCourses}
export default connect(mapStateToProps,mapDispatchToProps)(MyCourses) export default connect(mapStateToProps, mapDispatchToProps)(MyCourses)
\ No newline at end of file \ No newline at end of file
.info { .info {
display: flex; display: flex;
//flex-flow: column wrap;
//justify-content: space-between;
flex-wrap: wrap; flex-wrap: wrap;
width: 55%; width: 55%;
...@@ -56,6 +54,7 @@ ...@@ -56,6 +54,7 @@
align-items: center; align-items: center;
padding-top: 140px; padding-top: 140px;
background: $bg_f5f5f5; background: $bg_f5f5f5;
.iconfish { .iconfish {
width: 20px; width: 20px;
height: 20px; height: 20px;
...@@ -67,11 +66,12 @@ ...@@ -67,11 +66,12 @@
font-size: $font_12; font-size: $font_12;
color: $color_666; color: $color_666;
} }
button{
width:131px; button {
height:30px; width: 131px;
border:1px solid $active; height: 30px;
border-radius:15px; border: 1px solid $active;
border-radius: 15px;
background: transparent; background: transparent;
color: $active; color: $active;
font-size: $font_16; font-size: $font_16;
......
import {RECEIVE_MY_COURSES} from './actions' import {
RECEIVE_MY_COURSES,
INVALIDATE_COURSEDATA
} from './actions'
const initialState = { const initialState = {
isValid: false, shouldFetch: false,
courseList: [] courseData: {},
currentPage: 1,
currentNum: 10
} }
export default function myCourses(state = initialState, action) { export default function myCourses(state = initialState, action) {
switch (action.type) { switch (action.type) {
case RECEIVE_MY_COURSES: case RECEIVE_MY_COURSES:
return Object.assign({}, state, {courseList: action.payload}) return Object.assign(
{},
state,
{courseData: action.payload})
case INVALIDATE_COURSEDATA:
return Object.assign(
{},
state,
{shouldFetch: true})
default: default:
return state return state
} }
......
...@@ -10,6 +10,7 @@ $tabFontSize: 15px; ...@@ -10,6 +10,7 @@ $tabFontSize: 15px;
.tab { .tab {
height: $tabHeight; height: $tabHeight;
max-height: $tabHeight;
line-height: $tabHeight; line-height: $tabHeight;
text-align: center; text-align: center;
background: #F7F9FC; background: #F7F9FC;
......
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