-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(ReadmeHistory): create component that shows versioned
Readme
s
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
Showing
5 changed files
with
54 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters