8000 Merge pull request #38 from ShMcK/feature/solution-actions · coderoad/coderoad-vscode@d76dcdb · GitHub
[go: up one dir, main page]

Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit d76dcdb

Browse files
authored
Merge pull request #38 from ShMcK/feature/solution-actions
Feature/solution actions
2 parents 6b14921 + 6bf73c9 commit d76dcdb

File tree

11 files changed

+83
-32
lines changed

11 files changed

+83
-32
lines changed

src/actions/solutionActions.ts

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,11 @@
1-
// import * as CR from 'typings'
21
import * as G from 'typings/graphql'
3-
// import {TutorialModel} from '../services/tutorial'
4-
// import {gitLoadCommits, gitClear} from '../services/git'
5-
6-
const solutionActions = async (stepActions: G.StepActions): Promise<void> => {
7-
// TODO: should load same as commits
8-
9-
// const step: G.Step = tutorialModel.step()
10-
// const solution = step.solution
11-
12-
// await gitClear()
13-
// await gitLoadCommits(solution, dispatch)
2+
import * as vscode from 'vscode'
3+
import * as git from '../services/git'
4+
import setupActions from './setupActions'
145

6+
const solutionActions = async (workspaceRoot: vscode.WorkspaceFolder, stepActions: G.StepActions): Promise<void> => {
7+
await git.clear()
8+
return setupActions(workspaceRoot, stepActions)
159
}
1610

1711
export default solutionActions

src/channel/index.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,9 @@ class Channel implements Channel {
105105
return
106106
// load solution step actions (git commits, commands, open files)
107107
case 'SOLUTION_ACTIONS':
108-
solutionActions(action.payload)
108+
await solutionActions(this.workspaceRoot, action.payload)
109+
// run test following solution to update position
110+
vscode.commands.executeCommand('coderoad.run_test', action.payload)
109111
return
110112

111113
default:

src/channel/state/Progress.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ class Progress {
3333
public set = (value: CR.Progress) => {
3434
this.value = value
3535
if (!this.storage) {
36-
throw new Error('Tutorial storage not found')
36+
return defaultValue
3737
}
3838
this.storage.set(value)
3939
return this.value

typings/graphql.d.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,7 @@ export type Stage = {
136136
step?: Maybe<Step>,
137137
steps: Array<Step>,
138138
setup?: Maybe<StepActions>,
139-
status: string
139+
status: 'ACTIVE' | 'COMPLETE' | 'INCOMPLETE'
140140
};
141141

142142

@@ -151,8 +151,8 @@ export type Step = {
151151
text: Scalars['String'],
152152
setup: StepActions,
153153
solution: StepActions,
154-
status: string
155-
};
154+
status: 'ACTIVE' | 'COMPLETE' | 'INCOMPLETE'
155+
}
156156

157157
export type StepActions = {
158158
__typename?: 'StepActions',

web-app/src/App.tsx

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,16 @@
11
import * as React from 'react'
22
import { ApolloProvider } from '@apollo/react-hooks'
33

4+
import ErrorBoundary from './components/ErrorBoundary'
45
import client from './services/apollo'
56
import Routes from './Routes'
67

78
const App = () => (
8-
<ApolloProvider client={client}>
9-
<Routes />
10-
</ApolloProvider>
9+
<ErrorBoundary>
10+
<ApolloProvider client={client}>
11+
<Routes />
12+
</ApolloProvider>
13+
</ErrorBoundary>
1114
)
1215

1316
export default App
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
import * as React from 'react'
2+
3+
class ErrorBoundary extends React.Component {
4+
public state = { hasError: false }
5+
6+
public componentDidCatch(error: Error, info: any) {
7+
// Display fallback UI
8+
this.setState({ hasError: true })
9+
// You can also log the error to an error reporting service
10+
console.error(error)
11+
console.log(info)
12+
}
13+
14+
public render() {
15+
if (this.state.hasError) {
16+
// You can render any custom fallback UI
17+
return <h1>Something went wrong.</h1>
18+
}
19+
return this.props.children
20+
}
21+
}
22+
23+
export default ErrorBoundary

web-app/src/containers/Tutorial/StagePage/Stage/StepDescription/index.tsx

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import * as React from 'react'
22
import Markdown from '../../../../../components/Markdown'
3+
import { Button } from '@alifd/next'
34

45
const styles = {
56
// active: {
@@ -12,16 +13,29 @@ const styles = {
1213

1314
interface Props {
1415
text?: string | null
15-
hide: boolean
16+
mode: 'INCOMPLETE' | 'ACTIVE' | 'COMPLETE'
17+
onLoadSolution(): void
1618
}
1719

18-
const StepDescription = ({ text, hide }: Props) => {
19-
if (hide) {
20+
const StepDescription = ({ text, mode, onLoadSolution }: Props) => {
21+
const [loadedSolution, setLoadedSolution] = React.useState()
22+
23+
const onClickHandler = () => {
24+
if (!loadedSolution) {
25+
setLoadedSolution(true)
26+
onLoadSolution()
27+
}
28+
}
29+
30+
if (mode === 'INCOMPLETE') {
2031
return null
2132
}
33+
34+
const showLoadSolution = mode === 'ACTIVE' && !loadedSolution
2235
return (
2336
<div style={styles.card}>
2437
<Markdown>{text || ''}</Markdown>
38+
{showLoadSolution && <Button onClick={onClickHandler}>Load Solution</Button>}
2539
</div>
2640
)
2741
}

web-app/src/containers/Tutorial/StagePage/Stage/index.tsx

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -24,11 +24,12 @@ const styles = {
2424

2525
interface Props {
2626
stage: T.Stage
27-
onContinue(): void
28-
onSave(): void
27+
onContinue(): void
28+
onSave(): void
29+
onLoadSolution(): void
2930
}
3031

31-
const Stage = ({ stage, onContinue, onSave }: Props) => {
32+
const Stage = ({ stage, onContinue, onSave, onLoadSolution }: Props) => {
3233
if (!stage.steps) {
3334
throw new Error('No Stage steps found')
3435
}
@@ -50,12 +51,11 @@ const Stage = ({ stage, onContinue, onSave }: Props) => {
5051
if (!step) {
5152
return null
5253
}
53-
const hide = step.status === 'INCOMPLETE'
5454
return (
5555
<Step.Item
5656
key={step.id}
5757
title={step.title || `Step ${index + 1}`}
58-
content={<StepDescription text={step.text} hide={hide} />}
58+
content={<StepDescription text={step.text} mode={step.status} onLoadSolution={onLoadSolution} />}
5959
/>
6060
)
6161
})}
@@ -67,10 +67,10 @@ const Stage = ({ stage, onContinue, onSave }: Props) => {
6767
<Button onClick={onContinue}>Continue</Button>
6868
</div>
6969
) : (
70-
<div style={styles.options}>
70+
<div style={styles.options}>
7171
<Button onClick={onSave}>Save</Button>
7272
</div>
73-
)}
73+
)}
7474
</div>
7575
)
7676
}

web-app/src/containers/Tutorial/StagePage/index.tsx

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,10 @@ const StageSummaryPageContainer = (props: PageProps) => {
3333
})
3434
}
3535

36+
const onLoadSolution = (): void => {
37+
props.send({ type: 'STEP_SOLUTION_LOAD' })
38+
}
39+
3640
stage.steps.forEach((step: G.Step) => {
3741
if (progress.steps[step.id]) {
3842
step.status = 'COMPLETE'
@@ -44,7 +48,7 @@ const StageSummaryPageContainer = (props: PageProps) => {
4448
})
4549
stage.status = progress.stages[position.stageId] ? 'COMPLETE' : 'ACTIVE'
4650

47-
return <Stage stage={stage} onContinue={onContinue} onSave={onSave} />
51+
return <Stage stage={stage} onContinue={onContinue} onSave={onSave} onLoadSolution={onLoadSolution} />
4852
}
4953

5054
export default StageSummaryPageContainer

web-app/src/services/state/actions/editor.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,17 @@ export default {
9797
})
9898
}
9999
},
100+
editorLoadSolution(context: CR.MachineContext): void {
101+
const step: G.Step = selectors.currentStep(context)
102+
// tell editor to load solution commit
103+
channel.editorSend({
104+
type: 'SOLUTION_ACTIONS',
105+
payload: {
106+
stepId: step.id,
107+
...step.solution,
108+
}
109+
})
110+
},
100111
clearStorage(): void {
101112
channel.editorSend({type: 'TUTORIAL_CLEAR'})
102113
}

0 commit comments

Comments
 (0)
0