Skip to content

Fix/update to api #43

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 12 commits into from
Oct 15, 2019
Prev Previous commit
Next Next commit
fix up loading of tutorials with new api
  • Loading branch information
ShMcK committed Oct 14, 2019
commit bc922a53a0a04a3ab7c20be342b6e26012c42592
7 changes: 4 additions & 3 deletions src/actions/tutorialConfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,16 +15,17 @@ const tutorialConfig = async ({tutorial, alreadyConfigured, onComplete}: Tutoria
await git.initIfNotExists()

// TODO: if remote not already set
await git.setupRemote(tutorial.repo.uri)
await git.setupRemote(tutorial.version.data.config.repo.uri)
if (onComplete) {onComplete()}
}

// TODO: allow multiple coding languages in a tutorial
const language = tutorial.codingLanguage.toLowerCase()
const languages: G.CodingLanguage[] = tutorial.version.data.config.codingLanguages

// setup onSave hook
vscode.workspace.onDidSaveTextDocument((document: vscode.TextDocument) => {
if (document.uri.scheme === 'file' && language === document.languageId) {
// @ts-ignore // issue with GQL enums in TS
if (document.uri.scheme === 'file' && languages.includes(document.languageId.toUpperCase())) {
vscode.commands.executeCommand('coderoad.run_test')
}
})
Expand Down
2 changes: 1 addition & 1 deletion src/channel/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ class Channel implements Channel {
return
// configure test runner, language, git
case 'EDITOR_TUTORIAL_CONFIG':
const tutorialData = action.payload.tutorial
const tutorialData: G.Tutorial = action.payload.tutorial
this.context.setTutorial(this.workspaceState, tutorialData)
tutorialConfig({
tutorial: tutorialData,
Expand Down
6 changes: 3 additions & 3 deletions web-app/src/containers/Tutorial/SummaryPage/Summary/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,15 @@ const styles = {

interface Props {
title: string
text: string
description: string
onNext(): void
}

const Summary = ({ title, text, onNext }: Props) => (
const Summary = ({ title, description, onNext }: Props) => (
<div style={styles.card}>
<div style={styles.content}>
<h2 style={styles.title}>{title}</h2>
<p>{text}</p>
<p>{description}</p>
</div>
<div style={styles.options}>
<Button onClick={() => onNext()}>Continue</Button>
Expand Down
20 changes: 17 additions & 3 deletions web-app/src/containers/Tutorial/SummaryPage/index.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import * as React from 'react'
import * as G from 'typings/graphql'
import * as CR from 'typings'
import { useQuery } from '@apollo/react-hooks'

Expand All @@ -11,13 +12,22 @@ interface PageProps {
send(action: CR.Action): void
}

interface TutorialData {
tutorial: G.Tutorial
}

interface TutorialDataVariables {
tutorialId: string
version: string
}

const SummaryPage = (props: PageProps) => {
const { tutorial } = props.context

if (!tutorial) {
throw new Error('Tutorial not found in summary page')
}
const { loading, error, data } = useQuery(queryTutorial, {
const { loading, error, data } = useQuery<TutorialData, TutorialDataVariables>(queryTutorial, {
fetchPolicy: 'network-only', // for debugging purposes
variables: {
tutorialId: tutorial.id,
Expand All @@ -33,6 +43,10 @@ const SummaryPage = (props: PageProps) => {
return <ErrorView error={error} />
}

if (!data) {
return null
}

const onNext = () =>
props.send({
type: 'LOAD_TUTORIAL',
Expand All @@ -41,9 +55,9 @@ const SummaryPage = (props: PageProps) => {
},
})

const { title, text } = data.tutorial
const { title, description } = data.tutorial.version.summary

return <Summary title={title} text={text} onNext={onNext} />
return <Summary title={title} description={description} onNext={onNext} />
}

export default SummaryPage
11 changes: 10 additions & 1 deletion web-app/src/services/state/actions/editor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,15 @@ import channel from '../../channel'
import client from '../../apollo'
import tutorialQuery from '../../apollo/queries/tutorial'

interface TutorialData {
tutorial: G.Tutorial
}

interface TutorialDataVariables {
tutorialId: string
version: string
}

export default {
loadEnv() {
channel.editorSend({
Expand Down Expand Up @@ -34,7 +43,7 @@ export default {
throw new Error('Tutorial not available to load')
}

client.query({
client.query<TutorialData, TutorialDataVariables>({
query: tutorialQuery,
variables: {
tutorialId: context.tutorial.id,
Expand Down