-
Notifications
You must be signed in to change notification settings - Fork 48
Expand file tree
/
Copy pathcontainer.tsx
More file actions
32 lines (27 loc) · 896 Bytes
/
container.tsx
File metadata and controls
32 lines (27 loc) · 896 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
import * as React from 'react'
import { loadMarkdown, saveMarkdown } from './service'
import { View } from './view'
import { ContainerProps } from '../types'
export const Container: React.FC<ContainerProps> = (props) => {
const [markdown, setMarkdown] = React.useState<undefined | null | string>()
React.useEffect(() => {
loadMarkdown(props.store, props.subject.uri)
.then((markdown) => setMarkdown(markdown))
.catch(() => setMarkdown(null))
})
if (typeof markdown === 'undefined') {
return <section aria-busy={true}>Loading…</section>
}
if (markdown === null) {
return <section>Error loading markdown :(</section>
}
const saveHandler = (newMarkdown: string) => saveMarkdown(props.store, props.subject.uri, newMarkdown)
return (
<section>
<View
markdown={markdown}
onSave={saveHandler}
/>
</section>
)
}