Skip to content

Feature/load from GitHub #174

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 17 commits into from
Apr 2, 2020
Prev Previous commit
Next Next commit
cleanup select/summary pages
  • Loading branch information
ShMcK committed Mar 31, 2020
commit a513a80715d34c731509b63045658061252bb159
2 changes: 1 addition & 1 deletion .vscode/extensions.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
// See http://go.microsoft.com/fwlink/?LinkId=827846
// for the documentation about the extensions.json format
"recommendations": ["dbaeumer.vscode-eslint", "apollographql.vscode-apollo"]
"recommendations": ["dbaeumer.vscode-eslint"]
}
9 changes: 5 additions & 4 deletions web-app/src/components/TutorialOverview/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -70,23 +70,24 @@ const styles = {

interface Props {
tutorial: TT.Tutorial
onNext: () => void
onNext(): void
onClear(): void
}

const Summary = (props: Props) => {
return (
<div css={styles.page}>
<div css={styles.content}>
<div css={styles.header}>
{/* <div css={styles.nav}>
<div css={styles.nav}>
<Breadcrumb separator="/">
<Breadcrumb.Item>
<div css={styles.navLink} onClick={props.onBack}>
<div css={styles.navLink} onClick={props.onClear}>
&lt; Back to Tutorials
</div>
</Breadcrumb.Item>
</Breadcrumb>
</div> */}
</div>
<h1 css={styles.title}>{props.tutorial.summary.title}</h1>
<h3>{props.tutorial.summary.description}</h3>
{/* <h5 css={styles.meta}>
Expand Down
34 changes: 34 additions & 0 deletions web-app/src/containers/SelectTutorial/LoadTutorialSummary.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import * as React from 'react'
import useFetch from '../../services/hooks/useFetch'
import * as TT from 'typings/tutorial'
import TutorialOverview from '../../components/TutorialOverview'

interface Props {
url: string
send: any
onClear(): void
}

const LoadTutorialSummary = (props: Props) => {
const { data, error, loading } = useFetch<TT.Tutorial>(props.url)
if (loading) {
return <div>Loading...</div>
}
if (error) {
return <div>{JSON.stringify(error)}</div>
}
if (!data) {
return <div>No data returned</div>
}
const onNext = () => {
props.send({
type: 'TUTORIAL_START',
payload: {
tutorial: data,
},
})
}
return <TutorialOverview onNext={onNext} tutorial={data} onClear={props.onClear} />
}

export default LoadTutorialSummary
43 changes: 43 additions & 0 deletions web-app/src/containers/SelectTutorial/SelectTutorialForm.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
import * as React from 'react'
import useFetch from '../../services/hooks/useFetch'
import { Form, Select } from '@alifd/next'

const FormItem = Form.Item
const Option = Select.Option

// configurable url to tutorials
const tutorialUrl = 'https://raw.githubusercontent.com/coderoad/tutorials/master/tutorials.json'

type TutorialList = Array<{ id: string; title: string; configUrl: string }>

interface Props {
onUrlChange(url: string): void
}

const SelectTutorialForm = (props: Props) => {
const { data, error, loading } = useFetch<TutorialList>(tutorialUrl)
if (loading) {
return <div>Loading...</div>
}
if (error) {
return <div>{JSON.stringify(error)}</div>
}
if (!data) {
return <div>No data returned</div>
}
return (
<Form style={{ maxWidth: '500px' }}>
<FormItem label="Select Tutorial:">
<Select onChange={props.onUrlChange} style={{ width: '100%' }} placeholder="Tutorials...">
{data.map((tutorial) => (
<Option key={tutorial.id} value={tutorial.configUrl}>
{tutorial.title}
</Option>
))}
</Select>
</FormItem>
</Form>
)
}

export default SelectTutorialForm
76 changes: 11 additions & 65 deletions web-app/src/containers/SelectTutorial/index.tsx
Original file line number Diff line number Diff line change
@@ -1,15 +1,13 @@
import * as React from 'react'
import * as T from 'typings'
import * as TT from 'typings/tutorial'
import { Form, Select } from '@alifd/next'
import useFetch from '../../services/hooks/useFetch'
import TutorialOverview from '../../components/TutorialOverview'

const FormItem = Form.Item
const Option = Select.Option
import SelectTutorialForm from './SelectTutorialForm'
import LoadTutorialSummary from './LoadTutorialSummary'

const styles = {
page: {},
page: {
width: '100%',
},
header: {
padding: '1rem',
},
Expand All @@ -24,73 +22,21 @@ interface TutorialsData {
tutorials: TT.Tutorial[]
}

interface GitHubFetchProps {
url: string
send: any
}

const GitHubFetch = (props: GitHubFetchProps) => {
const { data, error, loading } = useFetch<TT.Tutorial>(props.url)
if (loading) {
return <div>Loading...</div>
}
if (error) {
return <div>{JSON.stringify(error)}</div>
}
if (!data) {
return <div>No data returned</div>
}
const onNext = () => {
console.log('called tutorial start')
props.send({
type: 'TUTORIAL_START',
payload: {
tutorial: data,
},
})
}
return <TutorialOverview onNext={onNext} tutorial={data} />
}

const tutorials = [
{
id: '1',
title: 'Basic Node & Express',
configUrl: 'https://raw.githubusercontent.com/coderoad/fcc-basic-node-and-express/master/coderoad-config.json',
},
{
id: '2',
title: 'Learn NPM',
configUrl: 'https://raw.githubusercontent.com/coderoad/fcc-learn-npm/master/coderoad-config.json',
},
]

interface Props {
send: any
context: any
}

const SelectTutorialPage = (props: Props) => {
const [url, setUrl] = React.useState<string | null>(null)
const handleUrlChange = (value: string) => {
setUrl(value)
}
return (
<div css={styles.page}>
<div css={styles.header}>
<Form style={{ maxWidth: '500px' }}>
<FormItem label="Select Tutorial:">
<Select onChange={handleUrlChange} style={{ width: '100%' }}>
{tutorials.map((tutorial) => (
<Option key={tutorial.id} value={tutorial.configUrl}>
{tutorial.title}
</Option>
))}
</Select>
</FormItem>
</Form>
</div>
{url && <GitHubFetch url={url} send={props.send} />}
{!url && (
<div css={styles.header}>
<SelectTutorialForm onUrlChange={setUrl} />
</div>
)}
{url && <LoadTutorialSummary url={url} send={props.send} onClear={() => setUrl(null)} />}
</div>
)
}
Expand Down