Skip to content

In progress: Feature/api #28

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

Closed
wants to merge 64 commits into from
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
64 commits
Select commit Hold shift + click to select a range
9004e35
setup server api
ShMcK Aug 14, 2019
4bd3fad
setup apollo on web
ShMcK Aug 14, 2019
4456261
setup new page query
ShMcK Aug 14, 2019
d0f984b
npm updates
ShMcK Aug 16, 2019
a591a2d
sort-package-json
ShMcK Aug 18, 2019
5a060fd
migrate codegen graphql typings
ShMcK Aug 18, 2019
f3f9765
cleanup routes
ShMcK Aug 18, 2019
2d84fa8
setup apollo decorator
ShMcK Aug 18, 2019
1114d13
new queryTutorials loaded
ShMcK Aug 18, 2019
4b1d714
migrate latestVersion to version
ShMcK Aug 18, 2019
5d38263
remove data from version, schema change
ShMcK Aug 18, 2019
8d4d43f
ckean up new container loading
ShMcK Aug 18, 2019
64837c0
load continue container
ShMcK Aug 18, 2019
b2fcd7a
add error component
ShMcK Aug 18, 2019
0c9b0b9
clenaup level summary progress
ShMcK Aug 18, 2019
f57b367
apollo decorator with local cache
ShMcK Aug 18, 2019
2b16a0b
working LevelStage container
ShMcK Aug 18, 2019
204840f
update level stories & structure
ShMcK Aug 18, 2019
2bc96a1
cleanup gql paths
ShMcK Aug 18, 2019
372658d
add level/stage/step to gql
ShMcK Aug 18, 2019
44613b6
migrate stage page
ShMcK Aug 18, 2019
df11100
fix typing paths for storybook
ShMcK Aug 18, 2019
7bab14b
cleanup Stage story
ShMcK Aug 18, 2019
c69b868
working stage container
ShMcK Aug 18, 2019
00b3550
cleanup storybook summary
ShMcK Aug 18, 2019
223019e
cleanup step stories
ShMcK Aug 18, 2019
d0d2f07
restructure single use components into containers
ShMcK Aug 18, 2019
b022179
remove old web api
ShMcK Aug 19, 2019
24eb6a6
absolute paths not allowed
ShMcK Aug 19, 2019
be46fad
create setStatus mutation
ShMcK Aug 19, 2019
26ae887
resolve build issues
ShMcK Aug 19, 2019
c39666a
update deps
ShMcK Aug 20, 2019
6c73657
fix react webview script issue
ShMcK Aug 22, 2019
36af369
create script for styles
ShMcK Aug 22, 2019
a058eff
update deps
ShMcK Aug 22, 2019
8c72738
cleanup logs
ShMcK Aug 22, 2019
d784c57
fix use effects
ShMcK Aug 22, 2019
f4e9877
fix no route unclear object
ShMcK Aug 22, 2019
6a13fcd
update api url for src
ShMcK Aug 22, 2019
39af55d
cleanup apollo server
ShMcK Aug 22, 2019
8740c1d
migrate to graphql-request on server
ShMcK Aug 23, 2019
5776877
tutorial command progress
ShMcK Aug 23, 2019
47224c4
update deps
ShMcK Aug 25, 2019
7bbacd6
update typings
ShMcK Aug 25, 2019
0dd047f
create Tutorial model
ShMcK Aug 25, 2019
97b878a
initialize state machine with tutorial model
ShMcK Aug 25, 2019
57675e5
tutorialModel progress
ShMcK Aug 25, 2019
a92d52f
heavy refactoring
ShMcK Aug 25, 2019
46d1e27
fix launch errors
ShMcK Aug 25, 2019
98c9cc9
remove unusued loading tutorial
ShMcK Aug 25, 2019
b358130
fix send data to client
ShMcK Aug 25, 2019
b6ec3e8
cleanup env vars & fix request
ShMcK Aug 25, 2019
bf0ad9b
clenaup typings
ShMcK Aug 25, 2019
0ad9d2c
add additional logging
ShMcK Aug 26, 2019
f462b39
heavy refactor
ShMcK Aug 26, 2019
1253177
Refactor editor dispatch uses
ShMcK Sep 1, 2019
c32d670
add jest
ShMcK Sep 1, 2019
3886921
fix stateToString function
ShMcK Sep 1, 2019
63f28db
fix jest mismatch build errors
ShMcK Sep 1, 2019
0d50ab6
update deps
ShMcK Sep 1, 2019
44cf7d7
cleanup client state
ShMcK Sep 1, 2019
957d05b
rename select to start
ShMcK Sep 1, 2019
0133ab8
migrate git into tutorial model
ShMcK Sep 1, 2019
50cad58
setup initial start/loaded actions
ShMcK Sep 1, 2019
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
setup initial start/loaded actions
  • Loading branch information
ShMcK committed Sep 1, 2019
commit 50cad589f3342128b5463556a09059411d682a5f
5 changes: 5 additions & 0 deletions src/editor/ReactWebView.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import * as path from 'path'
import * as CR from 'typings'
import * as vscode from 'vscode'
import {tutorialModel} from '../extension'

const getNonce = (): string => {
let text = ''
Expand Down Expand Up @@ -44,6 +45,10 @@ class ReactWebView {
case 'TUTORIAL_START':
console.log('TUTORIAL_START called')
console.log(action)
if (typeof action === 'string' || !action.payload || !action.payload.id) {
throw new Error('No tutorial id on tutorial start action')
}
tutorialModel.launch(action.payload.id)
break
// add other cases
default:
Expand Down
12 changes: 10 additions & 2 deletions src/services/tutorial/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import * as G from 'typings/graphql'
import * as CR from 'typings'
import * as git from '../../services/git'
import {machine} from '../../extension'
import * as storage from '../storage'
import api from '../api'
import tutorialQuery from '../../services/api/gql/getTutorial'
Expand Down Expand Up @@ -60,13 +61,16 @@ class Tutorial implements TutorialModel {
// })

}
public async launch(tutorialId: string) {
public launch = async (tutorialId: string) => {
console.log('launch tutorial')
machine.send('TUTORIAL_START')

const {tutorial}: {tutorial: G.Tutorial | null} = await api.request(tutorialQuery, {
tutorialId, // TODO: add selection of tutorial id
})

console.log('tutorial', tutorial)

if (!tutorial) {
throw new Error(`Tutorial ${tutorialId} not found`)
}
Expand All @@ -83,6 +87,8 @@ class Tutorial implements TutorialModel {
}
// version containing level data
this.version = tutorial.version
console.log('version', this.version)

// set initial position
this.position = {
levelId: this.version.levels[0].id,
Expand Down Expand Up @@ -112,7 +118,9 @@ class Tutorial implements TutorialModel {
storage.setPosition(this.position),
storage.setProgress(this.progress)
])
// machine.send('TUTORIAL_LOADED')

console.log('tutorial loaded')
machine.send('TUTORIAL_LOADED')
}

public async hasExisting(): Promise<boolean> {
Expand Down
7 changes: 6 additions & 1 deletion web-app/src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import * as CR from 'typings'

import client from './services/apollo'
import { SET_STATUS } from './services/apollo/mutations'
import currentTutorial from './services/current'
import Debugger from './components/Debugger'
import Routes from './Routes'
import { send } from './utils/vscode'
Expand Down Expand Up @@ -39,11 +40,15 @@ const App = () => {

} else if (message.type === 'SET_DATA') {
// SET_DATA - set state machine context
const { progress, position } = message.payload.data
console.log('DATA')
const { progress, position } = message.payload
if (process.env.REACT_APP_DEBUG) {
console.log(`Position: ${position.levelId}/${position.stageId}/${position.stepId}`)
setDebuggerInfo({ progress, position })
}
console.log('set currentTutorial')
currentTutorial.set({ position })
console.log('setStatus')
setStatus({ variables: { progress, position } })
}
}
Expand Down
45 changes: 26 additions & 19 deletions web-app/src/containers/New/TutorialList/index.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import * as React from 'react'

import currentTutorial from '../../../services/current'
import * as CR from 'typings'
import * as T from 'typings/graphql'
import TutorialItem from './TutorialItem'
Expand All @@ -10,25 +11,31 @@ interface Props {
}

const TutorialList = (props: Props) => {
const onSelect = (tutorial: T.Tutorial) => props.onNew({
type: 'TUTORIAL_START',
payload: {
id: tutorial.id,
version: tutorial.version,
}
})
const onSelect = (tutorial: T.Tutorial) => {
currentTutorial.set({
tutorialId: tutorial.id,
version: tutorial.version.version,
})
props.onNew({
type: 'TUTORIAL_START',
payload: {
id: tutorial.id,
version: tutorial.version.version,
}
})
}
return (
<div>
{props.tutorialList.map((tutorial: T.Tutorial) => (
<TutorialItem
key={tutorial.id}
onSelect={() => onSelect(tutorial)}
title={tutorial.title || ''}
text={tutorial.text || ''}
/>
))}
</div>
)
}
<div>
{props.tutorialList.map((tutorial: T.Tutorial) => (
<TutorialItem
key={tutorial.id}
onSelect={() => onSelect(tutorial)}
title={tutorial.title || ''}
text={tutorial.text || ''}
/>
))}
</div>
)
}

export default TutorialList
8 changes: 5 additions & 3 deletions web-app/src/containers/Tutorial/LevelPage/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import * as React from 'react'
import { useQuery } from '@apollo/react-hooks'
import * as T from 'typings/graphql'

import currentTutorial from '../../../services/current'
import ErrorView from '../../../components/Error'
import Level from './Level'
import queryLevel from './queryLevel'
Expand All @@ -26,11 +27,12 @@ interface ContainerProps {
}

const LevelSummaryPageContainer = (props: ContainerProps) => {
const { tutorialId, version, position: { levelId } } = currentTutorial.get()
const { loading, error, data } = useQuery(queryLevel, {
variables: {
tutorialId: '1',
version: '0.1.0',
levelId: '1',
tutorialId,
version,
levelId,
},
})

Expand Down
8 changes: 5 additions & 3 deletions web-app/src/containers/Tutorial/StagePage/index.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import * as React from 'react'
import { useQuery } from '@apollo/react-hooks'

import currentTutorial from '../../../services/current'
import ErrorView from '../../../components/Error'
import Stage from './Stage'
import queryStage from './queryStage'
Expand All @@ -10,11 +11,12 @@ interface PageProps {
}

const StageSummaryPageContainer = (props: PageProps) => {
const { tutorialId, version, position: { stageId } } = currentTutorial.get()
const { loading, error, data } = useQuery(queryStage, {
variables: {
tutorialId: '1',
version: '0.1.0',
stageId: '1',
tutorialId,
version,
stageId,
},
})
if (loading) {
Expand Down
4 changes: 3 additions & 1 deletion web-app/src/containers/Tutorial/SummaryPage/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,18 @@ import { useQuery } from '@apollo/react-hooks'

import querySummary from './querySummary'
import Summary from './Summary'
import currentTutorial from '../../../services/current'
import ErrorView from '../../../components/Error'

interface PageProps {
send(action: string): void
}

const SummaryPage = (props: PageProps) => {
const { tutorialId } = currentTutorial.get()
const { loading, error, data } = useQuery(querySummary, {
variables: {
tutorialId: '1',
tutorialId,
},
})

Expand Down
38 changes: 38 additions & 0 deletions web-app/src/services/current/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
import * as CR from 'typings'

interface CurrentTutorialParams {
tutorialId: string
version: string
position: CR.Position
}

interface SetCurrentTutorialParams {
tutorialId?: string
version?: string
position?: CR.Position
}

class CurrentTutorial {
private tutorialId = ''
private version = ''
private position: CR.Position = {levelId: '', stageId: '', stepId: ''}
public set({tutorialId, version, position}: SetCurrentTutorialParams) {
this.tutorialId = tutorialId || this.tutorialId
this.version = version || this.version
this.position = position || this.position
}
public get(): CurrentTutorialParams {
return {
tutorialId: this.tutorialId,
version: this.version,
position: this.position,
}
}
public clear() {
this.tutorialId = ''
this.version = ''
this.position = {levelId: '', stageId: '', stepId: ''}
}
}

export default new CurrentTutorial()