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

Commitbf3ae63

Browse files
committed
load tutorial from url
1 parent083c057 commitbf3ae63

File tree

5 files changed

+112
-29
lines changed

5 files changed

+112
-29
lines changed

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

Lines changed: 22 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,7 @@
11
import*asReactfrom'react'
2-
importuseFetchfrom'../../services/hooks/useFetch'
3-
import{Form,Select}from'@alifd/next'
4-
import{TUTORIAL_URL}from'../../environment'
5-
6-
constFormItem=Form.Item
7-
constOption=Select.Option
2+
import{Radio}from'@alifd/next'
3+
importTutorialSelectfrom'./forms/TutorialSelect'
4+
importTutorialUrlfrom'./forms/TutorialUrl'
85

96
conststyles={
107
formWrapper:{
@@ -14,31 +11,31 @@ const styles = {
1411
},
1512
}
1613

17-
typeTutorialList=Array<{id:string;title:string;configUrl:string}>
18-
1914
interfaceProps{
20-
onUrlChange(url:string):void
15+
tab:string
16+
setTab(tab:'list'|'url'):void
17+
url:string|null
18+
onTutorialLoad(url:string):void
2119
}
2220

2321
constSelectTutorialForm=(props:Props)=>{
24-
// load tutorial from a path to a tutorial list json
25-
const{ data, error, loading}=useFetch<TutorialList>(TUTORIAL_URL)
26-
// TODO: display errors
27-
constselectState=loading ?'loading' :error||!data ?'error' :undefined
2822
return(
2923
<divcss={styles.formWrapper}>
30-
<Formstyle={{maxWidth:'500px'}}>
31-
<FormItemlabel="Select Tutorial:">
32-
<SelectonChange={props.onUrlChange}style={{width:'100%'}}placeholder="Tutorials..."state={selectState}>
33-
{data&&
34-
data.map((tutorial)=>(
35-
<Optionkey={tutorial.id}value={tutorial.configUrl}>
36-
{tutorial.title}
37-
</Option>
38-
))}
39-
</Select>
40-
</FormItem>
41-
</Form>
24+
<Radio.Group
25+
style={{marginLeft:8}}
26+
shape="button"
27+
value={props.tab}
28+
//@ts-ignore ts lib validation issue
29+
onChange={props.setTab}
30+
>
31+
<Radiovalue="list">List</Radio>
32+
<Radiovalue="url">URL</Radio>
33+
{/* <Radio value="file">File</Radio> */}
34+
</Radio.Group>
35+
<br/>
36+
<br/>
37+
{props.tab==='list'&&<TutorialSelectonTutorialLoad={props.onTutorialLoad}/>}
38+
{props.tab==='url'&&<TutorialUrlonTutorialLoad={props.onTutorialLoad}defaultUrl={props.url||''}/>}
4239
</div>
4340
)
4441
}
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
import*asReactfrom'react'
2+
importuseFetchfrom'../../../services/hooks/useFetch'
3+
import{TUTORIAL_LIST_URL}from'../../../environment'
4+
import{Form,Select}from'@alifd/next'
5+
6+
constFormItem=Form.Item
7+
constOption=Select.Option
8+
9+
typeTutorialList=Array<{id:string;title:string;configUrl:string}>
10+
11+
interfaceProps{
12+
onTutorialLoad(url:string):void
13+
}
14+
15+
constTutorialSelect=(props:Props)=>{
16+
// load tutorial from a path to a tutorial list json
17+
const{ data, error, loading}=useFetch<TutorialList>(TUTORIAL_LIST_URL)
18+
// TODO: display errors
19+
constselectState=loading ?'loading' :error||!data ?'error' :undefined
20+
return(
21+
<Formstyle={{maxWidth:'500px'}}>
22+
<FormItemlabel="Select Tutorial:">
23+
<Select
24+
onChange={props.onTutorialLoad}
25+
style={{width:'100%'}}
26+
placeholder="Tutorials..."
27+
state={selectState}
28+
>
29+
{data&&
30+
data.map((tutorial)=>(
31+
<Optionkey={tutorial.id}value={tutorial.configUrl}>
32+
{tutorial.title}
33+
</Option>
34+
))}
35+
</Select>
36+
</FormItem>
37+
</Form>
38+
)
39+
}
40+
41+
exportdefaultTutorialSelect
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
import*asReactfrom'react'
2+
import{Button,Form,Radio,Input}from'@alifd/next'
3+
4+
constFormItem=Form.Item
5+
6+
interfaceProps{
7+
defaultUrl:string
8+
onTutorialLoad(url:string):void
9+
}
10+
11+
constTutorialUrl=(props:Props)=>{
12+
const[url,setUrl]=React.useState(props.defaultUrl)
13+
constonSubmit=(e:any)=>{
14+
e.preventDefault()
15+
console.log('tutorial url',url)
16+
props.onTutorialLoad(url)
17+
}
18+
19+
return(
20+
//@ts-ignore seems to be an onSubmit event ts error in lib
21+
<Formstyle={{maxWidth:'600px'}}onSubmit={onSubmit}>
22+
<FormItemlabel="URL path to coderoad config.json">
23+
<Input
24+
size="large"
25+
placeholder="https://raw.githubusercontent.com/coderoad/fcc-learn-npm/master/coderoad-config.json"
26+
defaultValue={props.defaultUrl}
27+
onChange={setUrl}
28+
aria-label="input url path to coderoad config.json"
29+
/>
30+
</FormItem>
31+
<ButtonhtmlType="submit"type="primary">
32+
Load
33+
</Button>{' '}
34+
&nbsp;&nbsp;
35+
</Form>
36+
)
37+
}
38+
39+
exportdefaultTutorialUrl

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

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,17 @@ interface Props {
1919
}
2020

2121
constSelectTutorialPage=(props:Props)=>{
22+
const[page,setPage]=React.useState<'form'|'summary'>('form')
23+
const[tab,setTab]=React.useState<'list'|'url'>('list')
2224
const[url,setUrl]=React.useState<string|null>(null)
25+
constonTutorialLoad=(url:string)=>{
26+
setUrl(url)
27+
setPage('summary')
28+
}
2329
return(
2430
<divcss={styles.page}>
25-
{!url&&<SelectTutorialFormonUrlChange={setUrl}/>}
26-
{url&&<LoadTutorialSummaryurl={url}send={props.send}onClear={()=>setUrl(null)}/>}
31+
{page==='form'&&<SelectTutorialFormurl={url}onTutorialLoad={onTutorialLoad}tab={tab}setTab={setTab}/>}
32+
{page==='summary'&&url&&<LoadTutorialSummaryurl={url}send={props.send}onClear={()=>setPage('form')}/>}
2733
</div>
2834
)
2935
}

‎web-app/src/environment.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
// validate .env
2-
constrequiredKeys=['REACT_APP_TUTORIAL_URL']
2+
constrequiredKeys=['REACT_APP_TUTORIAL_LIST_URL']
33
for(constrequiredofrequiredKeys){
44
if(!process.env[required]){
55
thrownewError(`Missing Environmental Variable:${required}`)
@@ -10,4 +10,4 @@ export const DEBUG: boolean = (process.env.REACT_APP_DEBUG || '').toLowerCase()
1010
exportconstVERSION:string=process.env.VERSION||'unknown'
1111
exportconstNODE_ENV:string=process.env.NODE_ENV||'development'
1212
exportconstLOG_STATE:boolean=(process.env.REACT_APP_LOG_STATE||'').toLowerCase()==='true'
13-
exportconstTUTORIAL_URL:string=process.env.REACT_APP_TUTORIAL_URL||''
13+
exportconstTUTORIAL_LIST_URL:string=process.env.REACT_APP_TUTORIAL_LIST_URL||''

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp