File tree Expand file tree Collapse file tree 4 files changed +26
-17
lines changed
web-app/src/containers/SelectTutorial Expand file tree Collapse file tree 4 files changed +26
-17
lines changed Original file line number Diff line number Diff line change @@ -5,7 +5,7 @@ import Loading from '../Loading'
55
66interface Props {
77 url : string
8- onSetDataFromUrl ( data : TT . Tutorial ) : void
8+ onLoadSummary ( data : TT . Tutorial ) : void
99}
1010
1111const LoadTutorialSummary = ( props : Props ) => {
@@ -20,7 +20,7 @@ const LoadTutorialSummary = (props: Props) => {
2020 if ( ! data ) {
2121 return < div > No data returned for tutorial</ div >
2222 }
23- props . onSetDataFromUrl ( data )
23+ props . onLoadSummary ( data )
2424 return null
2525}
2626
Original file line number Diff line number Diff line change 1+ import * as TT from 'typings/tutorial'
12import * as React from 'react'
23import { Radio } from '@alifd/next'
34import TutorialSelect from './forms/TutorialSelect'
@@ -16,7 +17,8 @@ interface Props {
1617 tab : string
1718 setTab ( tab : 'list' | 'url' ) : void
1819 url : string | null
19- onTutorialLoad ( url : string ) : void
20+ onTutorialLoadFromUrl ( url : string ) : void
21+ onLoadSummary ( data : TT . Tutorial | null ) : void
2022}
2123
2224const SelectTutorialForm = ( props : Props ) => {
@@ -35,9 +37,9 @@ const SelectTutorialForm = (props: Props) => {
3537 </ Radio . Group >
3638 < br />
3739 < br />
38- { props . tab === 'list' && < TutorialSelect onTutorialLoad = { props . onTutorialLoad } /> }
39- { props . tab === 'url' && < TutorialUrl onTutorialLoad = { props . onTutorialLoad } defaultUrl = { props . url || '' } /> }
40- { props . tab === 'file' && < TutorialFile onTutorialLoad = { props . onTutorialLoad } /> }
40+ { props . tab === 'list' && < TutorialSelect onTutorialLoad = { props . onTutorialLoadFromUrl } /> }
41+ { props . tab === 'url' && < TutorialUrl onTutorialLoad = { props . onTutorialLoadFromUrl } defaultUrl = { props . url || '' } /> }
42+ { props . tab === 'file' && < TutorialFile onLoadSummary = { props . onLoadSummary } /> }
4143 </ div >
4244 )
4345}
Original file line number Diff line number Diff line change 11import * as React from 'react'
2+ import * as TT from 'typings/tutorial'
23import { Form } from '@alifd/next'
34
45const FormItem = Form . Item
56
67interface Props {
7- onTutorialLoad ( url : string ) : void
8+ onLoadSummary ( data : TT . Tutorial ) : void
89}
910
1011const TutorialFile = ( props : Props ) => {
11- const [ json , setJson ] = React . useState < JSON | null > ( null )
12-
1312 const onChange = ( evt : any ) => {
1413 const files = evt . target . files
1514
@@ -20,9 +19,9 @@ const TutorialFile = (props: Props) => {
2019 const uploadedFile = files [ 0 ]
2120 const reader = new FileReader ( )
2221 reader . onload = ( e : any ) => {
23- // TODO: handle errors from bad JSON
24- const fileJson : JSON = JSON . parse ( e . target . result )
25- setJson ( fileJson )
22+ // TODO: handle errors from invalid JSON
23+ const fileJson : TT . Tutorial = JSON . parse ( e . target . result )
24+ props . onLoadSummary ( fileJson )
2625 }
2726 reader . readAsText ( uploadedFile )
2827 }
@@ -32,7 +31,7 @@ const TutorialFile = (props: Props) => {
3231 < FormItem label = "Load coderoad config.json" >
3332 < input type = "file" accept = "application/json" onChange = { onChange } />
3433 </ FormItem >
35-
34+ < br />
3635 </ Form >
3736 )
3837}
Original file line number Diff line number Diff line change @@ -34,11 +34,11 @@ const SelectTutorialPage = (props: Props) => {
3434 } ,
3535 } )
3636 }
37- const onTutorialLoad = ( url : string ) => {
37+ const onTutorialLoadFromUrl = ( url : string ) => {
3838 setUrl ( url )
3939 setPage ( 'loading' )
4040 }
41- const onSetDataFromUrl = ( d : TT . Tutorial ) => {
41+ const onLoadSummary = ( d : TT . Tutorial ) => {
4242 setData ( d )
4343 setPage ( 'summary' )
4444 }
@@ -48,8 +48,16 @@ const SelectTutorialPage = (props: Props) => {
4848 }
4949 return (
5050 < div css = { styles . page } >
51- { page === 'form' && < SelectTutorialForm url = { url } onTutorialLoad = { onTutorialLoad } tab = { tab } setTab = { setTab } /> }
52- { page === 'loading' && url && < LoadTutorialSummary url = { url } onSetDataFromUrl = { onSetDataFromUrl } /> }
51+ { page === 'form' && (
52+ < SelectTutorialForm
53+ url = { url }
54+ onLoadSummary = { onLoadSummary }
55+ onTutorialLoadFromUrl = { onTutorialLoadFromUrl }
56+ tab = { tab }
57+ setTab = { setTab }
58+ />
59+ ) }
60+ { page === 'loading' && url && < LoadTutorialSummary url = { url } onLoadSummary = { onLoadSummary } /> }
5361 { page === 'summary' && data && < TutorialOverview onNext = { onNext } tutorial = { data } onClear = { onClear } /> }
5462 </ div >
5563 )
You can’t perform that action at this time.
0 commit comments