Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
M
mr-julyedu
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
baiguangyao
mr-julyedu
Commits
d9f5c936
Commit
d9f5c936
authored
May 31, 2019
by
zhanghaozhe
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
study redux
parent
f67e6ca8
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
29 additions
and
22 deletions
+29
-22
src/components/study/myCourses/actions.js
+10
-9
src/components/study/myCourses/index.js
+12
-5
src/components/study/myCourses/reducers.js
+7
-8
No files found.
src/components/study/myCourses/actions.js
View file @
d9f5c936
...
...
@@ -12,8 +12,8 @@ const PAGE_INTERVAL = 1
export
const
NUM_INTERVAL
=
10
export
const
fetchCoursesListIfNeeded
=
()
=>
(
dispatch
,
getState
)
=>
{
const
myCourses
=
getState
().
myCourses
const
{
s
houldFetch
,
page
}
=
myCourses
if
(
shouldFetch
)
{
const
{
s
witchTab
,
page
}
=
myCourses
if
(
!
switchTab
)
{
dispatch
(
getMyCourses
({
page
:
page
+
PAGE_INTERVAL
,
num
:
NUM_INTERVAL
...
...
@@ -32,16 +32,16 @@ export const getMyCourses = payload => dispatch => {
page
:
payload
.
page
,
num
:
payload
.
num
}))
dispatch
(
invalidateCourseDate
())
})
}
export
const
INVALIDATE_COURSEDATA
=
'INVALIDATE_COURSEDATA'
export
const
invalidateCourseDate
=
()
=>
({
type
:
INVALIDATE_COURSEDATA
export
const
SWITCH_TAB
=
'SWITCH_TAB'
export
const
switchTab
=
payload
=>
({
type
:
SWITCH_TAB
,
payload
})
export
const
VALIDATE_COURSEDATA
=
'VALIDATE_COURSEDATA
'
export
const
validateCourseData
=
()
=>
({
type
:
VALIDATE_COURSEDATA
export
const
NOMORE_COURSE
=
'NOMORE_COURSES
'
export
const
nomoreCourse
=
()
=>
({
type
:
NOMORE_COURSE
})
\ No newline at end of file
src/components/study/myCourses/index.js
View file @
d9f5c936
...
...
@@ -3,9 +3,9 @@ import { VList } from '@/common'
import
'./my-courses.scss'
import
{
isToday
,
format
}
from
"date-fns"
import
{
connect
}
from
"react-redux"
import
{
fetchCoursesListIfNeeded
,
validateCourseData
}
from
"./actions"
import
{
fetchCoursesListIfNeeded
,
switchTab
}
from
"./actions"
import
InfiniteScroll
from
'react-infinite-scroller'
import
{
debounce
}
from
'lodash'
import
{
debounce
}
from
'lodash'
function
getStudyTime
(
seconds
)
{
...
...
@@ -78,16 +78,22 @@ class MyCourses extends PureComponent {
}
componentDidMount
()
{
console
.
log
(
'did mount'
)
this
.
props
.
switchTab
(
false
)
this
.
props
.
fetchCoursesListIfNeeded
();
}
componentWillUnmount
(){
console
.
log
(
'will unmount'
)
this
.
props
.
switchTab
(
true
);
}
componentDidUpdate
()
{
console
.
log
(
'updated'
)
}
loadFunc
=
debounce
(()
=>
{
if
(
this
.
props
.
courseList
.
length
%
10
===
0
){
this
.
props
.
validateCourseData
();
if
(
this
.
props
.
courseList
.
length
%
10
===
0
)
{
this
.
props
.
fetchCoursesListIfNeeded
();
}
},
200
)
...
...
@@ -153,7 +159,7 @@ const mapStateToProps = state => ({
const
mapDispatchToProps
=
{
fetchCoursesListIfNeeded
,
validateCourseData
switchTab
}
export
default
connect
(
mapStateToProps
,
mapDispatchToProps
)(
MyCourses
)
\ No newline at end of file
src/components/study/myCourses/reducers.js
View file @
d9f5c936
import
{
RECEIVE_MY_COURSES
,
INVALIDATE_COURSEDATA
,
VALIDATE_COURSEDATA
SWITCH_TAB
,
NOMORE_COURSE
}
from
'./actions'
const
initialState
=
{
s
houldFetch
:
tru
e
,
s
witchTab
:
fals
e
,
courseList
:
[],
page
:
0
,
statusCode
:
0
,
msg
:
''
,
noMore
:
false
noMore
:
false
,
}
...
...
@@ -19,10 +19,9 @@ export default function myCourses(state = initialState, action) {
case
RECEIVE_MY_COURSES
:
let
{
courseList
,
...
rest
}
=
action
.
payload
return
{...
state
,
...
rest
,
courseList
:
state
.
courseList
.
concat
(
courseList
)}
case
INVALIDATE_COURSEDATA
:
return
{...
state
,
shouldFetch
:
false
}
case
VALIDATE_COURSEDATA
:
return
{...
state
,
shouldFetch
:
true
}
case
SWITCH_TAB
:
return
{...
state
,
switchTab
:
action
.
payload
}
case
NOMORE_COURSE
:
default
:
return
state
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment