Skip to content

Commit

Permalink
feat(ReadmeHistory): create component that shows versioned Readmes
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
ramfox committed Nov 12, 2019
1 parent ae8c39f commit 0dd5619
Show file tree
Hide file tree
Showing 5 changed files with 54 additions and 8 deletions.
5 changes: 4 additions & 1 deletion app/components/DatasetComponent.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import BodyContainer from '../containers/BodyContainer'
import StructureContainer from '../containers/StructureContainer'
import ParseError from './ParseError'
import ReadmeContainer from '../containers/ReadmeContainer'
import ReadmeHistoryContainer from '../containers/ReadmeHistoryContainer'
import { CSSTransition } from 'react-transition-group'
import SpinnerWithIcon from './chrome/SpinnerWithIcon'

Expand Down Expand Up @@ -65,7 +66,9 @@ const DatasetComponent: React.FunctionComponent<DatasetComponentProps> = (props:
appear={true}
>
<div className='transition-wrap'>
<ReadmeContainer />
{history
? <ReadmeHistoryContainer />
: <ReadmeContainer />}
</div>
</CSSTransition>
<CSSTransition
Expand Down
31 changes: 31 additions & 0 deletions app/components/ReadmeHistory.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import * as React from 'react'

interface ReadmeHistoryProps {
peername: string
name: string
path: string
}

const ReadmeHistory: React.FunctionComponent<ReadmeHistoryProps> = (props) => {
const { peername, name, path } = props
const divElem = React.useRef<HTMLDivElement>(null)
React.useEffect(() => {
fetch(`http://localhost:2503/render/${peername}/${name}/at/${path}`)
.then(async (res) => res.text())
.then((render) => {
if (divElem && divElem.current) {
divElem.current.innerHTML = render
}
})
}, [peername, name, path])
return (
<div
// use "editor-preview" class to piggie-back off the simplemde styling
className="editor-preview"
ref={divElem}
>loading...
</div>
)
}

export default ReadmeHistory
2 changes: 1 addition & 1 deletion app/containers/ReadmeContainer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ const mapStateToProps = (state: Store) => {
}
}

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

Expand Down
18 changes: 18 additions & 0 deletions app/containers/ReadmeHistoryContainer.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import { connect } from 'react-redux'
import ReadmeHistory from '../components/ReadmeHistory'
import Store from '../models/store'

const mapStateToProps = (state: Store) => {
const { selections } = state

const { peername, name, commit } = selections

// get data for the currently selected component
return {
peername,
path: commit,
name
}
}

export default connect(mapStateToProps)(ReadmeHistory)
6 changes: 0 additions & 6 deletions app/reducers/commitDetail.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,6 @@ const initialState: CommitDetails = {
status: {},
isLoading: true,
components: {
readme: {
value: ''
},
body: {
value: [],
pageInfo: initialPageInfo
Expand Down Expand Up @@ -54,9 +51,6 @@ const commitDetailsReducer: Reducer = (state = initialState, action: AnyAction):
published,
isLoading: false,
components: {
readme: {
value: dataset && dataset.readme ? atob(dataset.readme.scriptBytes) : ''
},
body: initialState.components.body,
meta: {
value: dataset.meta
Expand Down

0 comments on commit 0dd5619

Please sign in to comment.