File tree Expand file tree Collapse file tree 14 files changed +135
-39
lines changed Expand file tree Collapse file tree 14 files changed +135
-39
lines changed Original file line number Diff line number Diff line change 11import * as React from 'react'
22
3- import Cond from './components/Cond '
4- import Loading from './components/Loading '
3+ import Router from './components/Router '
4+ import LoadingPage from './containers/LoadingPage '
55import ContinuePage from './containers/Continue'
66import NewPage from './containers/New'
77import TutorialPage from './containers/Tutorial'
88
9+ const { Route } = Router
10+
911interface Props {
1012 state : any
1113}
@@ -37,21 +39,22 @@ const Routes = ({ state }: Props) => {
3739 }
3840 } )
3941
40- // TODO: refactor cond to user <Router><Route> and accept first route as if/else if
4142 return (
4243 < div style = { { ...styles . page , ...dimensions } } >
43- < Cond state = { state } path = "SelectTutorial.Startup" >
44- < Loading />
45- </ Cond >
46- < Cond state = { state } path = "SelectTutorial.NewTutorial" >
47- < NewPage />
48- </ Cond >
49- < Cond state = { state } path = "SelectTutorial.ContinueTutorial" >
50- < ContinuePage />
51- </ Cond >
52- < Cond state = { state } path = "Tutorial" >
53- < TutorialPage state = { state } />
54- </ Cond >
44+ < Router state = { state } >
45+ < Route path = "SelectTutorial.Startup" >
46+ < LoadingPage text = "Launching..." />
47+ </ Route >
48+ < Route path = "SelectTutorial.NewTutorial" >
49+ < NewPage />
50+ </ Route >
51+ < Route path = "SelectTutorial.ContinueTutorial" >
52+ < ContinuePage />
53+ </ Route >
54+ < Route path = "Tutorial" >
55+ < TutorialPage state = { state } />
56+ </ Route >
57+ </ Router >
5558 </ div >
5659 )
5760}
Original file line number Diff line number Diff line change 11export function stateMatch ( state : any , statePath : string ) {
22 let current = state
3- let paths = statePath . split ( '.' )
3+ const paths = statePath . split ( '.' )
44 let complete = false
55 try {
66 for ( const p of paths ) {
Original file line number Diff line number Diff line change 11import * as React from 'react'
2+ import { Loading } from '@alifd/next'
23
3- const Loading = ( ) => {
4- return < div > Loading... </ div >
4+ interface Props {
5+ text : string
56}
67
7- export default Loading
8+ const LoadingComponent = ( { text } : Props ) => {
9+ return < Loading tip = { text } />
10+ }
11+
12+ export default LoadingComponent
Original file line number Diff line number Diff line change 1+ import * as React from 'react'
2+
3+ interface Props {
4+ children : any
5+ path : string
6+ }
7+
8+ const Route = ( { children } : Props ) => children
9+
10+ export default Route
Original file line number Diff line number Diff line change 1+ import * as React from 'react'
2+ import Route from './Route'
3+ import { stateMatch } from '../Cond/utils/state'
4+
5+ interface Props {
6+ state : string
7+ children : any
8+ }
9+
10+ // router finds first state match of <Route path='' />
11+ const Router = ( { state, children } : Props ) => {
12+ const childArray = React . Children . toArray ( children )
13+ for ( const child of childArray ) {
14+ if ( stateMatch ( state , child . props . path ) ) {
15+ return child . props . children
16+ }
17+ }
18+ console . warn ( `No Route matches for ${ state } ` )
19+ return null
20+ }
21+
22+ Router . Route = Route
23+
24+ export default Router
Original file line number Diff line number Diff line change 1+ import * as React from 'react'
2+ import Loading from '../components/Loading'
3+
4+ interface Props {
5+ text : string
6+ }
7+
8+ const styles = {
9+ page : {
10+ display : 'flex' ,
11+ alignItems : 'center' ,
12+ justifyContent : 'center' ,
13+ width : '100%' ,
14+ height : '100%' ,
15+ } ,
16+ }
17+
18+ const LoadingPage = ( { text } : Props ) => (
19+ < div style = { styles . page } >
20+ < Loading text = { text } />
21+ </ div >
22+ )
23+
24+ export default LoadingPage
Original file line number Diff line number Diff line change 11import * as React from 'react'
22import { Button } from '@alifd/next'
3+
34import Cond from '../../components/Cond'
45import DataContext from '../../utils/DataContext'
56import { send } from '../../utils/vscode'
7+ import LoadingPage from '../../containers/LoadingPage'
68
79interface Props {
810 onNew ( tutorialId : string ) : void
@@ -27,7 +29,7 @@ export const NewPage = (props: Props) => {
2729 </ div >
2830 </ Cond >
2931 < Cond state = { state } path = "SelectTutorial.NewTutorial.InitializeTutorial" >
30- < div > Initializing tutorial ...</ div >
32+ < LoadingPage text = "Launching Tutorial ..." / >
3133 </ Cond >
3234 </ div >
3335 )
Original file line number Diff line number Diff line change @@ -4,7 +4,6 @@ import Level from '../../components/Level'
44
55interface LevelProps {
66 send ( action : string ) : void
7- state : any
87}
98
109const LevelPage = ( props : LevelProps ) => {
Original file line number Diff line number Diff line change @@ -3,7 +3,6 @@ import DataContext from '../../utils/DataContext'
33import Stage from '../../components/Stage'
44
55interface PageProps {
6- state : any
76 send ( action : string ) : void
87}
98
Original file line number Diff line number Diff line change @@ -4,7 +4,6 @@ import Summary from '../../components/Summary'
44
55interface PageProps {
66 send ( action : string ) : void
7- state : any
87}
98
109const SummaryPage = ( props : PageProps ) => {
You can’t perform that action at this time.
0 commit comments