Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit2e894ce

Browse files
committed
refactoring level data
Signed-off-by: shmck <shawn.j.mckay@gmail.com>
1 parent3a0575e commit2e894ce

File tree

4 files changed

+25
-58
lines changed

4 files changed

+25
-58
lines changed

‎web-app/src/containers/Tutorial/components/Level.tsx

Lines changed: 3 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -37,23 +37,11 @@ const styles = {
3737

3838
interfaceProps{
3939
level:TT.Level
40+
setHintsIndex(stepIndex:number,value:number):void
41+
displayHintsIndex:number[]
4042
}
4143

42-
constLevel=({ level}:Props)=>{
43-
// hold state for hints for the level
44-
const[displayHintsIndex,setDisplayHintsIndex]=React.useState<number[]>([])
45-
constsetHintsIndex=(index:number,value:number)=>{
46-
returnsetDisplayHintsIndex((displayHintsIndex)=>{
47-
constnext=[...displayHintsIndex]
48-
next[index]=value
49-
returnnext
50-
})
51-
}
52-
React.useEffect(()=>{
53-
// set the hints to empty on level starts
54-
setDisplayHintsIndex(level.steps.map((s:TT.Step)=>-1))
55-
},[level.id])
56-
44+
constLevel=({ level, setHintsIndex, displayHintsIndex}:Props)=>{
5745
constpageBottomRef=React.useRef(null)
5846
constscrollToBottom=()=>{
5947
//@ts-ignore

‎web-app/src/containers/Tutorial/containers/Review.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ const ReviewPage = (props: Props) => {
2525
<Contenttitle={level.title}content={level.content}/>
2626
<Stepssteps={level.steps}displayHintsIndex={level.steps.map((s)=>-1)}setHintsIndex={()=>{}}/>
2727
</div>
28+
{/* divider */}
2829
{index<props.levels.length-1 ?<hr/> :null}
2930
</>
3031
)

‎web-app/src/containers/Tutorial/index.tsx

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,15 @@ interface PageProps {
8585

8686
constTutorialPage=(props:PageProps)=>{
8787
const{ position, progress, processes, testStatus}=props.context
88+
// hold state for hints for the level
89+
const[displayHintsIndex,setDisplayHintsIndex]=React.useState<number[]>([])
90+
constsetHintsIndex=(index:number,value:number)=>{
91+
returnsetDisplayHintsIndex((displayHintsIndex)=>{
92+
constnext=[...displayHintsIndex]
93+
next[index]=value
94+
returnnext
95+
})
96+
}
8897

8998
consttutorial=selectors.currentTutorial(props.context)
9099

@@ -112,6 +121,11 @@ const TutorialPage = (props: PageProps) => {
112121
testStatus,
113122
})
114123

124+
React.useEffect(()=>{
125+
// set the hints to empty on level starts
126+
setDisplayHintsIndex(level.steps.map((s:TT.Step)=>-1))
127+
},[level.id])
128+
115129
return(
116130
<div>
117131
<div>
@@ -122,7 +136,9 @@ const TutorialPage = (props: PageProps) => {
122136
<spancss={styles.title}>{tutorial.summary.title}</span>
123137
</div>
124138

125-
{page==='level'&&<Levellevel={level}/>}
139+
{page==='level'&&(
140+
<Levellevel={level}displayHintsIndex={displayHintsIndex}setHintsIndex={setHintsIndex}/>
141+
)}
126142
{page==='settings'&&<SettingsPage/>}
127143
{page==='review'&&<ReviewPagelevels={levels}/>}
128144
</div>

‎web-app/stories/Level.stories.tsx

Lines changed: 4 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -52,47 +52,9 @@ const level = {
5252
storiesOf('Level',module)
5353
.addDecorator(SideBarDecorator)
5454
.addDecorator(withKnobs)
55-
.add('Level',()=>(
56-
<Level
57-
level={level}
58-
currentStep={0}
59-
status="ACTIVE"
60-
position={{levelId:'1',stepId:'1.1',complete:false}}
61-
progress={{levels:{},steps:{}}}
62-
processes={[]}
63-
testStatus={null}
64-
/>
65-
))
66-
.add('Level 2',()=>(
67-
<Level
68-
level={level}
69-
currentStep={0}
70-
status="ACTIVE"
71-
position={{levelId:'1',stepId:'1.2',complete:false}}
72-
progress={{levels:{},steps:{'1.1':true}}}
73-
processes={[]}
74-
testStatus={null}
75-
/>
76-
))
55+
.add('Level',()=><Levellevel={level}/>)
56+
.add('Level 2',()=><Levellevel={level}/>)
7757
.add('No steps',()=>(
78-
<Level
79-
level={{id:'1',title:'No Step Level',content:'No steps in this one',steps:[]}}
80-
currentStep={0}
81-
status="ACTIVE"
82-
position={{levelId:'1',stepId:null,complete:false}}
83-
progress={{levels:{},steps:{}}}
84-
processes={[]}
85-
testStatus={null}
86-
/>
87-
))
88-
.add('No lesson',()=>(
89-
<Level
90-
level={{id:'1',title:'No Step Level',content:'',steps:level.steps}}
91-
currentStep={0}
92-
status="ACTIVE"
93-
position={{levelId:'1',stepId:'1.1',complete:false}}
94-
progress={{levels:{},steps:{}}}
95-
processes={[]}
96-
testStatus={null}
97-
/>
58+
<Levellevel={{id:'1',title:'No Step Level',content:'No steps in this one',steps:[],status:'ACTIVE'}}/>
9859
))
60+
.add('No lesson',()=><Levellevel={{id:'1',title:'No Step Level',content:'',steps:level.steps}}/>)

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp