Skip to content

Feature/key bindings #391

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 6 commits into from
Jul 18, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
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
7 changes: 7 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,13 @@
"title": "Start",
"category": "CodeRoad"
}
],
"keybindings": [
{
"key": "ctrl+enter",
"mac": "ctrl+enter",
"command": "coderoad.enter"
}
]
},
"displayName": "CodeRoad",
Expand Down
4 changes: 4 additions & 0 deletions src/editor/commands.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ export const COMMANDS = {
CONFIG_TEST_RUNNER: 'coderoad.config_test_runner',
RUN_TEST: 'coderoad.run_test',
SET_CURRENT_POSITION: 'coderoad.set_current_position',
ENTER: 'coderoad.enter',
}

interface CreateCommandProps {
Expand Down Expand Up @@ -103,5 +104,8 @@ export const createCommands = ({ extensionPath, workspaceState }: CreateCommandP
logger('currentPosition', currentPosition)
testRunner({ position: currentPosition, onSuccess: callbacks?.onSuccess, subtasks })
},
[COMMANDS.ENTER]: () => {
webview.send({ type: 'KEY_PRESS_ENTER' })
},
}
}
2 changes: 1 addition & 1 deletion web-app/src/Routes.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ const Routes = () => {
<LoadingPage text="Loading Level..." processes={context.processes} />
</Route>
<Route paths={{ Tutorial: { Level: true } }}>
<TutorialPage send={send} context={context} />
<TutorialPage send={send} context={context} state={route.replace('Tutorial.Level.', '')} />
</Route>
{/* Completed */}
<Route paths={{ Tutorial: { Completed: true } }}>
Expand Down
12 changes: 9 additions & 3 deletions web-app/src/containers/Tutorial/components/Continue.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import * as React from 'react'
import { Dialog } from '@alifd/next'
import { Dialog, Icon } from '@alifd/next'
import { css, jsx } from '@emotion/core'
import Button from '../../../components/Button'
import ProgressPie from './ProgressPie'
Expand All @@ -14,17 +14,21 @@ const styles = {
message: {
textAlign: 'center' as 'center',
},
buttonSubtext: {
padding: '0.5rem',
},
}

interface Props {
title: string
current: number // level index
max: number // level count
defaultOpen: boolean
onContinue(): void
}

const Continue = (props: Props) => {
const [modalState, setModalState] = React.useState<'closed' | 'open'>('closed')
const [modalState, setModalState] = React.useState<'closed' | 'open'>(props.defaultOpen ? 'open' : 'closed')

const onClose = () => {
setModalState('closed')
Expand Down Expand Up @@ -57,8 +61,10 @@ const Continue = (props: Props) => {
<h3>{props.title}</h3>
<br />
<Button type="primary" size="large" onClick={onContinue}>
Continue
Continue&nbsp;&nbsp;
<Icon type="arrow-right" />
</Button>
<div css={styles.buttonSubtext}>(ctrl + enter)</div>
</div>
</div>
</Dialog>
Expand Down
24 changes: 17 additions & 7 deletions web-app/src/containers/Tutorial/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ import TestMessage from '../../components/TestMessage'
import StepProgress from './components/StepProgress'
import { DISPLAY_RUN_TEST_BUTTON } from '../../environment'
import formatLevels from './formatLevels'
// import SettingsPage from './containers/Settings'
import Reset from './components/Reset'
import Continue from './components/Continue'

Expand Down Expand Up @@ -69,6 +68,7 @@ const styles = {
interface PageProps {
context: T.MachineContext
send(action: T.Action): void
state: string // 'Normal' | 'TestRunning' | 'TestFail' | 'TestPass' | 'LevelComplete'
}

/**
Expand All @@ -85,9 +85,6 @@ const TutorialPage = (props: PageProps) => {
const onContinue = (): void => {
props.send({
type: 'NEXT_LEVEL',
payload: {
levelId: position.levelId,
},
})
}

Expand All @@ -111,6 +108,8 @@ const TutorialPage = (props: PageProps) => {
testStatus,
})

const disableOptions = processes.length > 0 || props.state === 'TestRunning'

return (
<div>
<div>
Expand Down Expand Up @@ -141,26 +140,37 @@ const TutorialPage = (props: PageProps) => {
{/* Left */}
<div css={{ flex: 1 }}>
{DISPLAY_RUN_TEST_BUTTON && level.status !== 'COMPLETE' ? (
<Button style={{ marginLeft: '1rem' }} type="primary" onClick={onRunTest} disabled={processes.length > 0}>
<Button style={{ marginLeft: '1rem' }} type="primary" onClick={onRunTest} disabled={disableOptions}>
Run
</Button>
) : null}
</div>

{/* Center */}
<div css={{ flex: 1, display: 'flex', justifyContent: 'center' }}>
<Reset onReset={onReset} disabled={processes.length > 0} />
<Reset onReset={onReset} disabled={disableOptions || props.state === 'LevelComplete'} />
</div>

{/* Right */}
<div css={{ flex: 1, display: 'flex', justifyContent: 'flex-end' }}>
{level.status === 'COMPLETE' || !level.steps.length ? (
{!level.steps.length ? (
<div css={{ marginRight: '0.5rem' }}>
<Continue
onContinue={onContinue}
current={levelIndex + 1}
max={levels.length}
title={tutorial.summary.title}
defaultOpen={false}
/>
</div>
) : props.state === 'LevelComplete' ? (
<div css={{ marginRight: '0.5rem' }}>
<Continue
onContinue={onContinue}
current={levelIndex + 1}
max={levels.length}
title={tutorial.summary.title}
defaultOpen={true}
/>
</div>
) : level.steps.length > 1 ? (
Expand Down
2 changes: 1 addition & 1 deletion web-app/src/environment.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,4 @@ export const TUTORIAL_LIST_URL: string = process.env.REACT_APP_TUTORIAL_LIST_URL
export const SENTRY_DSN: string | null = process.env.REACT_APP_SENTRY_DSN || null

// config variables
export const DISPLAY_RUN_TEST_BUTTON = (process.env.CODEROAD_DISPLAY_RUN_TEST_BUTTON || '').toLowerCase() === 'true'
export const DISPLAY_RUN_TEST_BUTTON = (process.env.CODEROAD_DISPLAY_RUN_TEST_BUTTON || 'true').toLowerCase() === 'true'
7 changes: 7 additions & 0 deletions web-app/src/services/state/actions/context.ts
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,13 @@ const contextActions: ActionFunctionMap<T.MachineContext, T.MachineEvent> = {
return event.payload
},
}),
// @ts-ignore
updateLevel: assign({
position: (context: T.MachineContext, event: T.MachineEvent): any => {
const levelId = context.position.levelId
return { levelId }
},
}),
loadNext: send(
(context: T.MachineContext): T.Action => {
const { position, progress } = context
Expand Down
9 changes: 8 additions & 1 deletion web-app/src/services/state/machine.ts
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,9 @@ export const createMachine = (options: any) => {
RUN_RESET: {
actions: ['runReset'],
},
KEY_PRESS_ENTER: {
actions: ['runTest'],
},
},
},
TestRunning: {
Expand Down Expand Up @@ -217,7 +220,11 @@ export const createMachine = (options: any) => {
on: {
NEXT_LEVEL: {
target: 'LoadNext',
actions: ['testClear', 'updatePosition'],
actions: ['testClear', 'updateLevel'],
},
KEY_PRESS_ENTER: {
target: 'LoadNext',
actions: ['testClear', 'updateLevel'],
},
},
},
Expand Down