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
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

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
Next Next commit
rebuild after large changes
  • Loading branch information
ShMcK committed Oct 14, 2019
commit 8c3e5a656de86e8168810e4e46260972211d8324
54 changes: 29 additions & 25 deletions src/actions/setupActions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,34 +45,38 @@ const setupActions = async (workspaceRoot: vscode.WorkspaceFolder, {commands, co
}

// run command
await runCommands(commands)
if (commands) {
await runCommands(commands)
}

// open files
for (const filePath of files) {
try {
// TODO: figure out why this does not work
// try {
// const absoluteFilePath = join(workspaceRoot.uri.path, filePath)
// const doc = await vscode.workspace.openTextDocument(absoluteFilePath)
// await vscode.window.showTextDocument(doc, vscode.ViewColumn.One)
// // there are times when initialization leave the panel behind any files opened
// // ensure the panel is redrawn on the right side first
// // webview.createOrShow()
// } catch (error) {
// console.log(`Failed to open file ${filePath}`, error)
// }
const wr = vscode.workspace.rootPath
if (!wr) {
throw new Error('No workspace root path')
if (files) {
for (const filePath of files) {
try {
// TODO: figure out why this does not work
// try {
// const absoluteFilePath = join(workspaceRoot.uri.path, filePath)
// const doc = await vscode.workspace.openTextDocument(absoluteFilePath)
// await vscode.window.showTextDocument(doc, vscode.ViewColumn.One)
// // there are times when initialization leave the panel behind any files opened
// // ensure the panel is redrawn on the right side first
// // webview.createOrShow()
// } catch (error) {
// console.log(`Failed to open file ${filePath}`, error)
// }
const wr = vscode.workspace.rootPath
if (!wr) {
throw new Error('No workspace root path')
}
const absoluteFilePath = join(wr, filePath)
const doc = await vscode.workspace.openTextDocument(absoluteFilePath)
await vscode.window.showTextDocument(doc, vscode.ViewColumn.One)
// there are times when initialization leave the panel behind any files opened
// ensure the panel is redrawn on the right side first
vscode.commands.executeCommand('coderoad.open_webview')
} catch (error) {
console.log(`Failed to open file ${filePath}`, error)
}
const absoluteFilePath = join(wr, filePath)
const doc = await vscode.workspace.openTextDocument(absoluteFilePath)
await vscode.window.showTextDocument(doc, vscode.ViewColumn.One)
// there are times when initialization leave the panel behind any files opened
// ensure the panel is redrawn on the right side first
vscode.commands.executeCommand('coderoad.open_webview')
} catch (error) {
console.log(`Failed to open file ${filePath}`, error)
}
}
}
Expand Down
1 change: 0 additions & 1 deletion src/channel/state/Progress.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import Storage from '../../services/storage'

const defaultValue: CR.Progress = {
levels: {},
stages: {},
steps: {},
complete: false
}
Expand Down
2 changes: 1 addition & 1 deletion src/services/git/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ export function loadCommit(commit: string): Promise<void> {

/*
save commit
git commit -am '${level}/${stage}/${step} complete'
git commit -am '${level}/${step} complete'
*/

export async function saveCommit(message: string): Promise<void> {
Expand Down
4 changes: 0 additions & 4 deletions web-app/src/Routes.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import ContinuePage from './containers/Continue'
import NewPage from './containers/New'
import SummaryPage from './containers/Tutorial/SummaryPage'
import LevelSummaryPage from './containers/Tutorial/LevelPage'
import StageSummaryPage from './containers/Tutorial/StagePage'
import CompletedPage from './containers/Tutorial/CompletedPage'

const { Route } = Router
Expand Down Expand Up @@ -40,9 +39,6 @@ const Routes = () => {
<Route path="Tutorial.Level">
<LevelSummaryPage send={tempSend} context={{} as CR.MachineContext} />
</Route>
<Route path="Tutorial.Stage">
<StageSummaryPage send={tempSend} context={{} as CR.MachineContext} />
</Route>
<Route path="Tutorial.Completed">
<CompletedPage send={tempSend} context={{} as CR.MachineContext} />
</Route>
Expand Down
8 changes: 4 additions & 4 deletions web-app/src/containers/Continue/index.tsx
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import * as React from 'react'
import { Button, Card } from '@alifd/next'
import * as CR from 'typings'
import * as T from 'typings/graphql'
import * as G from 'typings/graphql'

interface Props {
tutorial: T.Tutorial
tutorial: G.Tutorial
onContinue(): void
onNew(): void
}
Expand All @@ -14,8 +14,8 @@ export const ContinuePage = (props: Props) => (
<h3>Continue</h3>
<Card showTitleBullet={false} contentHeight="auto">
<div>
<h2>{props.tutorial.title}</h2>
<p>{props.tutorial.text}</p>
<h2>{props.tutorial.version.summary.title}</h2>
<p>{props.tutorial.version.summary.description}</p>
<Button onClick={props.onContinue}>Resume</Button>
</div>
</Card>
Expand Down
8 changes: 4 additions & 4 deletions web-app/src/containers/New/TutorialList/index.tsx
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
import * as React from 'react'

import channel from '../../../services/channel'
import * as T from 'typings/graphql'
import * as G from 'typings/graphql'
import TutorialItem from './TutorialItem'

interface Props {
tutorialList: T.Tutorial[]
tutorialList: G.Tutorial[]
}

const TutorialList = (props: Props) => {
const onSelect = (tutorial: T.Tutorial) => {
const onSelect = (tutorial: G.Tutorial) => {
channel.machineSend({
type: 'TUTORIAL_START',
payload: {
Expand All @@ -19,7 +19,7 @@ const TutorialList = (props: Props) => {
}
return (
<div>
{props.tutorialList.map((tutorial: T.Tutorial) => (
{props.tutorialList.map((tutorial: G.Tutorial) => (
<TutorialItem
key={tutorial.id}
onSelect={() => onSelect(tutorial)}
Expand Down
67 changes: 32 additions & 35 deletions web-app/src/containers/Tutorial/LevelPage/Level/index.tsx
Original file line number Diff line number Diff line change
@@ -1,74 +1,71 @@
import { Step } from '@alifd/next'
import { Button, Step } from '@alifd/next'
import * as React from 'react'
import * as T from 'typings/graphql'
import * as G from 'typings/graphql'

import Markdown from '../../../../components/Markdown'
import LevelStageSummary from './LevelStageSummary'
import StepDescription from './StepDescription'

const styles = {
card: {},
card: {
padding: 0,
},
content: {
padding: '0rem 1rem',
paddingBottom: '1rem',
},
list: {
padding: '0rem',
},
options: {
padding: '0rem 1rem',
},
steps: {
padding: '1rem 0.5rem',
padding: '1rem 0rem',
},
title: {},
}

interface Props {
level: T.Level
onNext(): void
level: G.Level
onContinue(): void
onLoadSolution(): void
}

const Level = ({ level, onNext }: Props) => {
if (!level || !level.stages) {
throw new Error('No level stages found')
const Level = ({ level, onContinue, onLoadSolution }: Props) => {
if (!level.steps) {
throw new Error('No Stage steps found')
}
const activeIndex = level.stages.findIndex((stage: T.Stage | null) => stage && stage.status === 'ACTIVE') || 0

// grab the active step
const activeIndex: number = level.steps.findIndex((step: G.Step | null) => {
return step && step.status === 'ACTIVE'
})

return (
<div style={styles.card}>
<div style={styles.content}>
<h2 style={styles.title}>{level.title}</h2>
<Markdown>{level.text || ''}</Markdown>
<Markdown>{level.description || ''}</Markdown>
</div>
<div style={styles.steps}>
<Step current={activeIndex} direction="ver" animation={false}>
{level.stages.map((stage: T.Stage | null, index: number) => {
if (!stage) {
<Step current={activeIndex} direction="ver" shape="dot" animation readOnly>
{level.steps.map((step: G.Step | null, index: number) => {
if (!step) {
return null
}
const active = stage.status === 'ACTIVE'
const clickHandler = active
? onNext
: () => {
/* empty */
}
// note - must add click handler to title, content & step.item
// as all are separated components
return (
<Step.Item
key={stage.id}
style={{ backgroundColor: 'blue' }}
title={
<span className={active ? 'hover-select' : ''} onClick={clickHandler}>
{stage.title || `Stage ${index + 1}`}
</span>
}
content={<LevelStageSummary key={stage.id} stage={stage} onNext={clickHandler} />}
onClick={clickHandler}
key={step.id}
title={step.title || `Step ${index + 1}`}
content={<StepDescription text={step.description} mode={step.status} onLoadSolution={onLoadSolution} />}
/>
)
})}
</Step>
</div>

{level.status === 'COMPLETE' && (
<div style={styles.options}>
<Button onClick={onContinue}>Continue</Button>
</div>
)}
</div>
)
}
Expand Down
53 changes: 24 additions & 29 deletions web-app/src/containers/Tutorial/LevelPage/index.tsx
Original file line number Diff line number Diff line change
@@ -1,50 +1,45 @@
import * as React from 'react'
import * as CR from 'typings'
import * as G from 'typings/graphql'
import * as selectors from '../../../services/selectors'

import Level from './Level'

interface LevelProps {
level: G.Level
send(action: string): void
}

export const LevelSummaryPage = (props: LevelProps) => {
const onNext = (): void => {
props.send('NEXT')
}
return <Level level={props.level} onNext={onNext} />
}

interface ContainerProps {
interface PageProps {
context: CR.MachineContext
send(action: string): void
send(action: CR.Action): void
}

const LevelSummaryPageContainer = (props: ContainerProps) => {
const { tutorial, position, progress } = props.context
const LevelSummaryPageContainer = (props: PageProps) => {
const { position, progress } = props.context

if (!tutorial) {
throw new Error('Tutorial not found in LevelSummaryPageContainer')
}
const level: G.Level = selectors.currentLevel(props.context)

const level: G.Level | undefined = tutorial.version.data.levels.find((l: G.Level) => l.id === position.levelId)
const onContinue = (): void => {
props.send({
type: 'LEVEL_NEXT',
payload: {
LevelId: position.levelId,
},
})
}

if (!level) {
throw new Error('Level not found in LevelSummaryPageContainer')
const onLoadSolution = (): void => {
props.send({ type: 'STEP_SOLUTION_LOAD' })
}

level.stages.forEach((stage: G.Stage) => {
if (stage.id === position.stageId) {
stage.status = 'ACTIVE'
} else if (progress.stages[stage.id]) {
stage.status = 'COMPLETE'
level.steps.forEach((step: G.Step) => {
if (progress.steps[step.id]) {
step.status = 'COMPLETE'
} else if (step.id === position.stepId) {
step.status = 'ACTIVE'
} else {
stage.status = 'INCOMPLETE'
step.status = 'INCOMPLETE'
}
})
level.status = progress.levels[position.levelId] ? 'COMPLETE' : 'ACTIVE'

return <LevelSummaryPage level={level} send={props.send} />
return <Level level={level} onContinue={onContinue} onLoadSolution={onLoadSolution} />
}

export default LevelSummaryPageContainer
Original file line number Diff line number Diff line change
Expand Up @@ -23,17 +23,17 @@ const styles = {
}

interface Props {
stage: G.Stage
level: G.Level
onNext(): void
}

const LevelStageSummary = (props: Props) => {
const { stage, onNext } = props
const active = stage.status === 'ACTIVE'
const { level, onNext } = props
const active = level.status === 'ACTIVE'
return (
<div style={styles.card} className={active ? 'hover-select' : ''} onClick={onNext}>
<div style={styles.left}>
<Markdown>{stage.text || ''}</Markdown>
<Markdown>{level.description || ''}</Markdown>
</div>
</div>
)
Expand Down
Loading