mirror of
https://github.com/oceanprotocol/docs.git
synced 2024-11-26 19:49:26 +01:00
prototype fetching repo numbers
This commit is contained in:
parent
c96ad66a91
commit
3f378e0a75
@ -23,6 +23,7 @@
|
|||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@oceanprotocol/art": "^1.0.2",
|
"@oceanprotocol/art": "^1.0.2",
|
||||||
|
"axios": "^0.18.0",
|
||||||
"classnames": "^2.2.6",
|
"classnames": "^2.2.6",
|
||||||
"gatsby": "^2.0.52",
|
"gatsby": "^2.0.52",
|
||||||
"gatsby-image": "^2.0.20",
|
"gatsby-image": "^2.0.20",
|
||||||
|
@ -1,8 +1,9 @@
|
|||||||
import React from 'react'
|
import React, { PureComponent } from 'react'
|
||||||
import PropTypes from 'prop-types'
|
import PropTypes from 'prop-types'
|
||||||
import { StaticQuery, graphql } from 'gatsby'
|
import { StaticQuery, graphql } from 'gatsby'
|
||||||
import remark from 'remark'
|
import remark from 'remark'
|
||||||
import remarkReact from 'remark-react'
|
import remarkReact from 'remark-react'
|
||||||
|
import axios from 'axios'
|
||||||
import { ReactComponent as Star } from '../../images/star.svg'
|
import { ReactComponent as Star } from '../../images/star.svg'
|
||||||
import { ReactComponent as Forks } from '../../images/forks.svg'
|
import { ReactComponent as Forks } from '../../images/forks.svg'
|
||||||
import styles from './Repository.module.scss'
|
import styles from './Repository.module.scss'
|
||||||
@ -87,23 +88,66 @@ Links.propTypes = {
|
|||||||
url: PropTypes.string.isRequired
|
url: PropTypes.string.isRequired
|
||||||
}
|
}
|
||||||
|
|
||||||
const Numbers = ({ stargazers, forkCount, url }) => (
|
class Numbers extends PureComponent {
|
||||||
<aside className={styles.repositorynumbers}>
|
static propTypes = {
|
||||||
<a href={`${url}/stargazers`} title="Show Stargazers">
|
stargazers: PropTypes.object.isRequired,
|
||||||
<Star /> <span>{stargazers.totalCount}</span>
|
forkCount: PropTypes.number.isRequired,
|
||||||
</a>
|
url: PropTypes.string.isRequired,
|
||||||
{forkCount > 0 && (
|
name: PropTypes.string.isRequired
|
||||||
<a href={`${url}/network`} title="Show Forks">
|
}
|
||||||
<Forks /> <span>{forkCount}</span>
|
|
||||||
</a>
|
|
||||||
)}
|
|
||||||
</aside>
|
|
||||||
)
|
|
||||||
|
|
||||||
Numbers.propTypes = {
|
state = {
|
||||||
stargazers: PropTypes.object.isRequired,
|
forks: this.props.forkCount,
|
||||||
forkCount: PropTypes.number.isRequired,
|
stars: this.props.stargazers.totalCount
|
||||||
url: PropTypes.string.isRequired
|
}
|
||||||
|
|
||||||
|
url = 'https://oceanprotocol-github.now.sh'
|
||||||
|
|
||||||
|
fetchNumbers = async () => {
|
||||||
|
try {
|
||||||
|
const response = await axios({
|
||||||
|
method: 'get',
|
||||||
|
url: this.url,
|
||||||
|
timeout: 10000, // 10 sec.
|
||||||
|
headers: {
|
||||||
|
'Content-Type': 'application/json'
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
|
const repo = response.data.map(item => {
|
||||||
|
if (item.name === this.props.name) {
|
||||||
|
return item
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
|
const { forks, stars } = repo
|
||||||
|
this.setState({ forks, stars })
|
||||||
|
} catch (error) {
|
||||||
|
console.log(error) // eslint-disable-line no-console
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
componentDidMount() {
|
||||||
|
this.fetchNumbers()
|
||||||
|
}
|
||||||
|
|
||||||
|
render() {
|
||||||
|
const { url } = this.props
|
||||||
|
const { forks, stars } = this.state
|
||||||
|
|
||||||
|
return (
|
||||||
|
<aside className={styles.repositorynumbers}>
|
||||||
|
<a href={`${url}/stargazers`} title="Show Stargazers">
|
||||||
|
<Star /> <span>{stars}</span>
|
||||||
|
</a>
|
||||||
|
{forks > 0 && (
|
||||||
|
<a href={`${url}/network`} title="Show Forks">
|
||||||
|
<Forks /> <span>{forks}</span>
|
||||||
|
</a>
|
||||||
|
)}
|
||||||
|
</aside>
|
||||||
|
)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const Readme = ({ object }) => {
|
const Readme = ({ object }) => {
|
||||||
@ -165,6 +209,7 @@ const Repository = ({ name, links, readme }) => (
|
|||||||
stargazers={stargazers}
|
stargazers={stargazers}
|
||||||
forkCount={forkCount}
|
forkCount={forkCount}
|
||||||
url={url}
|
url={url}
|
||||||
|
name={name}
|
||||||
/>
|
/>
|
||||||
</footer>
|
</footer>
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user