File tree Expand file tree Collapse file tree 3 files changed +50
-0
lines changed
src/containers/Tutorial/components Expand file tree Collapse file tree 3 files changed +50
-0
lines changed Original file line number Diff line number Diff line change 1+ import * as React from 'react'
2+ import Button from '../../../components/Button'
3+
4+ interface Props {
5+ hints : string [ ]
6+ }
7+
8+ const Hints = ( props : Props ) => {
9+ const [ hintIndex , setHintIndex ] = React . useState ( 0 )
10+ const isFinalHint = props . hints . length - 1 === hintIndex
11+ console . log ( hintIndex )
12+ const nextHint = ( ) => {
13+ console . log ( hintIndex )
14+ if ( ! isFinalHint ) {
15+ setHintIndex ( ( currentHintIndex ) => currentHintIndex + 1 )
16+ }
17+ }
18+ return (
19+ < div >
20+ { props . hints . map ( ( h , i ) => {
21+ return i <= hintIndex ? (
22+ < div key = { i } style = { { backgroundColor : 'red' } } >
23+ { h }
24+ </ div >
25+ ) : null
26+ } ) }
27+ < Button onClick = { nextHint } disabled = { isFinalHint } >
28+ Next Hint
29+ </ Button >
30+ </ div >
31+ )
32+ }
33+
34+ export default Hints
Original file line number Diff line number Diff line change @@ -2,13 +2,15 @@ import * as React from 'react'
22import * as T from 'typings'
33import { css , jsx } from '@emotion/core'
44import TestStatusIcon from './TestStatusIcon'
5+ import Hints from './Hints'
56import Markdown from '../../../components/Markdown'
67
78interface Props {
89 order : number
910 content : string
1011 status : T . ProgressStatus
1112 subtasks : { name : string ; pass : boolean } [ ] | null
13+ hints ?: string [ ]
1214 onLoadSolution ( ) : void
1315}
1416
@@ -54,9 +56,11 @@ const Step = (props: Props) => {
5456 { props . status === 'COMPLETE' && < TestStatusIcon size = "small" checked /> }
5557 </ div >
5658 < div >
59+ { /* content */ }
5760 < div css = { styles . content } >
5861 < Markdown > { props . content || '' } </ Markdown >
5962 </ div >
63+ { /* subtasks */ }
6064 { props . subtasks ? (
6165 < ul css = { styles . subtasks } >
6266 { props . subtasks . map ( ( subtask ) => (
@@ -68,6 +72,8 @@ const Step = (props: Props) => {
6872 ) ) }
6973 </ ul >
7074 ) : null }
75+ { /* hints */ }
76+ { props . hints && props . hints . length ? < Hints hints = { props . hints } /> : null }
7177 </ div >
7278 </ div >
7379 </ div >
Original file line number Diff line number Diff line change @@ -98,3 +98,13 @@ storiesOf('Step', module)
9898 ] }
9999 />
100100 ) )
101+ . add ( 'Hints' , ( ) => (
102+ < Step
103+ order = { 1 }
104+ content = { text ( 'text' , stepText ) }
105+ status = "ACTIVE"
106+ onLoadSolution = { action ( 'onLoadSolution' ) }
107+ subtasks = { null }
108+ hints = { [ 'First hint!' , 'Second hint!' ] }
109+ />
110+ ) )
You can’t perform that action at this time.
0 commit comments