Skip to content
Prev Previous commit
Next Next commit
working version without progress
Signed-off-by: shmck <[email protected]>
  • Loading branch information
ShMcK committed Aug 1, 2020
commit 23082a4e8ba7e5ca4f98d024079c19e04415a7d3
2 changes: 1 addition & 1 deletion src/environment.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ export type Env = 'test' | 'local' | 'development' | 'production'
export const NODE_ENV: Env = process.env.NODE_ENV || 'development'

// toggle logging in development
export const LOG = true
export const LOG = false

// error logging tool
export const INSTRUMENTATION_KEY = '6ff37c76-72f3-48e3-a1b9-d5636f519b7b'
Expand Down
1 change: 1 addition & 0 deletions web-app/src/Routes.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ const Routes = () => {
}

logger(`ROUTE: ${route}`)
logger(`POSITION: ${JSON.stringify(context.position)}`)

return (
<Router route={route}>
Expand Down
12 changes: 6 additions & 6 deletions web-app/src/environment.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
// validate .env
const requiredKeys = ['REACT_APP_TUTORIAL_LIST_URL']
for (const required of requiredKeys) {
if (!process.env[required]) {
throw new Error(`Missing Environmental Variable: ${required}`)
}
}
// const requiredKeys = ['REACT_APP_TUTORIAL_LIST_URL']
// for (const required of requiredKeys) {
// if (!process.env[required]) {
// throw new Error(`Missing Environmental Variable: ${required}`)
// }
// }

export const DEBUG: boolean = (process.env.REACT_APP_DEBUG || '').toLowerCase() === 'true'
export const VERSION: string = process.env.VERSION || 'unknown'
Expand Down
2 changes: 1 addition & 1 deletion web-app/src/services/logger/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { LOG } from '../../environment'

export type Log = string | object | null
export type Log = string | object | number | null

const logger = (...messages: Log[]): void => {
if (!LOG) {
Expand Down
4 changes: 2 additions & 2 deletions web-app/src/services/state/actions/context.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { assign, send } from 'xstate'
import * as selectors from '../../selectors'
import getStepNext from './utils/stepNext'
import getNext from './utils/getNext'
import logger from 'services/logger'

export const setStart = assign({
env: (context: T.MachineContext, event: T.MachineEvent) => {
Expand Down Expand Up @@ -34,6 +35,7 @@ export const initPosition = assign({

export const updateStepPosition = assign({
position: (context: T.MachineContext, event: T.MachineEvent): any => {
logger('updateStepPosition', event)
return event.payload.position
},
})
Expand All @@ -54,8 +56,6 @@ export const loadNext = send(
export const stepNext = send(
(context: T.MachineContext): T.Action => {
const level: TT.Level = selectors.currentLevel(context)
console.log(`STEP_NEXT: ${JSON.stringify(context.position)}`)
console.log(`STEP NEXT LEVEL ${JSON.stringify(level)}`)
return getStepNext(context.position, level)
},
)
Expand Down
13 changes: 11 additions & 2 deletions web-app/src/services/state/actions/utils/stepNext.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,17 @@ const level: TT.Level = {
}

describe('stepNext', () => {
it('should LOAD_NEXT_STEP when there is another step', () => {
it('should LOAD_NEXT_STEP when there is another step (1)', () => {
const position = { levelId: '1', stepId: '1.1', complete: true }
const result = getStepNext(position, level)
expect(result).toEqual({
type: 'LOAD_NEXT_STEP',
payload: {
step: level.steps[1],
},
})
})
it('should LOAD_NEXT_STEP when there is another step (2)', () => {
const position = { levelId: '1', stepId: '1.2', complete: false }
const result = getStepNext(position, level)
expect(result).toEqual({
Expand All @@ -36,7 +46,6 @@ describe('stepNext', () => {
},
})
})

it('should LEVEL_COMPLETE when there are no steps', () => {
const position = { levelId: '1', stepId: null, complete: false }
const result = getStepNext(position, { ...level, steps: [] })
Expand Down
4 changes: 1 addition & 3 deletions web-app/src/services/state/actions/utils/stepNext.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,7 @@ import * as TT from 'typings/tutorial'
import logger from '../../../../services/logger'

const getStepNext = (position: T.Position, level: TT.Level): T.Action => {
logger('getStepNext position', position)
const { steps } = level

if (steps.length) {
const stepIndex = steps.findIndex((s: TT.Step) => s.id === position.stepId)
const finalStepIndex = steps.length - 1
Expand All @@ -14,7 +12,7 @@ const getStepNext = (position: T.Position, level: TT.Level): T.Action => {
return {
type: 'LOAD_NEXT_STEP',
payload: {
step: nextStep,
position: { levelId: position.levelId, stepId: nextStep.id, complete: false },
},
}
}
Expand Down
2 changes: 1 addition & 1 deletion web-app/src/services/state/machine.ts
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,7 @@ export const createMachine = (options: any) => {
on: {
LOAD_NEXT_STEP: {
target: 'Normal',
actions: ['loadStep'],
actions: ['loadStep', 'updateStepPosition'],
},
LEVEL_COMPLETE: 'LevelComplete',
},
Expand Down