Skip to content

Feature/style changes #386

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 28 commits into from
Jul 12, 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
Prev Previous commit
Next Next commit
refactor level
Signed-off-by: shmck <shawn.j.mckay@gmail.com>
  • Loading branch information
ShMcK committed Jul 11, 2020
commit 6cdcc6afe4417f69ad4f0cb486c0f549dd8d3bec
104 changes: 7 additions & 97 deletions web-app/src/containers/Tutorial/components/Level.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,8 @@ import * as React from 'react'
import * as T from 'typings'
import * as TT from 'typings/tutorial'
import { css, jsx } from '@emotion/core'
import Button from '../../../components/Button'
import Markdown from '../../../components/Markdown'
import ProcessMessages from '../../../components/ProcessMessages'
import TestMessage from '../../../components/TestMessage'
import Step from './Step'
import { DISPLAY_RUN_TEST_BUTTON } from '../../../environment'

const styles = {
page: {
Expand Down Expand Up @@ -40,46 +36,11 @@ const styles = {
fontWeight: 'bold' as 'bold',
lineHeight: '1.2rem',
},
processes: {
padding: '0 1rem',
position: 'fixed' as 'fixed',
bottom: '2rem',
left: 0,
right: 0,
top: 'auto',
},
testMessage: {
position: 'absolute' as 'absolute',
top: 'auto',
bottom: '2rem',
left: '5px',
right: '5px',
},
footer: {
display: 'flex' as 'flex',
flexDirection: 'row' as 'row',
justifyContent: 'space-between',
alignItems: 'center',
height: '2rem',
backgroundColor: 'black',
fontSize: '1rem',
lineHeight: '1rem',
padding: '10px 1rem',
position: 'fixed' as 'fixed',
bottom: 0,
left: 0,
right: 0,
color: 'white',
},
taskCount: {
fontSize: '0.8rem',
opacity: 0.9,
},
}

interface Props {
tutorial: Exclude<TT.Tutorial, 'config'>
index: number
level: TT.Level
currentStep: number
status: 'COMPLETE' | 'ACTIVE' | 'INCOMPLETE'
progress: T.Progress
position: T.Position
Expand All @@ -91,21 +52,7 @@ interface Props {
onOpenLogs(channel: string): void
}

const Level = ({
tutorial,
index,
status,
progress,
position,
onContinue,
onRunTest,
onLoadSolution,
onOpenLogs,
processes,
testStatus,
}: Props) => {
const level: TT.Level = tutorial.levels[index]

const Level = ({ level, progress, position, onLoadSolution, currentStep, testStatus }: Props) => {
// hold state for hints for the level
const [displayHintsIndex, setDisplayHintsIndex] = React.useState<number[]>([])
const setHintsIndex = (index: number, value: number) => {
Expand All @@ -117,10 +64,10 @@ const Level = ({
}
React.useEffect(() => {
// set the hints to empty on level starts
setDisplayHintsIndex(steps.map((s) => -1))
setDisplayHintsIndex(level.steps.map((s: TT.Step) => -1))
}, [position.levelId])

const steps: Array<TT.Step & { status: T.ProgressStatus }> = level.steps.map((step: TT.Step) => {
const steps: TT.Step[] = level.steps.map((step: TT.Step) => {
// label step status for step component
let status: T.ProgressStatus = 'INCOMPLETE'
if (progress.steps[step.id]) {
Expand All @@ -132,10 +79,6 @@ const Level = ({
})

// current
let currentStep = steps.findIndex((s) => s.status === 'ACTIVE')
if (currentStep === -1) {
currentStep = steps.length
}

const pageBottomRef = React.useRef(null)
const scrollToBottom = () => {
Expand All @@ -159,7 +102,7 @@ const Level = ({
{steps.length ? (
<div css={styles.tasks}>
<div css={styles.steps}>
{steps.map((step: (TT.Step & { status: T.ProgressStatus }) | null, stepIndex: number) => {
{steps.map((step: TT.Step | null, stepIndex: number) => {
if (!step) {
return null
}
Expand All @@ -173,8 +116,7 @@ const Level = ({
return (
<Step
key={step.id}
index={index}
status={step.status}
status={step.status || 'INCOMPLETE'}
content={step.content}
onLoadSolution={onLoadSolution}
subtasks={subtasks}
Expand All @@ -189,38 +131,6 @@ const Level = ({
) : null}

<div ref={pageBottomRef} />

<div css={styles.footer}>
{/* Process Modal */}
{processes.length > 0 && (
<div css={styles.processes}>
<ProcessMessages processes={processes} />
</div>
)}
{/* Test Fail Modal */}
{testStatus && testStatus.type === 'warning' && (
<div css={styles.testMessage}>
<TestMessage message={testStatus.title} />
</div>
)}

{DISPLAY_RUN_TEST_BUTTON && status !== 'COMPLETE' ? (
<Button type="primary" onClick={onRunTest} disabled={processes.length > 0}>
Run
</Button>
) : null}
<span>
{status === 'COMPLETE' || !steps.length ? (
<Button type="primary" onClick={onContinue}>
Continue
</Button>
) : (
<span css={styles.taskCount}>
{currentStep} of {steps.length} tasks
</span>
)}
</span>
</div>
</div>
</div>
)
Expand Down
15 changes: 8 additions & 7 deletions web-app/src/containers/Tutorial/components/SideMenu.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ const styles = {
interface Props {
visible: boolean
toggleVisible(visible: boolean): void
page: 'level' | 'settings' | 'review'
setPage(page: 'level' | 'settings' | 'review'): void
}

const SideMenu = (props: Props) => {
Expand All @@ -35,17 +37,16 @@ const SideMenu = (props: Props) => {
onClose={onMenuClose}
>
<Menu style={styles.menu} defaultOpenKeys="sub-menu">
<Item disabled key="1">
<Item key="level" disabled={props.page === 'level'} onClick={() => props.setPage('level')}>
<Icon type="detail" size="small" color="#EBEBEB" />
<span style={styles.itemText}>Level</span>
</Item>
<Item key="review" disabled={props.page === 'review'} onClick={() => props.setPage('review')}>
<Icon type="list" size="small" color="#EBEBEB" />
<span style={styles.itemText}>Review</span>
</Item>
{/* <Divider key="divider" />
<Item disabled key="2">
<Icon type="help" size="small" color="#EBEBEB" />
<span style={styles.itemText}>Help</span>
</Item> */}
<Divider key="divider" />
<Item disabled key="3">
<Item key="settings" disabled={props.page === 'settings'} onClick={() => props.setPage('review')}>
<Icon type="set" size="small" color="#EBEBEB" />
<span style={styles.itemText}>Settings</span>
</Item>
Expand Down
3 changes: 0 additions & 3 deletions web-app/src/containers/Tutorial/components/Step.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,10 @@ import * as React from 'react'
import * as T from 'typings'
import { css, jsx } from '@emotion/core'
import TestStatusIcon from './TestStatusIcon'
import Icon from '../../../components/Icon'
import Hints from './Hints'
import Markdown from '../../../components/Markdown'

interface Props {
index: number
content: string
status: T.ProgressStatus
subtasks: { name: string; pass: boolean }[] | null
Expand Down Expand Up @@ -76,7 +74,6 @@ const Step = (props: Props) => {
return (
<li key={subtask.name} css={styles.subtask}>
<TestStatusIcon size="xs" status={subtaskStatus} />

<span style={{ marginLeft: '0.5rem' }}>{subtask.name}</span>
</li>
)
Expand Down
13 changes: 13 additions & 0 deletions web-app/src/containers/Tutorial/containers/Review.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import * as React from 'react'

const styles = {
container: {
padding: '1rem',
},
}

const ReviewPage = () => {
return <div css={styles.container}>Review Coming soon...</div>
}

export default ReviewPage
13 changes: 13 additions & 0 deletions web-app/src/containers/Tutorial/containers/Settings.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import * as React from 'react'

const styles = {
container: {
padding: '1rem',
},
}

const SettingsPage = () => {
return <div css={styles.container}>Settings coming soon...</div>
}

export default SettingsPage
125 changes: 106 additions & 19 deletions web-app/src/containers/Tutorial/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,12 @@ import * as selectors from '../../services/selectors'
import SideMenu from './components/SideMenu'
import Level from './components/Level'
import Icon from '../../components/Icon'
import SettingsPage from './containers/Settings'
import ReviewPage from './containers/Review'
import Button from '../../components/Button'
import ProcessMessages from '../../components/ProcessMessages'
import TestMessage from '../../components/TestMessage'
import { DISPLAY_RUN_TEST_BUTTON } from '../../environment'

const styles = {
header: {
Expand All @@ -24,6 +30,41 @@ const styles = {
textDecoration: 'none',
color: 'inherit',
},
footer: {
display: 'flex' as 'flex',
flexDirection: 'row' as 'row',
justifyContent: 'space-between',
alignItems: 'center',
height: '2rem',
backgroundColor: 'black',
fontSize: '1rem',
lineHeight: '1rem',
padding: '10px 1rem',
position: 'fixed' as 'fixed',
bottom: 0,
left: 0,
right: 0,
color: 'white',
},
taskCount: {
fontSize: '0.8rem',
opacity: 0.9,
},
processes: {
padding: '0 1rem',
position: 'fixed' as 'fixed',
bottom: '2rem',
left: 0,
right: 0,
top: 'auto',
},
testMessage: {
position: 'absolute' as 'absolute',
top: 'auto',
bottom: '2rem',
left: '5px',
right: '5px',
},
}

interface PageProps {
Expand Down Expand Up @@ -59,30 +100,76 @@ const TutorialPage = (props: PageProps) => {

const levelIndex = tutorial.levels.findIndex((l: TT.Level) => l.id === position.levelId)
const levelStatus = progress.levels[position.levelId] ? 'COMPLETE' : 'ACTIVE'
const level: TT.Level = tutorial.levels[levelIndex]
const [menuVisible, setMenuVisible] = React.useState(false)

const [page, setPage] = React.useState<'level' | 'settings' | 'review'>('level')

let currentStep = level.steps.findIndex((s: TT.Step) => s.status === 'ACTIVE')
if (currentStep === -1) {
currentStep = level.steps.length
}

return (
<div>
<div css={styles.header}>
<a onClick={() => setMenuVisible(!menuVisible)}>
<Icon type="toggle-left" size="small" />
</a>
<span css={styles.title}>{tutorial.summary.title}</span>
<div>
<div css={styles.header}>
<a onClick={() => setMenuVisible(!menuVisible)}>
<Icon type="toggle-left" size="small" />
</a>
<span css={styles.title}>{tutorial.summary.title}</span>
</div>

{page === 'level' && (
<Level
level={level}
currentStep={currentStep}
status={levelStatus}
progress={progress}
position={position}
onContinue={onContinue}
onRunTest={onRunTest}
onLoadSolution={onLoadSolution}
onOpenLogs={onOpenLogs}
processes={processes}
testStatus={testStatus}
/>
)}
{page === 'settings' && <SettingsPage />}
{page === 'review' && <ReviewPage />}
</div>
<div css={styles.footer}>
{/* Process Modal */}
{processes.length > 0 && (
<div css={styles.processes}>
<ProcessMessages processes={processes} />
</div>
)}
{/* Test Fail Modal */}
{testStatus && testStatus.type === 'warning' && (
<div css={styles.testMessage}>
<TestMessage message={testStatus.title} />
</div>
)}

{DISPLAY_RUN_TEST_BUTTON && levelStatus !== 'COMPLETE' ? (
<Button type="primary" onClick={onRunTest} disabled={processes.length > 0}>
Run
</Button>
) : null}
<span>
{levelStatus === 'COMPLETE' || !level.steps.length ? (
<Button type="primary" onClick={onContinue}>
Continue
</Button>
) : (
<span css={styles.taskCount}>
{currentStep} of {level.steps.length} tasks
</span>
)}
</span>
</div>
<Level
tutorial={tutorial}
index={levelIndex}
status={levelStatus}
progress={progress}
position={position}
onContinue={onContinue}
onRunTest={onRunTest}
onLoadSolution={onLoadSolution}
onOpenLogs={onOpenLogs}
processes={processes}
testStatus={testStatus}
/>
<SideMenu visible={menuVisible} toggleVisible={setMenuVisible} />
<SideMenu visible={menuVisible} toggleVisible={setMenuVisible} page={page} setPage={setPage} />
</div>
)
}
Expand Down
Loading