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

Commit82973bc

Browse files
authored
Merge pull requestcoderoad#178 from ShMcK/load/tutorial-from-url
Load/tutorial from url
2 parentsb06049c +bf3ae63 commit82973bc

File tree

9 files changed

+171
-147
lines changed

9 files changed

+171
-147
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||''

‎web-app/stories/API.stories.tsx

Lines changed: 0 additions & 43 deletions
This file was deleted.

‎web-app/stories/GitHubFetch.stories.tsx

Lines changed: 0 additions & 19 deletions
This file was deleted.

‎web-app/stories/Overview.stories.tsx

Lines changed: 57 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -1,54 +1,69 @@
1+
import*asTTfrom'../../typings/tutorial'
12
import{linkTo}from'@storybook/addon-links'
23
import{action}from'@storybook/addon-actions'
34
import{storiesOf}from'@storybook/react'
45
importReactfrom'react'
5-
importOverViewPagefrom'../src/containers/Overview/OverviewPage'
6+
importOverViewPagefrom'../src/components/TutorialOverview'
67
importSideBarDecoratorfrom'./utils/SideBarDecorator'
78

89
storiesOf('Overview',module)
910
.addDecorator(SideBarDecorator)
1011
.add('OverView Page',()=>{
11-
constlevels=[
12-
{
13-
id:'L1',
14-
title:'The First Level',
15-
summary:'A Summary of the first level',
12+
consttutorial:TT.Tutorial={
13+
id:'1',
14+
version:'0.1.0',
15+
config:{
16+
testRunner:{command:''},
17+
repo:{uri:'',branch:'master'},
1618
},
17-
{
18-
id:'L2',
19-
title:'The Second Level',
20-
summary:'A Summary of the second level',
19+
summary:{
20+
title:'Manage NPM package.json',
21+
description:'Learn to use the package manager at the core of JavaScript projects.',
2122
},
22-
{
23-
id:'L3',
24-
title:'The Third Level',
25-
summary:'A Summary of the third level',
26-
},
27-
{
28-
id:'L4',
29-
title:'The Fourth Level',
30-
summary:'A Summary of the fourth level',
31-
},
32-
{
33-
id:'L5',
34-
title:'The Fifth Level',
35-
summary:'A Summary of the fifth level',
36-
},
37-
{
38-
id:'L6',
39-
title:'The Sixth Level',
40-
summary:'A Summary of the sixth level',
41-
},
42-
]
43-
return(
44-
<OverViewPage
45-
title="Manage NPM package.json"
46-
description="Learn to use the package manager at the core of JavaScript projects."
47-
createdBy={{name:'Shawn McKay'}}
48-
updatedAt={newDate().toUTCString()}
49-
levels={levels}
50-
onBack={action('back')}
51-
onNext={linkTo('Tutorial SideBar','Level')}
52-
/>
53-
)
23+
levels:[
24+
{
25+
id:'L1',
26+
title:'The First Level',
27+
summary:'A Summary of the first level',
28+
content:'',
29+
steps:[],
30+
},
31+
{
32+
id:'L2',
33+
title:'The Second Level',
34+
summary:'A Summary of the second level',
35+
content:'',
36+
steps:[],
37+
},
38+
{
39+
id:'L3',
40+
title:'The Third Level',
41+
summary:'A Summary of the third level',
42+
content:'',
43+
steps:[],
44+
},
45+
{
46+
id:'L4',
47+
title:'The Fourth Level',
48+
summary:'A Summary of the fourth level',
49+
content:'',
50+
steps:[],
51+
},
52+
{
53+
id:'L5',
54+
title:'The Fifth Level',
55+
summary:'A Summary of the fifth level',
56+
content:'',
57+
steps:[],
58+
},
59+
{
60+
id:'L6',
61+
title:'The Sixth Level',
62+
summary:'A Summary of the sixth level',
63+
content:'',
64+
steps:[],
65+
},
66+
],
67+
}
68+
return<OverViewPagetutorial={tutorial}onClear={action('clear')}onNext={linkTo('Tutorial SideBar','Level')}/>
5469
})

‎web-app/stories/SelectTutorial.stories.tsx

Lines changed: 2 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
import{action}from'@storybook/addon-actions'
22
import{storiesOf}from'@storybook/react'
33
importReactfrom'react'
4-
importSelectTutorialfrom'../src/containers/SelectTutorial/SelectTutorial'
5-
importTutorialItemfrom'../src/containers/SelectTutorial/TutorialItem'
4+
importSelectTutorialfrom'../src/containers/SelectTutorial'
65
importSideBarDecoratorfrom'./utils/SideBarDecorator'
76

87
consttutorialList=[
@@ -31,16 +30,5 @@ const tutorialList = [
3130
storiesOf('Select Tutorial',module)
3231
.addDecorator(SideBarDecorator)
3332
.add('Select Tutorial Page',()=>{
34-
return<SelectTutorialtutorialList={tutorialList}send={action('send')}/>
35-
})
36-
.add('Tutorial Item',()=>{
37-
consttutorial=tutorialList[0]
38-
return(
39-
<TutorialItem
40-
onSelect={action('onSelect')}
41-
title={tutorial.summary.title}
42-
description={tutorial.summary.description}
43-
createdBy={{name:'First Lastname'}}
44-
/>
45-
)
33+
return<SelectTutorialsend={action('send')}context={{}}/>
4634
})

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp