Skip to content

Traverse content (blocked) #296

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 5 commits into from
Apr 26, 2020
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
setup menu dropdown for level
Signed-off-by: shmck <[email protected]>
  • Loading branch information
ShMcK committed Apr 21, 2020
commit 11f7ec10af8a9e6babc1ec009e281f89cfd52de7
41 changes: 28 additions & 13 deletions web-app/src/containers/Tutorial/components/Level.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -87,18 +87,33 @@ const styles = {

interface Props {
menu: any
level: TT.Level & { status: T.ProgressStatus; index: number; steps: Array<TT.Step & { status: T.ProgressStatus }> }
steps: Array<TT.Step & { status: T.ProgressStatus }>
title: string
index: number
content: string
status: 'COMPLETE' | 'ACTIVE' | 'INCOMPLETE'
processes: T.ProcessEvent[]
testStatus: T.TestStatus | null
onContinue(): void
onLoadSolution(): void
}

const Level = ({ menu, level, onContinue, onLoadSolution, processes, testStatus }: Props) => {
const Level = ({
menu,
steps,
title,
content,
index,
status,
onContinue,
onLoadSolution,
processes,
testStatus,
}: Props) => {
// @ts-ignore
let currentStep = level.steps.findIndex((s) => s.status === 'ACTIVE')
let currentStep = steps.findIndex((s) => s.status === 'ACTIVE')
if (currentStep === -1) {
currentStep = level.steps.length
currentStep = steps.length
}

const pageBottomRef = React.useRef(null)
Expand All @@ -116,7 +131,7 @@ const Level = ({ menu, level, onContinue, onLoadSolution, processes, testStatus
<Dropdown
trigger={
<a css={styles.learn}>
Learn <Icon type="arrow-down" size="xxs" />{' '}
Learn <Icon type="arrow-down" size="xxs" />
</a>
}
triggerType="click"
Expand All @@ -125,15 +140,15 @@ const Level = ({ menu, level, onContinue, onLoadSolution, processes, testStatus
</Dropdown>
</div>
<div css={styles.text}>
<h2 css={styles.title}>{level.title}</h2>
<Markdown>{level.content || ''}</Markdown>
<h2 css={styles.title}>{title}</h2>
<Markdown>{content || ''}</Markdown>
</div>

{level.steps.length ? (
{steps.length ? (
<div css={styles.tasks}>
<div css={styles.header}>Tasks</div>
<div css={styles.steps}>
{level.steps.map((step: (TT.Step & { status: T.ProgressStatus }) | null, index: number) => {
{steps.map((step: (TT.Step & { status: T.ProgressStatus }) | null, index: number) => {
if (!step) {
return null
}
Expand Down Expand Up @@ -165,17 +180,17 @@ const Level = ({ menu, level, onContinue, onLoadSolution, processes, testStatus

<div css={styles.footer}>
<span>
{typeof level.index === 'number' ? `${level.index + 1}. ` : ''}
{level.title}
{typeof index === 'number' ? `${index + 1}. ` : ''}
{title}
</span>
<span>
{level.status === 'COMPLETE' || !level.steps.length ? (
{status === 'COMPLETE' || !steps.length ? (
<Button type="primary" onClick={onContinue}>
Continue
</Button>
) : (
<span css={styles.taskCount}>
{currentStep} of {level.steps.length} tasks
{currentStep} of {steps.length} tasks
</span>
)}
</span>
Expand Down
36 changes: 16 additions & 20 deletions web-app/src/containers/Tutorial/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ const TutorialPage = (props: PageProps) => {

const tutorial = selectors.currentTutorial(props.context)
const levelData: TT.Level = selectors.currentLevel(props.context)
const [content, setContent] = React.useState<string>(levelData.content)

const onContinue = (): void => {
props.send({
Expand All @@ -31,25 +32,16 @@ const TutorialPage = (props: PageProps) => {
props.send({ type: 'STEP_SOLUTION_LOAD' })
}

const level: TT.Level & {
status: T.ProgressStatus
index: number
steps: Array<TT.Step & { status: T.ProgressStatus }>
} = {
...levelData,
index: tutorial.levels.findIndex((l: TT.Level) => l.id === position.levelId),
status: progress.levels[position.levelId] ? 'COMPLETE' : 'ACTIVE',
steps: levelData.steps.map((step: TT.Step) => {
// label step status for step component
let status: T.ProgressStatus = 'INCOMPLETE'
if (progress.steps[step.id]) {
status = 'COMPLETE'
} else if (step.id === position.stepId) {
status = 'ACTIVE'
}
return { ...step, status }
}),
}
const steps = levelData.steps.map((step: TT.Step) => {
// label step status for step component
let status: T.ProgressStatus = 'INCOMPLETE'
if (progress.steps[step.id]) {
status = 'COMPLETE'
} else if (step.id === position.stepId) {
status = 'ACTIVE'
}
return { ...step, status }
})

const menu = (
<Menu>
Expand Down Expand Up @@ -79,8 +71,12 @@ const TutorialPage = (props: PageProps) => {

return (
<Level
title={levelData.title}
content={content}
menu={menu}
level={level}
index={tutorial.levels.findIndex((l: TT.Level) => l.id === position.levelId)}
steps={steps}
status={progress.levels[position.levelId] ? 'COMPLETE' : 'ACTIVE'}
onContinue={onContinue}
onLoadSolution={onLoadSolution}
processes={processes}
Expand Down
37 changes: 30 additions & 7 deletions web-app/stories/Level.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ storiesOf('Level', module)
description: 'A summary of the level',
content: 'Some content here in markdown',
setup: null,
status: 'ACTIVE',
status: 'ACTIVE' as 'ACTIVE',
steps: [
{
id: 'L1:S1',
Expand Down Expand Up @@ -88,7 +88,11 @@ storiesOf('Level', module)
return (
<Level
menu={menu}
level={level}
title={level.title}
content={level.content}
index={0}
status={level.status}
steps={level.steps}
onContinue={action('onContinue')}
onLoadSolution={action('onLoadSolution')}
processes={[]}
Expand All @@ -104,6 +108,7 @@ storiesOf('Level', module)
description: 'A description',
content: 'Should support markdown test\n ```js\nvar a = 1\n```\nwhew it works!',
setup: { commits: ['77e57cd'], commands: ['npm install'], files: [] },
status: 'ACTIVE' as 'ACTIVE',
steps: [
{
id: 'L1:S1',
Expand Down Expand Up @@ -143,7 +148,11 @@ storiesOf('Level', module)
return (
<Level
menu={menu}
level={level}
title={level.title}
content={level.content}
index={0}
status={level.status}
steps={level.steps}
onContinue={action('onContinue')}
onLoadSolution={action('onLoadSolution')}
processes={[
Expand All @@ -167,6 +176,7 @@ storiesOf('Level', module)
commits: ['6adeb95'],
commands: ['npm install'],
},
status: 'ACTIVE' as 'ACTIVE',
steps: [
{
id: 'L1:S1',
Expand Down Expand Up @@ -227,7 +237,11 @@ storiesOf('Level', module)
return (
<Level
menu={menu}
level={level}
title={level.title}
content={level.content}
index={0}
status={level.status}
steps={level.steps}
onContinue={action('onContinue')}
onLoadSolution={action('onLoadSolution')}
processes={[]}
Expand All @@ -246,6 +260,7 @@ storiesOf('Level', module)
commits: ['0d7543c'],
commands: ['npm install'],
},
status: 'ACTIVE' as 'ACTIVE',
steps: [
{
id: 'L2:S1',
Expand Down Expand Up @@ -300,7 +315,11 @@ storiesOf('Level', module)
return (
<Level
menu={menu}
level={level}
title={level.title}
content={level.content}
index={0}
status={level.status}
steps={level.steps}
onContinue={action('onContinue')}
onLoadSolution={action('onLoadSolution')}
processes={[]}
Expand All @@ -316,13 +335,17 @@ storiesOf('Level', module)
description: 'A summary of the level',
content: 'Some content here in markdown',
setup: null,
status: 'ACTIVE',
status: 'ACTIVE' as 'ACTIVE',
steps: [],
}
return (
<Level
menu={menu}
level={level}
title={level.title}
content={level.content}
index={0}
status={level.status}
steps={level.steps}
onContinue={action('onContinue')}
onLoadSolution={action('onLoadSolution')}
processes={[]}
Expand Down