Skip to content

Feature/tutorial from file #179

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 4 commits into from
Apr 3, 2020
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
move load from url into its own function
  • Loading branch information
ShMcK committed Apr 3, 2020
commit f85afd1342a0c7d90f3e304a8df14b6ffdf24155
15 changes: 3 additions & 12 deletions web-app/src/containers/SelectTutorial/LoadTutorialSummary.tsx
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
import * as React from 'react'
import useFetch from '../../services/hooks/useFetch'
import * as TT from 'typings/tutorial'
import TutorialOverview from '../../components/TutorialOverview'
import Loading from '../Loading'

interface Props {
url: string
send: any
onClear(): void
onSetDataFromUrl(data: TT.Tutorial): void
}

const LoadTutorialSummary = (props: Props) => {
Expand All @@ -22,15 +20,8 @@ const LoadTutorialSummary = (props: Props) => {
if (!data) {
return <div>No data returned for tutorial</div>
}
const onNext = () => {
props.send({
type: 'TUTORIAL_START',
payload: {
tutorial: data,
},
})
}
return <TutorialOverview onNext={onNext} tutorial={data} onClear={props.onClear} />
props.onSetDataFromUrl(data)
return null
}

export default LoadTutorialSummary
25 changes: 23 additions & 2 deletions web-app/src/containers/SelectTutorial/index.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import * as TT from 'typings/tutorial'
import * as React from 'react'
import SelectTutorialForm from './SelectTutorialForm'
import TutorialOverview from '../../components/TutorialOverview'
import LoadTutorialSummary from './LoadTutorialSummary'

const styles = {
Expand All @@ -19,17 +21,36 @@ interface Props {
}

const SelectTutorialPage = (props: Props) => {
const [page, setPage] = React.useState<'form' | 'summary'>('form')
const [data, setData] = React.useState<TT.Tutorial | null>()
const [page, setPage] = React.useState<'form' | 'loading' | 'summary'>('form')
const [tab, setTab] = React.useState<'list' | 'url'>('list')
const [url, setUrl] = React.useState<string | null>(null)

const onNext = () => {
props.send({
type: 'TUTORIAL_START',
payload: {
tutorial: data,
},
})
}
const onTutorialLoad = (url: string) => {
setUrl(url)
setPage('loading')
}
const onSetDataFromUrl = (d: TT.Tutorial) => {
setData(d)
setPage('summary')
}
const onClear = () => {
setData(null)
setPage('form')
}
return (
<div css={styles.page}>
{page === 'form' && <SelectTutorialForm url={url} onTutorialLoad={onTutorialLoad} tab={tab} setTab={setTab} />}
{page === 'summary' && url && <LoadTutorialSummary url={url} send={props.send} onClear={() => setPage('form')} />}
{page === 'loading' && url && <LoadTutorialSummary url={url} onSetDataFromUrl={onSetDataFromUrl} />}
{page === 'summary' && data && <TutorialOverview onNext={onNext} tutorial={data} onClear={onClear} />}
</div>
)
}
Expand Down