10000 update typings for node processes · coderoad/coderoad-vscode@4d2cfd6 · GitHub
[go: up one dir, main page]

Skip to content

Commit 4d2cfd6

Browse files
committed
update typings for node processes
1 parent 06f1285 commit 4d2cfd6

File tree

11 files changed

+129
-55
lines changed
  • editor
  • web-app/stories
  • 11 files changed

    +129
    -55
    lines changed

    src/actions/setupActions.ts

    Lines changed: 2 additions & 1 deletion
    Original file line numberDiff line numberDiff line change
    @@ -1,4 +1,5 @@
    11
    import * as T from 'typings'
    2+
    import * as TT from 'typings/tutorial'
    23
    import * as vscode from 'vscode'
    34
    import * as git from '../services/git'
    45
    import loadWatchers from './utils/loadWatchers'
    @@ -8,7 +9,7 @@ import onError from '../services/sentry/onError'
    89

    910
    const setupActions = async (
    1011
    workspaceRoot: vscode.WorkspaceFolder,
    11-
    actions: T.StepActions,
    12+
    actions: TT.StepActions,
    1213
    send: (action: T.Action) => void, // send messages to client
    1314
    ): Promise<void> => {
    1415
    const { commands, commits, files, watchers } = actions

    src/actions/solutionActions.ts

    Lines changed: 2 additions & 1 deletion
    Original file line numberDiff line numberDiff line change
    @@ -1,12 +1,13 @@
    11
    import * as T from 'typings'
    2+
    import * as TT from 'typings/tutorial'
    23
    import * as vscode from 'vscode'
    34
    import * as git from '../services/git'
    45
    import setupActions from './setupActions'
    56
    import onError from '../services/sentry/onError'
    67

    78
    const solutionActions = async (
    89
    workspaceRoot: vscode.WorkspaceFolder,
    9-
    stepActions: T.StepActions,
    10+
    stepActions: TT.StepActions,
    1011
    send: (action: T.Action) => void,
    1112
    ): Promise<void> => {
    1213
    await git.clear()

    src/actions/tutorialConfig.ts

    Lines changed: 2 additions & 3 deletions
    Original file line numberDiff line numberDiff line change
    @@ -1,13 +1,12 @@
    11
    import * as T from 'typings'
    2-
    import * as G from 'typings/graphql'
    2+
    import * as TT from 'typings/tutorial'
    33
    import * as vscode from 'vscode'
    44
    import { COMMANDS } from '../editor/commands'
    5-
    import languageMap from '../editor/languageMap'
    65
    import * as git from '../services/git'
    76
    import onError from '../services/sentry/onError'
    87

    98
    interface TutorialConfigParams {
    10-
    config: T.TutorialConfig
    9+
    config: TT.TutorialConfig
    1110
    alreadyConfigured?: boolean
    1211
    onComplete?(): void
    1312
    }

    src/channel/context.ts

    Lines changed: 2 additions & 2 deletions
    Original file line numberDiff line numberDiff line change
    @@ -1,5 +1,5 @@
    11
    import * as CR from 'typings'
    2-
    import * as G from 'typings/graphql'
    2+
    import * as TT from 'typings/tutorial'
    33
    import * as vscode from 'vscode'
    44
    import Position from './state/Position'
    55
    import Progress from './state/Progress'
    @@ -17,7 +17,7 @@ class Context {
    1717
    }
    1818
    public setTutorial = async (
    1919
    workspaceState: vscode.Memento,
    20-
    tutorial: G.Tutorial,
    20+
    tutorial: TT.Tutorial,
    2121
    ): Promise<{ progress: CR.Progress; position: CR.Position }> => {
    2222
    this.tutorial.set(tutorial)
    2323
    const progress: CR.Progress = await this.progress.setTutorial(workspaceState, tutorial)

    src/channel/index.ts

    Lines changed: 8 additions & 8 deletions
    Original file line numberDiff line numberDiff line change
    @@ -1,5 +1,5 @@
    11
    import * as T from 'typings'
    2-
    import * as G from 'typings/graphql'
    2+
    import * as TT from 'typings/tutorial'
    33
    import * as vscode from 'vscode'
    44
    import saveCommit from '../actions/saveCommit'
    55
    import setupActions from '../actions/setupActions'
    @@ -54,10 +54,10 @@ class Channel implements Channel {
    5454
    return
    5555
    // continue from tutorial from local storage
    5656
    case 'EDITOR_TUTORIAL_LOAD':
    57-
    const tutorial: G.Tutorial | null = this.context.tutorial.get()
    57+
    const tutorial: TT.Tutorial | null = this.context.tutorial.get()
    5858

    5959
    // new tutorial
    60-
    if (!tutorial || !tutorial.id || !tutorial.version) {
    60+
    if (!tutorial || !tutorial.id) {
    6161
    this.send({ type: 'START_NEW_TUTORIAL' })
    6262
    return
    6363
    }
    @@ -81,23 +81,23 @@ class Channel implements Channel {
    8181
    return
    8282
    // configure test runner, language, git
    8383
    case 'EDITOR_TUTORIAL_CONFIG':
    84-
    const tutorialData: G.Tutorial = action.payload.tutorial
    84+
    const tutorialData: TT.Tutorial = action.payload.tutorial
    8585
    // setup tutorial config (save watcher, test runner, etc)
    8686
    this.context.setTutorial(this.workspaceState, tutorialData)
    8787

    88-
    const data: G.TutorialData = tutorialData.version.data
    88+
    const data: TT.TutorialData = tutorialData.data
    8989

    9090
    await tutorialConfig({ config: data.config }, onError)
    9191

    9292
    // report back to the webview that setup is complete
    9393
    this.send({ type: 'TUTORIAL_CONFIGURED' })
    9494
    return
    9595
    case 'EDITOR_TUTORIAL_CONTINUE_CONFIG':
    96-
    const tutorialContinue: G.Tutorial | null = this.context.tutorial.get()
    96+
    const tutorialContinue: TT.Tutorial | null = this.context.tutorial.get()
    9797
    if (!tutorialContinue) {
    9898
    throw new Error('Invalid tutorial to continue')
    9999
    }
    100-
    const continueConfig: T.TutorialConfig = tutorialContinue.version.data.config
    100+
    const continueConfig: TT.TutorialConfig = tutorialContinue.data.config
    101101
    await tutorialConfig(
    102102
    {
    103103
    config: continueConfig,
    @@ -148,7 +148,7 @@ class Channel implements Channel {
    148148
    throw new Error('Error with current tutorial')
    149149
    }
    150150
    // update local storage stepProgress
    151-
    const progress = this.context.progress.setStepComplete(tutorial.version.data, action.payload.stepId)
    151+
    const progress = this.context.progress.setStepComplete(tutorial.data, action.payload.stepId)
    152152
    this.context.position.setPositionFromProgress(tutorial, progress)
    153153
    saveCommit()
    154154
    }

    src/channel/state/Position.ts

    Lines changed: 7 additions & 7 deletions
    Original file line numberDiff line numberDiff line change
    @@ -1,5 +1,5 @@
    11
    import * as CR from 'typings'
    2-
    import * as G from 'typings/graphql'
    2+
    import * as TT from 'typings/tutorial'
    33

    44
    const defaultValue: CR.Position = {
    55
    levelId: '',
    @@ -22,34 +22,34 @@ class Position {
    2222
    this.value = defaultValue
    2323
    }
    2424
    // calculate the current position based on the saved progress
    25-
    public setPositionFromProgress = (tutorial: G.Tutorial, progress: CR.Progress): CR.Position => {
    25+
    public setPositionFromProgress = (tutorial: TT.Tutorial, progress: CR.Progress): CR.Position => {
    2626
    // tutorial already completed
    2727
    // TODO handle start again?
    2828
    if (progress.complete) {
    2929
    return this.value
    3030
    }
    3131

    32-
    if (!tutorial || !tutorial.version || !tutorial.version.data || !tutorial.version.data.levels) {
    32+
    if (!tutorial || !tutorial.data || !tutorial.data.levels) {
    3333
    throw new Error('Error setting position from progress')
    3434
    }
    3535

    3636
    // get level
    37-
    const { levels } = tutorial.version.data
    38-
    const lastLevelIndex: number | undefined = levels.findIndex((l: G.Level) => !progress.levels[l.id])
    37+
    const { levels } = tutorial.data
    38+
    const lastLevelIndex: number | undefined = levels.findIndex((l: TT.Level) => !progress.levels[l.id])
    3939
    if (lastLevelIndex >= levels.length) {
    4040
    throw new Error('Error setting progress level')
    4141
    }
    4242

    4343
    // get step
    44-
    const currentLevel: G.Level = levels[lastLevelIndex]
    44+
    const currentLevel: TT.Level = levels[lastLevelIndex]
    4545
    let currentStepId: string | null
    4646
    if (!currentLevel.steps.length) {
    4747
    // no steps available for level
    4848
    currentStepId = null
    4949
    } else {
    5050
    // find current step id
    5151
    const { steps } = currentLevel
    52-
    const lastStepIndex: number | undefined = steps.findIndex((s: G.Step) => !progress.steps[s.id])
    52+
    const lastStepIndex: number | undefined = steps.findIndex((s: TT.Step) => !progress.steps[s.id])
    5353
    if (lastStepIndex >= steps.length) {
    5454
    throw new Error('Error setting progress step')
    5555
    }

    src/channel/state/Progress.ts

    Lines changed: 2 additions & 2 deletions
    Original file line numberDiff line numberDiff line change
    @@ -1,5 +1,5 @@
    11
    import * as CR from 'typings'
    2-
    import * as G from 'typings/graphql'
    2+
    import * as TT from 'typings/tutorial'
    33
    import * as vscode from 'vscode'
    44
    import Storage from '../../services/storage'
    55

    @@ -39,7 +39,7 @@ class Progress {
    3939
    public reset = () => {
    4040
    this.set(defaultValue)
    4141
    }
    42-
    public setStepComplete = (tutorialData: G.TutorialData, stepId: string): CR.Progress => {
    42+
    public setStepComplete = (tutorialData: TT.TutorialData, stepId: string): CR.Progress => {
    4343
    const next = this.value
    4444
    // mark step complete
    4545
    next.steps[stepId] = true

    src/channel/state/Tutorial.ts

    Lines changed: 6 additions & 6 deletions
    Original file line numberDiff line numberDiff line change
    @@ -1,26 +1,26 @@
    1-
    import * as G from 'typings/graphql'
    1+
    import * as TT from 'typings/tutorial'
    22
    import * as vscode from 'vscode'
    33
    import Storage from '../../services/storage'
    44

    55
    // Tutorial
    66
    class Tutorial {
    7-
    private storage: Storage<G.Tutorial | null>
    8-
    private value: G.Tutorial | null = null
    7+
    private storage: Storage<TT.Tutorial | null>
    8+
    private value: TT.Tutorial | null = null
    99
    constructor(workspaceState: vscode.Memento) {
    10-
    this.storage = new Storage<G.Tutorial | null>({
    10+
    this.storage = new Storage<TT.Tutorial | null>({
    1111
    key: 'coderoad:currentTutorial',
    1212
    storage: workspaceState,
    1313
    defaultValue: null,
    1414
    })
    1515
    // set value from storage
    16-
    this.storage.get().then((value: G.Tutorial | null) => {
    16+
    this.storage.get().then((value: TT.Tutorial | null) => {
    1717
    this.value = value
    1818
    })
    1919
    }
    2020
    public get = () => {
    2121
    return this.value
    2222
    }
    23-
    public set = (value: G.Tutorial | null) => {
    23+
    public set = (value: TT.Tutorial | null) => {
    2424
    this.value = value
    2525
    this.storage.set(value)
    2626
    }

    src/editor/commands.ts

    Lines changed: 2 additions & 2 deletions
    Original file line numberDiff line numberDiff line change
    @@ -1,4 +1,4 @@
    1-
    import * as T from 'typings'
    1+
    import * as TT from 'typings/tutorial'
    22
    import * as vscode from 'vscode'
    33
    import createTestRunner, { Payload } from '../services/testRunner'
    44
    import createWebView from '../webview'
    @@ -49,7 +49,7 @@ export const createCommands = ({ extensionPath, workspaceState, workspaceRoot }:
    4949
    // setup 1x1 horizontal layout
    5050
    webview.createOrShow()
    5151
    },
    52-
    [COMMANDS.CONFIG_TEST_RUNNER]: (config: T.TutorialTestRunner) => {
    52+
    [COMMANDS.CONFIG_TEST_RUNNER]: (config: TT.TutorialTestRunner) => {
    5353
    testRunner = createTestRunner(config, {
    5454
    onSuccess: (payload: Payload) => {
    5555
    // send test pass message back to client

    src/editor/languageMap.ts

    Lines changed: 0 additions & 23 deletions
    This file was deleted.
    Lines changed: 96 additions & 0 deletions
    Original file line numberDiff line numberDiff line change
    @@ -0,0 +1,96 @@
    1+
    import { storiesOf } from '@storybook/react'
    2+
    import { action } from '@storybook/addon-actions'
    3+
    import React from 'react'
    4+
    import { css, jsx } from '@emotion/core'
    5+
    import SelectWorkspace from '../src/containers/Check/SelectWorkspace'
    6+
    import SideBarDecorator from './utils/SideBarDecorator'
    7+
    import { Form, Input, Select } from '@alifd/next'
    8+
    9+
    const FormItem = Form.Item
    10+
    const Option = Select.Option
    11+
    12+
    const styles = {
    13+
    container: {
    14+
    display: 'flex' as 'flex',
    15+
    flexDirection: 'column' as 'column',
    16+
    },
    17+
    }
    18+
    19+
    const useFetch = (url: string, options?: object) => {
    20+
    const [data, setData] = React.useState(null)
    21+
    const [error, setError] = React.useState(null)
    22+
    const [loading, setLoading] = React.useState(true)
    23+
    React.useEffect(() => {
    24+
    const fetchData = async () => {
    25+
    try {
    26+
    const res = await fetch(url, options)
    27+
    setLoading(false)
    28+
    const json = await res.json()
    29+
    setData(json)
    30+
    } catch (error) {
    31+
    setError(error)
    32+
    }
    33+
    }
    34+
    fetchData()
    35+
    }, [url])
    36+
    return { data, error, loading }
    37+
    }
    38+
    39+
    const GitHubFetch = ({ url }) => {
    40+
    if (!url) {
    41+
    return null
    42+
    }
    43+
    const { data, error, loading } = useFetch(url)
    44+
    if (loading) {
    45+
    return <div>Loading...</div>
    46+
    }
    47+
    if (error) {
    48+
    return <div>{JSON.stringify(error)}</div>
    49+
    }
    50+
    return <div>{JSON.stringify(data)}</div>
    51+
    }
    52+
    53+
    const tutorials = [
    54+
    {
    55+
    id: '1',
    56+
    title: 'Basic Node & Express',
    57+
    configUrl: 'https://raw.githubusercontent.com/coderoad/fcc-basic-node-and-express/master/coderoad-config.json',
    58+
    },
    59+
    {
    60+
    id: '2',
    61+
    title: 'Learn NPM',
    62+
    configUrl: 'https://raw.githubusercontent.com/coderoad/fcc-learn-npm/master/coderoad-config.json',
    63+
    },
    64+
    ]
    65+
    66+
    const SelectTutorial = () => {
    67+
    const [url, setUrl] = React.useState(null)
    68+
    const handleUrlChange = (value) => {
    69+
    setUrl(value)
    70+
    }
    71+
    return (
    72+
    <div>
    73+
    <Form style={{ maxWidth: '500px' }}>
    74+
    <FormItem label="Select Tutorial:">
    75+
    <Select onChange={handleUrlChange} style={{ width: '100%' }}>
    76+
    {tutorials.map((tutorial) => (
    77+
    <Option key={tutorial.id} value={tutorial.configUrl}>
    78+
    {tutorial.title}
    79+
    </Option>
    80+
    ))}
    81+
    </Select>
    82+
    </FormItem>
    83+
    </Form>
    84+
    <GitHubFetch url={url} />
    85+
    </div>
    86+
    )
    87+
    }
    88+
    89+
    storiesOf('GitHub Fetch', module)
    90+
    .addDecorator(SideBarDecorator)
    91+
    .add('Request', () => {
    92+
    return <GitHubFetch url={tutorials[0].configUrl} />
    93+
    })
    94+
    .add('Select Tutorial', () => {
    95+
    return <SelectTutorial />
    96+
    })

    0 commit comments

    Comments
     (0)
    0