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

Commit4a71bf7

Browse files
authored
Merge pull requestcoderoad#351 from coderoad/validate-tutorial-url
Validate tutorial url
2 parents3694916 +f91e000 commit4a71bf7

File tree

3 files changed

+30
-6
lines changed

3 files changed

+30
-6
lines changed

‎web-app/src/containers/SelectTutorial/LoadTutorialSummary.tsx

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,37 @@
11
import*asReactfrom'react'
2+
import{Dialog}from'@alifd/next'
23
importuseFetchfrom'../../services/hooks/useFetch'
34
import*asTTfrom'typings/tutorial'
45
importLoadingPagefrom'../Loading'
56

67
interfaceProps{
78
url:string
89
onLoadSummary(data:TT.Tutorial):void
10+
onReturnToSelection():void
911
}
1012

1113
constLoadTutorialSummary=(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<LoadingPagetext="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
returnnull
2537
}

‎web-app/src/containers/SelectTutorial/forms/TutorialUrl.tsx

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,23 @@ interface Props {
99
onTutorialLoad(url:string):void
1010
}
1111

12+
consturlRegex=/[-a-zA-Z0-9@:%._\+~#=]{1,256}\.[a-zA-Z0-9()]{1,6}\b([-a-zA-Z0-9()@:%_\+.~#?&//=]*)\.json/
13+
1214
constTutorialUrl=(props:Props)=>{
1315
const[url,setUrl]=React.useState(props.defaultUrl)
16+
const[inputState,setInputState]=React.useState<undefined|'success'|'error'>()
17+
1418
constonSubmit=(e:any)=>{
1519
e.preventDefault()
1620
logger(`Tutorial url:${url}`)
1721
props.onTutorialLoad(url)
1822
}
1923

24+
consthandleChange=(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
<Formstyle={{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-
<ButtonhtmlType="submit"type="primary">
42+
<ButtonhtmlType="submit"type="primary"disabled={inputState!=='success'}>
3343
Load
3444
</Button>{' '}
3545
&nbsp;&nbsp;

‎web-app/src/containers/SelectTutorial/index.tsx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,9 @@ const SelectTutorialPage = (props: Props) => {
5858
setTab={setTab}
5959
/>
6060
)}
61-
{page==='loading'&&url&&<LoadTutorialSummaryurl={url}onLoadSummary={onLoadSummary}/>}
61+
{page==='loading'&&url&&(
62+
<LoadTutorialSummaryurl={url}onLoadSummary={onLoadSummary}onReturnToSelection={()=>setPage('form')}/>
63+
)}
6264
{page==='summary'&&data&&<TutorialOverviewonNext={onNext}tutorial={data}onClear={onClear}/>}
6365
</div>
6466
)

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp