diff --git a/typings/tutorial.d.ts b/typings/tutorial.d.ts index 58bd21df..00dd1dfc 100644 --- a/typings/tutorial.d.ts +++ b/typings/tutorial.d.ts @@ -28,6 +28,7 @@ export type Step = { setup: StepActions solution: Maybe subtasks?: { [testName: string]: boolean } + hints?: string[] } /** A tutorial for use in VSCode CodeRoad */ @@ -61,7 +62,7 @@ export interface TestRunnerArgs { export interface TestRunnerConfig { command: string - args?: TestRunnerArgs + args: TestRunnerArgs path?: string // deprecated directory?: string actions?: StepActions // deprecated diff --git a/web-app/src/containers/Tutorial/components/Hints.tsx b/web-app/src/containers/Tutorial/components/Hints.tsx new file mode 100644 index 00000000..39acaef6 --- /dev/null +++ b/web-app/src/containers/Tutorial/components/Hints.tsx @@ -0,0 +1,50 @@ +import * as React from 'react' +import Markdown from '../../../components/Markdown' +import Button from '../../../components/Button' + +const styles = { + hints: { + marginTop: '1rem', + }, + hintList: { + marginBottom: '0.5rem', + }, + hint: { + margin: '0.5rem 0', + backgroundColor: 'rgba(255,229,100,0.3)', + borderLeft: '#ffe564', + padding: '0.5rem', + }, +} + +interface Props { + hints: string[] +} + +const Hints = (props: Props) => { + const [hintIndex, setHintIndex] = React.useState(-1) + const isFinalHint = props.hints.length - 1 === hintIndex + const nextHint = () => { + if (!isFinalHint) { + setHintIndex((currentHintIndex) => currentHintIndex + 1) + } + } + return ( +
+
+ {props.hints.map((h, i) => { + return i <= hintIndex ? ( +
+ {h} +
+ ) : null + })} +
+ +
+ ) +} + +export default Hints diff --git a/web-app/src/containers/Tutorial/components/Level.tsx b/web-app/src/containers/Tutorial/components/Level.tsx index e8f01d0f..b28382dd 100644 --- a/web-app/src/containers/Tutorial/components/Level.tsx +++ b/web-app/src/containers/Tutorial/components/Level.tsx @@ -173,6 +173,7 @@ const Level = ({ content={step.content} onLoadSolution={onLoadSolution} subtasks={subtasks} + hints={step.hints} /> ) })} diff --git a/web-app/src/containers/Tutorial/components/Step.tsx b/web-app/src/containers/Tutorial/components/Step.tsx index b1007de6..5065685c 100644 --- a/web-app/src/containers/Tutorial/components/Step.tsx +++ b/web-app/src/containers/Tutorial/components/Step.tsx @@ -2,6 +2,7 @@ import * as React from 'react' import * as T from 'typings' import { css, jsx } from '@emotion/core' import TestStatusIcon from './TestStatusIcon' +import Hints from './Hints' import Markdown from '../../../components/Markdown' interface Props { @@ -9,6 +10,7 @@ interface Props { content: string status: T.ProgressStatus subtasks: { name: string; pass: boolean }[] | null + hints?: string[] onLoadSolution(): void } @@ -54,9 +56,11 @@ const Step = (props: Props) => { {props.status === 'COMPLETE' && }
+ {/* content */}
{props.content || ''}
+ {/* subtasks */} {props.subtasks ? (
    {props.subtasks.map((subtask) => ( @@ -68,6 +72,8 @@ const Step = (props: Props) => { ))}
) : null} + {/* hints */} + {props.hints && props.hints.length ? : null}
diff --git a/web-app/stories/Step.stories.tsx b/web-app/stories/Step.stories.tsx index ca519850..463bd290 100644 --- a/web-app/stories/Step.stories.tsx +++ b/web-app/stories/Step.stories.tsx @@ -98,3 +98,13 @@ storiesOf('Step', module) ]} /> )) + .add('Hints', () => ( + + ))