1
1
import React , { Component } from 'react'
2
2
import PropTypes from 'prop-types'
3
3
import { connect } from 'react-redux'
4
- import { logout , getCurrentProblemThunk , findOrCreateUserProblem , clearCurrentProblem } from '../store'
4
+ import { logout , getCurrentProblemThunk , getUserInputThunk , clearCurrentProblem } from '../store'
5
5
import { NavLink } from 'react-router-dom'
6
6
import Levels from './Levels'
7
7
import Editor from './CodeEditor'
@@ -28,20 +28,17 @@ class SingleProblem extends Component {
28
28
} )
29
29
} } )
30
30
. catch ( err => console . log ( err ) )
31
+
31
32
this . props . loadProblem ( this . props . params , this . props . userId )
32
33
}
33
34
34
35
render ( ) {
35
- const { email, isLoggedIn, problem, params, userId} = this . props
36
- let codeInput = ''
37
- if ( problem . users ) {
38
- codeInput = problem . users [ 0 ] . UserProblem . savedInput
39
- }
36
+ const { email, isLoggedIn, problem, params, userId, userInput} = this . props
40
37
return (
41
38
< div className = 'toc' >
42
39
< h3 > { problem ? problem . name : '' } </ h3 >
43
40
< h4 > { problem ? problem . prompt : '' } </ h4 >
44
- < Editor codeInput = { codeInput } />
41
+ < Editor userInput = { userInput } />
45
42
< NavLink to = { '/' } >
46
43
< button > Go Back Home</ button >
47
44
</ NavLink >
@@ -60,6 +57,7 @@ const mapState = (state, ownprops) => {
60
57
isLoggedIn : ! ! state . user . id ,
61
58
email : state . user . email ,
62
59
userId : state . user . id ,
60
+ userInput : state . userInput
63
61
}
64
62
}
65
63
@@ -69,6 +67,7 @@ const mapDispatch = (dispatch) => {
69
67
dispatch ( logout ( ) )
70
68
} ,
71
69
loadProblem ( problemId , userId ) {
70
+ dispatch ( getUserInputThunk ( problemId , userId ) )
72
71
dispatch ( getCurrentProblemThunk ( problemId , userId ) )
73
72
} ,
74
73
clearProblem ( ) {
0 commit comments