File tree Expand file tree Collapse file tree 3 files changed +30
-6
lines changed Top Open diff view settings
web-app/src/containers/SelectTutorial Expand file tree Collapse file tree 3 files changed +30
-6
lines changed Top Open diff view settings Original file line number Diff line number Diff line change 11import * as React from 'react'
2+ import { Dialog } from '@alifd/next'
23import useFetch from '../../services/hooks/useFetch'
34import * as TT from 'typings/tutorial'
45import LoadingPage from '../Loading'
56
67interface Props {
78 url : string
89 onLoadSummary ( data : TT . Tutorial ) : void
10+ onReturnToSelection ( ) : void
911}
1012
1113const LoadTutorialSummary = ( props : Props ) => {
1214 const { data, error, loading } = useFetch < TT . Tutorial > ( props . url )
15+ if ( ! data ) {
16+ return (
17+ < Dialog
18+ title = "Tutorial Not Found"
19+ visible = { true }
20+ closeable = { false }
21+ footerActions = { [ 'ok' ] }
22+ onOk = { props . onReturnToSelection }
23+ >
24+ No data returned for tutorial
25+ </ Dialog >
26+ )
27+ }
1328 if ( loading ) {
1429 return < LoadingPage text = "Loading tutorial summary..." />
1530 }
1631 if ( error ) {
1732 console . log ( `Failed to load tutorial summary: ${ error } ` )
1833 return < div > Error loading summary</ div >
1934 }
20- if ( ! data ) {
21- return < div > No data returned for tutorial</ div >
22- }
2335 props . onLoadSummary ( data )
2436 return null
2537}
Original file line number Diff line number Diff line change @@ -9,14 +9,23 @@ interface Props {
99 onTutorialLoad ( url : string ) : void
1010}
1111
12+ const urlRegex = / [ - a - z A - Z 0 - 9 @ : % . _ \+ ~ # = ] { 1 , 256 } \. [ a - z A - Z 0 - 9 ( ) ] { 1 , 6 } \b ( [ - a - z A - Z 0 - 9 ( ) @ : % _ \+ . ~ # ? & / / = ] * ) \. j s o n /
13+
1214const TutorialUrl = ( props : Props ) => {
1315 const [ url , setUrl ] = React . useState ( props . defaultUrl )
16+ const [ inputState , setInputState ] = React . useState < undefined | 'success' | 'error' > ( )
17+
1418 const onSubmit = ( e : any ) => {
1519 e . preventDefault ( )
1620 logger ( `Tutorial url: ${ url } ` )
1721 props . onTutorialLoad ( url )
1822 }
1923
24+ const handleChange = ( text : string ) => {
25+ setUrl ( text )
26+ ! ! text . match ( urlRegex ) ? setInputState ( 'success' ) : setInputState ( 'error' )
27+ }
28+
2029 return (
2130 // @ts -ignore seems to be an onSubmit event ts error in lib
2231 < Form style = { { maxWidth : '600px' } } onSubmit = { onSubmit } >
@@ -25,11 +34,12 @@ const TutorialUrl = (props: Props) => {
2534 size = "large"
2635 placeholder = "https://raw.githubusercontent.com/coderoad/fcc-learn-npm/master/coderoad-config.json"
2736 defaultValue = { props . defaultUrl }
28- onChange = { setUrl }
37+ onChange = { handleChange }
38+ state = { inputState }
2939 aria-label = "input url path to coderoad config.json"
3040 />
3141 </ FormItem >
32- < Button htmlType = "submit" type = "primary" >
42+ < Button htmlType = "submit" type = "primary" disabled = { inputState !== 'success' } >
3343 Load
3444 </ Button > { ' ' }
3545
Original file line number Diff line number Diff line change @@ -58,7 +58,9 @@ const SelectTutorialPage = (props: Props) => {
5858 setTab = { setTab }
5959 />
6060 ) }
61- { page === 'loading' && url && < LoadTutorialSummary url = { url } onLoadSummary = { onLoadSummary } /> }
61+ { page === 'loading' && url && (
62+ < LoadTutorialSummary url = { url } onLoadSummary = { onLoadSummary } onReturnToSelection = { ( ) => setPage ( 'form' ) } />
63+ ) }
6264 { page === 'summary' && data && < TutorialOverview onNext = { onNext } tutorial = { data } onClear = { onClear } /> }
6365 </ div >
6466 )
You can’t perform that action at this time.
0 commit comments