Skip to content

Commit 0dd5619

Browse files
committed
feat(ReadmeHistory): create component that shows versioned Readmes
As our first step, let's just have a component that talks right to the `/render/` endpoint and injects the resulting html into the page. Later, we can add in viewing the raw underlying file. We will need to go through this process when we add transform scripts into the Desktop, but we can punt on this until then.
1 parent ae8c39f commit 0dd5619

File tree

5 files changed

+54
-8
lines changed

5 files changed

+54
-8
lines changed

app/components/DatasetComponent.tsx

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import BodyContainer from '../containers/BodyContainer'
77
import StructureContainer from '../containers/StructureContainer'
88
import ParseError from './ParseError'
99
import ReadmeContainer from '../containers/ReadmeContainer'
10+
import ReadmeHistoryContainer from '../containers/ReadmeHistoryContainer'
1011
import { CSSTransition } from 'react-transition-group'
1112
import SpinnerWithIcon from './chrome/SpinnerWithIcon'
1213

@@ -65,7 +66,9 @@ const DatasetComponent: React.FunctionComponent<DatasetComponentProps> = (props:
6566
appear={true}
6667
>
6768
<div className='transition-wrap'>
68-
<ReadmeContainer />
69+
{history
70+
? <ReadmeHistoryContainer />
71+
: <ReadmeContainer />}
6972
</div>
7073
</CSSTransition>
7174
<CSSTransition

app/components/ReadmeHistory.tsx

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
import * as React from 'react'
2+
3+
interface ReadmeHistoryProps {
4+
peername: string
5+
name: string
6+
path: string
7+
}
8+
9+
const ReadmeHistory: React.FunctionComponent<ReadmeHistoryProps> = (props) => {
10+
const { peername, name, path } = props
11+
const divElem = React.useRef<HTMLDivElement>(null)
12+
React.useEffect(() => {
13+
fetch(`http://localhost:2503/render/${peername}/${name}/at/${path}`)
14+
.then(async (res) => res.text())
15+
.then((render) => {
16+
if (divElem && divElem.current) {
17+
divElem.current.innerHTML = render
18+
}
19+
})
20+
}, [peername, name, path])
21+
return (
22+
<div
23+
// use "editor-preview" class to piggie-back off the simplemde styling
24+
className="editor-preview"
25+
ref={divElem}
26+
>loading...
27+
</div>
28+
)
29+
}
30+
31+
export default ReadmeHistory

app/containers/ReadmeContainer.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ const mapStateToProps = (state: Store) => {
2020
}
2121
}
2222

23-
const mergeProps = (props: any, actions: any): ReadmeProps => {
23+
const mergeProps = (props: any, actions: any): ReadmeProps => { //eslint-disable-line
2424
return { ...props, ...actions }
2525
}
2626

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
import { connect } from 'react-redux'
2+
import ReadmeHistory from '../components/ReadmeHistory'
3+
import Store from '../models/store'
4+
5+
const mapStateToProps = (state: Store) => {
6+
const { selections } = state
7+
8+
const { peername, name, commit } = selections
9+
10+
// get data for the currently selected component
11+
return {
12+
peername,
13+
path: commit,
14+
name
15+
}
16+
}
17+
18+
export default connect(mapStateToProps)(ReadmeHistory)

app/reducers/commitDetail.ts

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,6 @@ const initialState: CommitDetails = {
1515
status: {},
1616
isLoading: true,
1717
components: {
18-
readme: {
19-
value: ''
20-
},
2118
body: {
2219
value: [],
2320
pageInfo: initialPageInfo
@@ -54,9 +51,6 @@ const commitDetailsReducer: Reducer = (state = initialState, action: AnyAction):
5451
published,
5552
isLoading: false,
5653
components: {
57-
readme: {
58-
value: dataset && dataset.readme ? atob(dataset.readme.scriptBytes) : ''
59-
},
6054
body: initialState.components.body,
6155
meta: {
6256
value: dataset.meta

0 commit comments

Comments
 (0)