Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Feature/new continue#5

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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged
ShMcK merged 10 commits intomasterfromfeature/new-continue
Jun 10, 2019
Merged
Show file tree
Hide file tree
Changes from1 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
PrevPrevious commit
NextNext commit
setup pages
  • Loading branch information
@ShMcK
ShMcK committedJun 10, 2019
commit314e71bc2c282867521525a1cbbb8c2a63fb7966
1 change: 1 addition & 0 deletionspackage.json
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -32,6 +32,7 @@
"compile":"tsc -p ./",
"watch":"tsc -watch -p ./",
"postinstall":"node ./node_modules/vscode/bin/install",
"storybook":"cd web-app && npm run storybook",
"test":"npm run build && node ./node_modules/vscode/bin/test"
},
"devDependencies": {
Expand Down
21 changes: 1 addition & 20 deletionsweb-app/src/App.tsx
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -3,31 +3,12 @@ import * as CR from 'typings'

import Debugger from './components/Debugger'
import Routes from './Routes'
import DataContext, { initialState, initialData} from './utils/DataContext'

interface ReceivedEvent {
data: CR.Action
}

const initialState = { SelectTutorial: 'Initial '}
const initialData: CR.MachineContext = {
position: { levelId: '', stageId: '', stepId: '' },
data: {
summary: {
title: '',
description: '',
levelList: [],
},
levels: {},
stages: {},
steps: {},
},
progress: { levels: {}, stages: {}, steps: {}, complete: false },
}

const DataContext = React.createContext({ state: initialState, ...initialData })



const App = () => {
const [state, setState] = React.useState(initialState)
const [data, setData]: [CR.MachineContext, (data: CR.MachineContext) => void] = React.useState(initialData)
Expand Down
14 changes: 11 additions & 3 deletionsweb-app/src/Routes.tsx
View file
Open in desktop
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
import * as React from 'react'
import { send } from './utils/vscode'

import Cond from './components/Cond'
import NewPage from './containers/New'
import ContinuePage from './containers/Continue'
import TutorialPage from './containers/Tutorial'


interface Props {
Expand All@@ -14,11 +14,19 @@ const Routes = ({ state }: Props) => {
// TODO: refactor cond to user <Router><Route> and accept first route as if/else if
return (
<div>
<Cond state={state} path="SelectTutorial.Startup">
<div style={{ backgroundColor: 'red' }}>
<h3>Starting...</h3>
</div>
</Cond>
<Cond state={state} path="SelectTutorial.NewTutorial">
<NewPageonNew={() => send('TUTORIAL_START')}/>
<NewPage />
</Cond>
<Cond state={state} path="SelectTutorial.ContinueTutorial">
<ContinuePage onContinue={() => console.log('continue!')} tutorials={[]} />
<ContinuePage />
</Cond>
<Cond state={state} path="Tutorial">
<TutorialPage />
</Cond>
</div>
)
Expand Down
9 changes: 8 additions & 1 deletionweb-app/src/components/Cond/utils/state.ts
View file
Open in desktop
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,16 @@
export function stateMatch(state: any, statePath: string) {
let current = state
let paths = statePath.split('.')
let complete = false
try {
for (const p of paths) {
current = current[p]
if (p === current && !complete) {
// handle strings
complete = true
} else {
// handle objects
current = current[p]
}
}
} catch (error) {
return false
Expand Down
5 changes: 3 additions & 2 deletionsweb-app/src/containers/Continue/index.tsx
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -9,10 +9,11 @@ interface Props {
// onReset(): void
}

const ContinuePage = (props: Props) => {
exportconst ContinuePage = (props: Props) => {
// context
return (
<div>
<h3>Continue</h3>
{props.tutorials.map((tutorial: CR.Tutorial) => (
<ContinueItem
key={tutorial.id}
Expand All@@ -25,4 +26,4 @@ const ContinuePage = (props: Props) => {
)
}

export default ContinuePage
export default() => <ContinuePage tutorials={[]} onContinue={(id: string) => console.log(id)}/>
27 changes: 19 additions & 8 deletionsweb-app/src/containers/New/index.tsx
View file
Open in desktop
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,36 @@
import * as React from 'react'
import { Button } from '@alifd/next'
import Cond from '../../components/Cond'
import DataContext from '../../utils/DataContext'
import { send } from '../../utils/vscode'

interface Props {
onNew(tutorialId: string): void
}

const NewPage = (props: Props) => {
export const NewPage = (props: Props) => {
const { state } = React.useContext(DataContext)
const [tutorialList, setTutorialList] = React.useState([{ id: '1', title: 'Demo', description: 'A basic demo' }])
// context
return (
<div>
<h2>Start a new Project</h2>
{tutorialList.map(tutorial => (
<Cond state={state} path="SelectTutorial.NewTutorial.SelectTutorial">
<div>
<h3>{tutorial.title}</h3>
<p>{tutorial.description}</p>
<Button onClick={() => props.onNew(tutorial.id)}>Start</Button>
<h2>Start a new Project</h2>
{tutorialList.map(tutorial => (
<div>
<h3>{tutorial.title}</h3>
<p>{tutorial.description}</p>
<Button onClick={() => props.onNew(tutorial.id)}>Start</Button>
</div>
))}
</div>
))}
</Cond>
<Cond state={state} path='SelectTutorial.NewTutorial.InitializeTutorial'>
<div>Initializing tutorial...</div>
</Cond>
</div>
)
}

export default NewPage
export default() => <NewPage onNew={() => send('TUTORIAL_START')} />
14 changes: 14 additions & 0 deletionsweb-app/src/containers/Tutorial/index.tsx
View file
Open in desktop
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
import*asReactfrom'react'

interfaceProps{}

constTutorial=(props:Props)=>{
// useContext
return(
<div>
<h3>Tutorial</h3>
</div>
)
}

exportdefaultTutorial
22 changes: 22 additions & 0 deletionsweb-app/src/utils/DataContext.tsx
View file
Open in desktop
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
import * as React from 'react'
import * as CR from 'typings'

export const initialState = { SelectTutorial: 'Initial ' }
export const initialData: CR.MachineContext = {
position: { levelId: '', stageId: '', stepId: '' },
data: {
summary: {
title: '',
description: '',
levelList: [],
},
levels: {},
stages: {},
steps: {},
},
progress: { levels: {}, stages: {}, steps: {}, complete: false },
}

const DataContext = React.createContext({ state: initialState, ...initialData })

export default DataContext
4 changes: 2 additions & 2 deletionsweb-app/stories/Continue.stories.tsx
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -3,7 +3,7 @@ import React from 'react'
import { storiesOf } from '@storybook/react'
import { action } from '@storybook/addon-actions'

importContinue from '../src/containers/Continue'
import{ ContinuePage } from '../src/containers/Continue'
import demo from './data/basic'

storiesOf('Continue', module).add('Page', () => <Continue tutorials={[demo]} onContinue={action('onContinue')} />)
storiesOf('Continue', module).add('Page', () => <ContinuePage tutorials={[demo]} onContinue={action('onContinue')} />)
4 changes: 2 additions & 2 deletionsweb-app/stories/New.stories.tsx
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -3,6 +3,6 @@ import React from 'react'
import { storiesOf } from '@storybook/react'
import { action } from '@storybook/addon-actions'

importNew from '../src/containers/New'
import{ NewPage } from '../src/containers/New'

storiesOf('New', module).add('Page', () => <New onNew={action('onNew')} />)
storiesOf('New', module).add('Page', () => <NewPage onNew={action('onNew')} />)

[8]ページ先頭

©2009-2025 Movatter.jp