Skip to content

Fix/no steps #167

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Mar 28, 2020
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
render level with no steps
  • Loading branch information
ShMcK committed Mar 23, 2020
commit 76420e5036e3f48523a9757c4952d4d425c78f3a
53 changes: 26 additions & 27 deletions web-app/src/containers/Tutorial/LevelPage/Level.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -85,8 +85,10 @@ interface Props {
}

const Level = ({ level, onContinue, onLoadSolution, processes, testStatus }: Props) => {
if (!level.steps) {
throw new Error('No Stage steps found')
// @ts-ignore
let currentStep = level.steps.findIndex(s => s.status === 'ACTIVE')
if (currentStep === -1) {
currentStep = level.steps.length
}

const pageBottomRef = React.useRef(null)
Expand All @@ -95,11 +97,6 @@ const Level = ({ level, onContinue, onLoadSolution, processes, testStatus }: Pro
// @ts-ignore
pageBottomRef.current.scrollIntoView({ behavior: 'smooth' })
}
// @ts-ignore
let currentStep = level.steps.findIndex(s => s.status === 'ACTIVE')
if (currentStep === -1) {
currentStep = level.steps.length
}
React.useEffect(scrollToBottom, [currentStep])

return (
Expand All @@ -112,26 +109,28 @@ const Level = ({ level, onContinue, onLoadSolution, processes, testStatus }: Pro
<Markdown>{level.content || ''}</Markdown>
</div>

<div css={styles.tasks}>
<div css={styles.header}>Tasks</div>
<div css={styles.steps}>
{level.steps.map((step: (G.Step & { status: T.ProgressStatus }) | null, index: number) => {
if (!step) {
return null
}
return (
<Step
key={step.id}
order={index + 1}
status={step.status}
content={step.content}
onLoadSolution={onLoadSolution}
/>
)
})}
{level.steps.length ? (
<div css={styles.tasks}>
<div css={styles.header}>Tasks</div>
<div css={styles.steps}>
{level.steps.map((step: (G.Step & { status: T.ProgressStatus }) | null, index: number) => {
if (!step) {
return null
}
return (
<Step
key={step.id}
order={index + 1}
status={step.status}
content={step.content}
onLoadSolution={onLoadSolution}
/>
)
})}
</div>
</div>
<div ref={pageBottomRef} />
</div>
) : null}
<div ref={pageBottomRef} />

{(testStatus || processes.length > 0) && (
<div css={styles.processes}>
Expand All @@ -149,7 +148,7 @@ const Level = ({ level, onContinue, onLoadSolution, processes, testStatus }: Pro
{level.title}
</span>
<span>
{level.status === 'COMPLETE' ? (
{level.status === 'COMPLETE' || !level.steps.length ? (
<Button type="primary" onClick={onContinue}>
Continue
</Button>
Expand Down
21 changes: 21 additions & 0 deletions web-app/stories/Level.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -289,3 +289,24 @@ storiesOf('Level', module)
/>
)
})
.add('No steps', () => {
const level = {
id: 'L1',
index: 0,
title: 'A Title',
description: 'A summary of the level',
content: 'Some content here in markdown',
setup: null,
status: 'ACTIVE',
steps: [],
}
return (
<Level
level={level}
onContinue={action('onContinue')}
onLoadSolution={action('onLoadSolution')}
processes={[]}
testStatus={null}
/>
)
})