Skip to content

Commit 8b6499b

Browse files
committed
refactor tutorial paths
1 parent cb9f82e commit 8b6499b

File tree

9 files changed

+47
-40
lines changed

9 files changed

+47
-40
lines changed

src/editor/commands/index.ts

+1-3
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,6 @@ import { setStorage } from '../storage'
44
import ReactWebView from '../ReactWebView'
55
import { isEmptyWorkspace } from '../workspace'
66
import * as CR from 'typings'
7-
// TODO: replace with actual tutorial loading later
8-
import tutorial from '../../state/context/tutorials/basic'
97

108
const COMMANDS = {
119
START: 'coderoad.start',
@@ -46,7 +44,7 @@ export const createCommands = ({ context, machine, storage, git, position }: Cre
4644
},
4745
// launch a new tutorial
4846
// NOTE: may be better to move into action as logic is primarily non-vscode
49-
[COMMANDS.TUTORIAL_LAUNCH]: async () => {
47+
[COMMANDS.TUTORIAL_LAUNCH]: async (tutorial: CR.Tutorial) => {
5048
console.log('launch tutorial')
5149

5250
await isEmptyWorkspace()

src/services/api/fetch.ts

-32
This file was deleted.

src/services/api/index.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import * as CR from 'typings'
22

33
// temporary tutorials
4-
import basicTutorial from '../../state/context/tutorials/basic'
4+
import basicTutorial from 'tutorials/basic'
55

66
interface Options {
77
resource: string

src/state/actions/index.ts

+5-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import { assign } from 'xstate'
22
// NOTE: codesmell - importing machine
33
import { machine } from '../../extension'
4+
import api from '../../services/api'
45
import * as CR from 'typings'
56
import * as vscode from 'vscode'
67
import * as storage from '../../services/storage'
@@ -37,8 +38,10 @@ export default {
3738

3839
machine.send(canContinue ? 'CONTINUE' : 'NEW')
3940
},
40-
tutorialLaunch() {
41-
vscode.commands.executeCommand('coderoad.tutorial_launch')
41+
async tutorialLaunch() {
42+
// TODO: add selection of tutorial id
43+
const tutorial: CR.Tutorial = await api({ resource: 'getTutorial', params: { id: '1' } })
44+
vscode.commands.executeCommand('coderoad.tutorial_launch', tutorial)
4245
},
4346
tutorialContinue: assign({
4447
// load initial data, progress & position

src/state/context/index.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import basicTutorialData from './tutorials/basic'
1+
import basicTutorialData from 'tutorials/basic'
22
import * as CR from 'typings'
33

44
const tutorialContext: CR.MachineContext = {

tsconfig.json

+4-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
"dom"
99
],
1010
"sourceMap": true,
11-
"rootDir": "src",
11+
"rootDirs": ["src", "tutorials"],
1212
"baseUrl": "src",
1313
"strict": true, /* enable all strict type-checking options */
1414
/* Additional Checks */
@@ -23,6 +23,9 @@
2323
"emitDecoratorMetadata": true,
2424
"paths": {
2525
"typings": ["../typings/index.d.ts"],
26+
"tutorials/basic": [
27+
"../tutorials/basic.ts"
28+
]
2629
},
2730
},
2831
"exclude": [
File renamed without changes.

web-app/src/services/api/index.tsx

+32
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
import * as CR from 'typings'
2+
3+
// temporary tutorials
4+
import basicTutorial from 'tutorials/basic'
5+
6+
interface Options {
7+
resource: string
8+
params?: any
9+
}
10+
11+
const tutorialsData: { [key: string]: CR.Tutorial } = {
12+
tutorialId: basicTutorial,
13+
}
14+
15+
// TODO: replace with fetch resource
16+
export default async function fetch(options: Options): Promise<any> {
17+
console.log('options', options)
18+
switch (options.resource) {
19+
case 'getTutorialsSummary':
20+
// list of ids with summaries
21+
let data: { [id: string]: CR.TutorialSummary } = {}
22+
for (const tutorial of Object.values(tutorialsData)) {
23+
data[tutorial.id] = tutorial.data.summary
24+
}
25+
return data
26+
case 'getTutorial':
27+
// specific tutorial by id
28+
return tutorialsData[options.params.id]
29+
default:
30+
throw new Error('Resource not found')
31+
}
32+
}

web-app/tsconfig.paths.json

+3
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,9 @@
99
"typings": [
1010
"../../typings/index.d.ts"
1111
],
12+
"tutorials/basic": [
13+
"../../tutorials/basic.ts"
14+
]
1215
}
1316
},
1417
"exclude": [

0 commit comments

Comments
 (0)