From 0fd10d3f6899adb8f3d4b546cdc9881c95f53f18 Mon Sep 17 00:00:00 2001 From: shmck Date: Sat, 30 Nov 2019 16:31:06 -0800 Subject: [PATCH 1/4] remove unused --- .../src/containers/Overview/OverviewPage.tsx | 148 +++++++++--------- web-app/src/services/state/actions/editor.ts | 10 -- 2 files changed, 74 insertions(+), 84 deletions(-) diff --git a/web-app/src/containers/Overview/OverviewPage.tsx b/web-app/src/containers/Overview/OverviewPage.tsx index bb8ffd71..65f8accc 100644 --- a/web-app/src/containers/Overview/OverviewPage.tsx +++ b/web-app/src/containers/Overview/OverviewPage.tsx @@ -5,87 +5,87 @@ import * as G from 'typings/graphql' import Markdown from '../../components/Markdown' const styles = { - page: { - position: 'relative' as 'relative', - display: 'flex' as 'flex', - flexDirection: 'column' as 'column', - width: '100%', - }, - summary: { - padding: '0rem 1rem 1rem 1rem', - }, - title: { - fontWeight: 'bold' as 'bold', - }, - description: { - fontSize: '1rem', - }, - header: { - height: '36px', - backgroundColor: '#EBEBEB', - fontSize: '16px', - lineHeight: '16px', - padding: '10px 1rem', - }, - levelList: { - padding: '0rem 1rem', - }, - options: { - position: 'absolute' as 'absolute', - bottom: 0, - display: 'flex' as 'flex', - flexDirection: 'row' as 'row', - alignItems: 'center' as 'center', - justifyContent: 'flex-end' as 'flex-end', - height: '50px', - padding: '1rem', - paddingRight: '2rem', - backgroundColor: 'black', - width: '100%', - }, + page: { + position: 'relative' as 'relative', + display: 'flex' as 'flex', + flexDirection: 'column' as 'column', + width: '100%', + }, + summary: { + padding: '0rem 1rem 1rem 1rem', + }, + title: { + fontWeight: 'bold' as 'bold', + }, + description: { + fontSize: '1rem', + }, + header: { + height: '36px', + backgroundColor: '#EBEBEB', + fontSize: '16px', + lineHeight: '16px', + padding: '10px 1rem', + }, + levelList: { + padding: '0rem 1rem', + }, + options: { + position: 'absolute' as 'absolute', + bottom: 0, + display: 'flex' as 'flex', + flexDirection: 'row' as 'row', + alignItems: 'center' as 'center', + justifyContent: 'flex-end' as 'flex-end', + height: '50px', + padding: '1rem', + paddingRight: '2rem', + backgroundColor: 'black', + width: '100%', + }, } interface Props { - title: string - description: string - levels: G.Level[] - onNext(): void + title: string + description: string + levels: G.Level[] + onNext(): void } const Summary = ({ title, description, levels, onNext }: Props) => ( -
-
-
- CodeRoad -
-
-

{title}

- {description} -
-
-
- Levels -
-
- {levels.map((level: G.Level, index: number) => ( -
-

- {index + 1}. {level.title} -

-
{level.description}
-
- ))} -
-
-
+
+
+
+ CodeRoad +
+
+

{title}

+ {description} +
+
+
+ Levels +
+
+ {levels.map((level: G.Level, index: number) => ( +
+

+ {index + 1}. {level.title} +

+
{level.description}
+
+ ))} +
+
+
-
- {/* TODO: Add back button */} - -
-
+
+ {/* TODO Add back button */} + +
+
) export default Summary diff --git a/web-app/src/services/state/actions/editor.ts b/web-app/src/services/state/actions/editor.ts index f021272a..7db737a3 100644 --- a/web-app/src/services/state/actions/editor.ts +++ b/web-app/src/services/state/actions/editor.ts @@ -27,16 +27,6 @@ export default { type: 'EDITOR_TUTORIAL_LOAD', }) }, - // TODO: syncProgress unused - syncProgress(context: CR.MachineContext): void { - // sync progress in editor local storage for persistence - channel.editorSend({ - type: 'EDITOR_SYNC_PROGRESS', - payload: { - progress: context.progress, - }, - }) - }, initializeTutorial(context: CR.MachineContext, event: CR.MachineEvent) { // setup test runner and git if (!context.tutorial) { From bdf0c32ca0f6e7301973a4478ad1becd4208a223 Mon Sep 17 00:00:00 2001 From: shmck Date: Sat, 30 Nov 2019 16:31:20 -0800 Subject: [PATCH 2/4] cleanup todos --- src/actions/tutorialConfig.ts | 2 +- src/actions/utils/openFiles.ts | 2 +- src/channel/index.ts | 5 ----- src/channel/state/Position.ts | 14 ++++++++++++-- src/channel/state/Progress.ts | 3 +++ src/channel/state/Tutorial.ts | 7 ++++--- src/editor/commands.ts | 4 ++-- src/services/git/index.ts | 2 +- src/services/storage/index.ts | 8 ++++---- src/webview/index.ts | 2 +- typings/index.d.ts | 2 +- web-app/src/Routes.tsx | 2 +- web-app/src/components/Markdown/index.tsx | 2 +- web-app/src/components/Markdown/prism.ts | 2 +- web-app/src/components/StepHelp/index.tsx | 2 +- web-app/src/services/state/actions/api.ts | 2 +- web-app/src/services/state/actions/context.ts | 4 ++-- web-app/src/services/state/machine.ts | 7 +++---- 18 files changed, 40 insertions(+), 32 deletions(-) diff --git a/src/actions/tutorialConfig.ts b/src/actions/tutorialConfig.ts index d1fbe181..772f6334 100644 --- a/src/actions/tutorialConfig.ts +++ b/src/actions/tutorialConfig.ts @@ -26,7 +26,7 @@ const tutorialConfig = async ( }) }) - // TODO: if remote not already set + // TODO if remote not already set await git.setupRemote(config.repo.uri).catch(error => { onError({ title: error.message, description: 'Remove your current Git project and restarting' }) }) diff --git a/src/actions/utils/openFiles.ts b/src/actions/utils/openFiles.ts index 011aa596..04f137ea 100644 --- a/src/actions/utils/openFiles.ts +++ b/src/actions/utils/openFiles.ts @@ -8,7 +8,7 @@ const openFiles = async (files: string[]) => { } for (const filePath of files) { try { - // TODO: figure out why this does not work + // TODO figure out why this does not work // try { // const absoluteFilePath = join(workspaceRoot.uri.path, filePath) // const doc = await vscode.workspace.openTextDocument(absoluteFilePath) diff --git a/src/channel/index.ts b/src/channel/index.ts index f53b900d..a184989b 100644 --- a/src/channel/index.ts +++ b/src/channel/index.ts @@ -114,11 +114,6 @@ class Channel implements Channel { onError, ) return - case 'EDITOR_SYNC_PROGRESS': - // sync client progress on server - this.context.position.set(action.payload.position) - this.context.progress.set(action.payload.progress) - return // load step actions (git commits, commands, open files) case 'SETUP_ACTIONS': vscode.commands.executeCommand(COMMANDS.SET_CURRENT_STEP, action.payload) diff --git a/src/channel/state/Position.ts b/src/channel/state/Position.ts index 988241ae..799016d0 100644 --- a/src/channel/state/Position.ts +++ b/src/channel/state/Position.ts @@ -13,9 +13,15 @@ class Position { this.value = defaultValue } public get = () => { + if (!this.value.levelId || !this.value.stepId) { + console.log('NO POSITION RETURNED') + } + console.log(this.value) return this.value } public set = (value: CR.Position) => { + console.log('--- position set') + console.log(value) this.value = value } public reset = () => { @@ -23,8 +29,9 @@ class Position { } // calculate the current position based on the saved progress public setPositionFromProgress = (tutorial: G.Tutorial, progress: CR.Progress): CR.Position => { + console.log('--- set position from progress') // tutorial already completed - // TODO: handle start again? + // TODO handle start again? if (progress.complete) { return this.value } @@ -36,7 +43,7 @@ class Position { const { levels } = tutorial.version.data const lastLevelIndex: number | undefined = levels.findIndex((l: G.Level) => !progress.levels[l.id]) - // TODO: consider all levels complete as progress.complete + // TODO consider all levels complete as progress.complete if (lastLevelIndex >= levels.length) { throw new Error('Error setting progress level') } @@ -56,6 +63,9 @@ class Position { levelId: currentLevel.id, stepId: currentStep.id, } + + console.log('--- calculated set position from progress') + console.log(this.value) return this.value } } diff --git a/src/channel/state/Progress.ts b/src/channel/state/Progress.ts index 311e8a60..64e69551 100644 --- a/src/channel/state/Progress.ts +++ b/src/channel/state/Progress.ts @@ -43,6 +43,9 @@ class Progress { public setStepComplete = (stepId: string): CR.Progress => { const next = this.value next.steps[stepId] = true + + // TODO validate if progress is complete for a level or tutorial + return this.set(next) } } diff --git a/src/channel/state/Tutorial.ts b/src/channel/state/Tutorial.ts index d6efac1d..1dffa9fc 100644 --- a/src/channel/state/Tutorial.ts +++ b/src/channel/state/Tutorial.ts @@ -6,20 +6,21 @@ import Storage from '../../services/storage' // Tutorial class Tutorial { private storage: Storage - private value: G.Tutorial | null + private value: G.Tutorial | null = null constructor(workspaceState: vscode.Memento) { this.storage = new Storage({ key: 'coderoad:currentTutorial', storage: workspaceState, defaultValue: null, }) - this.value = null // set value from storage this.storage.get().then((value: G.Tutorial | null) => { this.value = value }) } - public get = () => this.value + public get = () => { + return this.value + } public set = (value: G.Tutorial | null) => { this.value = value this.storage.set(value) diff --git a/src/editor/commands.ts b/src/editor/commands.ts index 309a3985..95a23855 100644 --- a/src/editor/commands.ts +++ b/src/editor/commands.ts @@ -26,7 +26,7 @@ export const createCommands = ({ extensionPath, workspaceState, workspaceRoot }: return { // initialize [COMMANDS.START]: async () => { - // TODO: replace with a prompt to open a workspace + // TODO replace with a prompt to open a workspace // await isEmptyWorkspace() let webviewState: 'INITIALIZING' | 'RESTARTING' @@ -58,6 +58,7 @@ export const createCommands = ({ extensionPath, workspaceState, workspaceRoot }: // send test pass message back to client vscode.window.showInformationMessage('PASS') webview.send({ type: 'TEST_PASS', payload }) + // update local storage }, onFail: (payload: Payload, message: string) => { // send test fail message back to client @@ -75,7 +76,6 @@ export const createCommands = ({ extensionPath, workspaceState, workspaceRoot }: }) }, [COMMANDS.SET_CURRENT_STEP]: ({ stepId }: Payload) => { - // NOTE: as async, may sometimes be inaccurate // set from last setup stepAction currentStepId = stepId }, diff --git a/src/services/git/index.ts b/src/services/git/index.ts index 28c43bcd..fe3a7c57 100644 --- a/src/services/git/index.ts +++ b/src/services/git/index.ts @@ -119,7 +119,7 @@ export async function checkRemoteExists(): Promise { return false } // string match on remote output - // TODO: improve the specificity of this regex + // TODO improve the specificity of this regex return !!stdout.match(gitOrigin) } catch (error) { return false diff --git a/src/services/storage/index.ts b/src/services/storage/index.ts index 6fe98a99..8a64cceb 100644 --- a/src/services/storage/index.ts +++ b/src/services/storage/index.ts @@ -16,10 +16,10 @@ class Storage { this.defaultValue = defaultValue } public get = async (): Promise => { - // const value: string | undefined = await this.storage.get(this.key) - // if (value) { - // return JSON.parse(value) - // } + const value: string | undefined = await this.storage.get(this.key) + if (value) { + return JSON.parse(value) + } return this.defaultValue } public set = (value: T): void => { diff --git a/src/webview/index.ts b/src/webview/index.ts index d0ee7ca4..52bca445 100644 --- a/src/webview/index.ts +++ b/src/webview/index.ts @@ -12,7 +12,7 @@ interface ReactWebViewProps { const createReactWebView = ({ extensionPath, workspaceState, workspaceRoot }: ReactWebViewProps) => { let loaded = false - // TODO: add disposables + // TODO add disposables const disposables: vscode.Disposable[] = [] function createWebViewPanel(): vscode.WebviewPanel { diff --git a/typings/index.d.ts b/typings/index.d.ts index 2241145a..be073989 100644 --- a/typings/index.d.ts +++ b/typings/index.d.ts @@ -108,7 +108,7 @@ interface MessageState { state: string } -// todo: type each string param and payload +// TODO type each string param and payload export type EditorDispatch = (type: string, payload?: MessageData | MessageState | any) => void export interface ProcessEvent { diff --git a/web-app/src/Routes.tsx b/web-app/src/Routes.tsx index ab947e5e..64309345 100644 --- a/web-app/src/Routes.tsx +++ b/web-app/src/Routes.tsx @@ -15,7 +15,7 @@ const { Route } = Router const tempSend = (action: any) => console.log('sent') const Routes = () => { - // TODO: refactor for typescript to understand send & context passed into React.cloneElement's + // TODO refactor for typescript to understand send & context passed into React.cloneElement's return ( diff --git a/web-app/src/components/Markdown/index.tsx b/web-app/src/components/Markdown/index.tsx index cab3bc0c..a39c6d33 100644 --- a/web-app/src/components/Markdown/index.tsx +++ b/web-app/src/components/Markdown/index.tsx @@ -36,7 +36,7 @@ const Markdown = (props: Props) => {

${props.children}

` } - // TODO: sanitize markdown or HTML + // TODO sanitize markdown or HTML return
} diff --git a/web-app/src/components/Markdown/prism.ts b/web-app/src/components/Markdown/prism.ts index fee032e3..76e2aa27 100644 --- a/web-app/src/components/Markdown/prism.ts +++ b/web-app/src/components/Markdown/prism.ts @@ -10,4 +10,4 @@ import 'prismjs/components/prism-javascript' import 'prismjs/components/prism-json' import 'prismjs/components/prism-sql' import 'prismjs/components/prism-typescript' -// TODO: import all - current list only supports js related +// TODO import all - current list only supports js related diff --git a/web-app/src/components/StepHelp/index.tsx b/web-app/src/components/StepHelp/index.tsx index 2e959da0..9e0fab49 100644 --- a/web-app/src/components/StepHelp/index.tsx +++ b/web-app/src/components/StepHelp/index.tsx @@ -27,7 +27,7 @@ interface Props { } const StepHelp = (props: Props) => { - // TODO: extract or replace load solution + // TODO extract or replace load solution const [loadedSolution, setLoadedSolution] = React.useState() const onClickHandler = () => { if (!loadedSolution) { diff --git a/web-app/src/services/state/actions/api.ts b/web-app/src/services/state/actions/api.ts index 3fe5ae99..4520ea5a 100644 --- a/web-app/src/services/state/actions/api.ts +++ b/web-app/src/services/state/actions/api.ts @@ -32,7 +32,7 @@ export default { .catch(console.error) if (!result || !result.data) { - // TODO: handle failed authentication + // TODO handle failed authentication console.error('ERROR: Authentication failed') const error = { title: 'Authentication Failed', diff --git a/web-app/src/services/state/actions/context.ts b/web-app/src/services/state/actions/context.ts index 5d358e34..2882906f 100644 --- a/web-app/src/services/state/actions/context.ts +++ b/web-app/src/services/state/actions/context.ts @@ -47,7 +47,7 @@ export default { // @ts-ignore updateStepPosition: assign({ position: (context: CR.MachineContext, event: CR.MachineEvent): CR.Position => { - // TODO: calculate from progress + // TODO calculate from progress const { position } = context // merge in the updated position @@ -176,7 +176,7 @@ export default { const level: G.Level = selectors.currentLevel(context) const { steps } = level - // TODO: verify not -1 + // TODO verify not -1 const stepIndex = steps.findIndex((s: G.Step) => s.id === position.stepId) const finalStep = stepIndex === steps.length - 1 const stepComplete = progress.steps[position.stepId] diff --git a/web-app/src/services/state/machine.ts b/web-app/src/services/state/machine.ts index b1a0c4b7..493d4d24 100644 --- a/web-app/src/services/state/machine.ts +++ b/web-app/src/services/state/machine.ts @@ -97,12 +97,12 @@ export const machine = Machine Date: Sun, 1 Dec 2019 14:51:03 -0800 Subject: [PATCH 3/4] fix currentStepId on continue load --- src/channel/index.ts | 4 +++- src/editor/commands.ts | 2 +- web-app/src/services/state/actions/editor.ts | 6 +++++- 3 files changed, 9 insertions(+), 3 deletions(-) diff --git a/src/channel/index.ts b/src/channel/index.ts index a184989b..9a0e79a6 100644 --- a/src/channel/index.ts +++ b/src/channel/index.ts @@ -113,10 +113,12 @@ class Channel implements Channel { }, onError, ) + // update the current stepId on startup + vscode.commands.executeCommand(COMMANDS.SET_CURRENT_STEP, action.payload) return // load step actions (git commits, commands, open files) case 'SETUP_ACTIONS': - vscode.commands.executeCommand(COMMANDS.SET_CURRENT_STEP, action.payload) + await vscode.commands.executeCommand(COMMANDS.SET_CURRENT_STEP, action.payload) setupActions(this.workspaceRoot, action.payload, this.send) return // load solution step actions (git commits, commands, open files) diff --git a/src/editor/commands.ts b/src/editor/commands.ts index 95a23855..7fac20fd 100644 --- a/src/editor/commands.ts +++ b/src/editor/commands.ts @@ -81,7 +81,7 @@ export const createCommands = ({ extensionPath, workspaceState, workspaceRoot }: }, [COMMANDS.RUN_TEST]: (current: Payload | undefined, onSuccess: () => void) => { // use stepId from client, or last set stepId - const payload: Payload = { stepId: current ? current.stepId : currentStepId } + const payload: Payload = { stepId: current && current.stepId.length ? current.stepId : currentStepId } testRunner(payload, onSuccess) }, } diff --git a/web-app/src/services/state/actions/editor.ts b/web-app/src/services/state/actions/editor.ts index 7db737a3..3dcfd318 100644 --- a/web-app/src/services/state/actions/editor.ts +++ b/web-app/src/services/state/actions/editor.ts @@ -55,9 +55,13 @@ export default { return Promise.reject(`Failed to load tutorial config ${error.message}`) }) }, - continueConfig() { + continueConfig(context: CR.MachineContext) { channel.editorSend({ type: 'EDITOR_TUTORIAL_CONTINUE_CONFIG', + payload: { + // pass position because current stepId or first stepId will be empty + stepId: context.position.stepId, + }, }) }, loadLevel(context: CR.MachineContext): void { From eb3628e50c5d3101e5fef1f219bb8e55ef3486ee Mon Sep 17 00:00:00 2001 From: shmck Date: Sun, 1 Dec 2019 14:52:37 -0800 Subject: [PATCH 4/4] remove position logs --- src/channel/state/Position.ts | 9 --------- 1 file changed, 9 deletions(-) diff --git a/src/channel/state/Position.ts b/src/channel/state/Position.ts index 799016d0..b13e53db 100644 --- a/src/channel/state/Position.ts +++ b/src/channel/state/Position.ts @@ -13,15 +13,9 @@ class Position { this.value = defaultValue } public get = () => { - if (!this.value.levelId || !this.value.stepId) { - console.log('NO POSITION RETURNED') - } - console.log(this.value) return this.value } public set = (value: CR.Position) => { - console.log('--- position set') - console.log(value) this.value = value } public reset = () => { @@ -29,7 +23,6 @@ class Position { } // calculate the current position based on the saved progress public setPositionFromProgress = (tutorial: G.Tutorial, progress: CR.Progress): CR.Position => { - console.log('--- set position from progress') // tutorial already completed // TODO handle start again? if (progress.complete) { @@ -64,8 +57,6 @@ class Position { stepId: currentStep.id, } - console.log('--- calculated set position from progress') - console.log(this.value) return this.value } }