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
71bac820
Commit
71bac820
authored
May 29, 2019
by
zhanghaozhe
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
study redux
parent
dbfb701d
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
76 additions
and
40 deletions
+76
-40
src/HOCs/WithFullSize/index.js
+2
-2
src/HOCs/WithTab/index.js
+2
-2
src/components/study/index.js
+25
-6
src/components/study/myCourses/actions.js
+19
-11
src/components/study/myCourses/index.js
+21
-6
src/components/study/myCourses/reducers.js
+6
-12
src/index.js
+1
-1
No files found.
src/HOCs/WithFullSize/index.js
View file @
71bac820
import
React
,
{
Component
}
from
'react'
;
import
React
,
{
Pure
Component
}
from
'react'
;
export
default
function
(
WrappedComponent
)
{
return
class
extends
Component
{
return
class
extends
Pure
Component
{
componentDidMount
()
{
const
height
=
window
.
innerHeight
document
.
body
.
style
.
height
=
`
${
height
}
px`
...
...
src/HOCs/WithTab/index.js
View file @
71bac820
import
React
,
{
Component
}
from
'react'
import
React
,
{
Pure
Component
}
from
'react'
import
NavBar
from
'@/common/NavBar'
export
default
function
WithTab
(
WrappedComponent
)
{
return
class
extends
Component
{
return
class
extends
Pure
Component
{
render
()
{
return
(
<>
...
...
src/components/study/index.js
View file @
71bac820
...
...
@@ -6,27 +6,47 @@ import MyCourses from "./myCourses"
import
FreeCourses
from
'./freeCourses'
import
WithTab
from
'@/HOCs/WithTab'
import
WithFullSize
from
'@/HOCs/WithFullSize'
import
{
compose
}
from
'redux'
import
{
compose
}
from
'redux'
class
Study
extends
Component
{
state
=
{
}
list
;
storeScrollPosition
(
tab
){
}
render
()
{
const
{
match
}
=
this
.
props
;
return
(
<
section
id
=
'study'
>
<
div
className
=
'tab'
>
<
div
>
<
NavLink
to
=
{
`
${
match
.
url
}
/my-course`
}
activeClassName
=
'active'
>
我的课程
<
/NavLink
>
<
NavLink
to
=
{
`
${
match
.
url
}
/my-course`
}
replace
activeClassName
=
'active'
>
我的课程
<
/NavLink
>
<
/div
>
<
div
>
<
NavLink
to
=
{
`
${
match
.
url
}
/free-course`
}
activeClassName
=
'active'
>
免费课程
<
/NavLink
>
<
NavLink
to
=
{
`
${
match
.
url
}
/free-course`
}
replace
activeClassName
=
'active'
>
免费课程
<
/NavLink
>
<
/div
>
<
/div
>
<
div
className
=
"study-container"
>
<
div
className
=
"study-container"
ref
=
{
el
=>
this
.
list
=
el
}
>
<
Switch
>
<
Redirect
exact
from
=
'/study'
to
=
'study/my-course'
/>
<
Route
path
=
{
`
${
this
.
props
.
match
.
path
}
/my-course`
}
component
=
{
MyCourses
}
/
>
{
/*<Route path={`${this.props.match.path}/my-course`} component={MyCourses}/>
<Route path={`${this.props.match.path}/free-course`} component={FreeCourses}/>*/
}
<
Route
path
=
{
`
${
this
.
props
.
match
.
path
}
/my-course`
}
render
=
{
props
=>
{
<
MyCourses
storeScrollPosition
=
{
this
.
storeScrollPosition
}
/
>
}}
/
>
<
Route
path
=
{
`
${
this
.
props
.
match
.
path
}
/free-course`
}
component
=
{
FreeCourses
}
/
>
<
/Switch
>
<
/div
>
...
...
@@ -36,7 +56,6 @@ class Study extends Component {
}
// export default WithFullSize(WithTab(Study))
export
default
compose
(
WithFullSize
,
WithTab
...
...
src/components/study/myCourses/actions.js
View file @
71bac820
...
...
@@ -8,23 +8,31 @@ export const receiveMyCourses = payload => ({
})
const
PAGE_INTERVAL
=
1
const
NUM_INTERVAL
=
10
export
const
fetchCoursesListIfNeeded
=
()
=>
(
dispatch
,
getState
)
=>
{
const
myCourses
=
getState
().
myCourses
const
{
shouldFetch
,
page
,
num
}
=
myCourses
if
(
shouldFetch
)
{
dispatch
(
getMyCourses
({
page
:
page
+
PAGE_INTERVAL
,
num
:
num
+
NUM_INTERVAL
}))
}
}
export
const
getMyCourses
=
payload
=>
dispatch
=>
{
return
api
.
get
(
`/m/my_course/
${
payload
.
page
}
/
${
payload
.
num
}
`
)
.
then
(
res
=>
{
dispatch
(
receiveMyCourses
(
res
.
data
))
dispatch
(
receiveMyCourses
({
courseData
:
res
.
data
,
page
:
payload
.
page
,
num
:
payload
.
num
}))
dispatch
(
invalidateCourseDate
())
})
}
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
...
...
src/components/study/myCourses/index.js
View file @
71bac820
...
...
@@ -3,7 +3,11 @@ import { VList } from '@/common'
import
'./my-courses.scss'
import
{
isToday
,
format
}
from
"date-fns"
import
{
connect
}
from
"react-redux"
import
{
getMyCourses
}
from
"./actions"
import
{
fetchCoursesListIfNeeded
}
from
"./actions"
function
getStudyTime
(
seconds
)
{
return
{
...
...
@@ -13,7 +17,6 @@ function getStudyTime(seconds) {
}
}
function
AddCourse
(
props
)
{
return
(
<
div
className
=
'add-course'
>
...
...
@@ -49,12 +52,19 @@ function Record({record: {seconds, lesson_name}}) {
)
}
class
MyCourses
extends
PureComponent
{
state
=
{
addVisible
:
false
addVisible
:
false
,
courseData
:
[]
}
list
;
handleClick
=
()
=>
{
console
.
log
(
1
);
}
...
...
@@ -63,7 +73,11 @@ class MyCourses extends PureComponent {
}
componentDidMount
()
{
this
.
props
.
getMyCourses
({
page
:
1
,
num
:
10
});
this
.
props
.
fetchCoursesListIfNeeded
();
}
componentWillUnmount
()
{
console
.
log
(
'will unmount'
)
}
render
()
{
...
...
@@ -71,7 +85,7 @@ class MyCourses extends PureComponent {
if
(
data
&&
data
.
length
!==
0
)
{
return
(
<>
<
ul
>
<
ul
ref
=
{
el
=>
this
.
list
=
el
}
>
{
data
.
map
((
item
,
index
)
=>
{
...
...
@@ -124,6 +138,6 @@ const mapStateToProps = state => ({
courseData
:
state
.
myCourses
.
courseData
})
const
mapDispatchToProps
=
{
getMyCourses
}
const
mapDispatchToProps
=
{
fetchCoursesListIfNeeded
}
export
default
connect
(
mapStateToProps
,
mapDispatchToProps
)(
MyCourses
)
\ No newline at end of file
src/components/study/myCourses/reducers.js
View file @
71bac820
...
...
@@ -4,25 +4,19 @@ import {
}
from
'./actions'
const
initialState
=
{
shouldFetch
:
fals
e
,
courseData
:
{}
,
currentPage
:
1
,
currentNum
:
1
0
shouldFetch
:
tru
e
,
courseData
:
[]
,
page
:
0
,
num
:
0
}
export
default
function
myCourses
(
state
=
initialState
,
action
)
{
switch
(
action
.
type
)
{
case
RECEIVE_MY_COURSES
:
return
Object
.
assign
(
{},
state
,
{
courseData
:
action
.
payload
})
return
{...
state
,
...
action
.
payload
}
case
INVALIDATE_COURSEDATA
:
return
Object
.
assign
(
{},
state
,
{
shouldFetch
:
true
})
return
{...
state
,
shouldFetch
:
false
}
default
:
return
state
}
...
...
src/index.js
View file @
71bac820
...
...
@@ -3,7 +3,7 @@ import ReactDOM from 'react-dom';
import
{
createStore
,
applyMiddleware
}
from
'redux'
import
{
Provider
}
from
'react-redux'
import
thunk
from
'redux-thunk'
import
{
logger
}
from
'redux-logger'
import
logger
from
'redux-logger'
import
Routes
from
'./router'
;
import
rootReducers
from
'./store'
...
...
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