2021-08-29 03:31:10 +00:00
|
|
|
import * as React from "react"
|
|
|
|
import {Panel, Anchor} from "@steffo/bluelib-react";
|
2021-08-29 18:42:35 +00:00
|
|
|
import {FontAwesomeIcon} from "@fortawesome/react-fontawesome"
|
2021-08-29 03:31:10 +00:00
|
|
|
import Style from "./Project.module.css"
|
2021-08-29 18:42:35 +00:00
|
|
|
import { faStar } from "@fortawesome/free-solid-svg-icons"
|
2021-08-29 03:31:10 +00:00
|
|
|
|
|
|
|
|
2022-02-19 02:29:14 +00:00
|
|
|
export function Project({user, repo, lang}) {
|
2021-08-29 03:31:10 +00:00
|
|
|
const [data, setData] = React.useState(null)
|
|
|
|
const [error, setError] = React.useState(null)
|
|
|
|
|
|
|
|
const fetchData = React.useCallback(
|
|
|
|
() => {
|
|
|
|
fetch(`https://api.github.com/repos/${user}/${repo}`)
|
|
|
|
.then(r => r.json())
|
|
|
|
.then(d => setData(d))
|
|
|
|
.catch(e => setError(e))
|
|
|
|
},
|
|
|
|
[user, repo, setData, setError]
|
|
|
|
)
|
|
|
|
|
|
|
|
React.useEffect(
|
|
|
|
() => {
|
|
|
|
fetchData()
|
|
|
|
},
|
|
|
|
[fetchData]
|
|
|
|
)
|
|
|
|
|
|
|
|
const color = React.useMemo(
|
|
|
|
() => {
|
|
|
|
if(data === null) {
|
|
|
|
return "color-yellow"
|
|
|
|
}
|
|
|
|
else if(error !== null) {
|
|
|
|
return "color-red"
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
return ""
|
|
|
|
}
|
|
|
|
},
|
|
|
|
[data, error]
|
|
|
|
)
|
|
|
|
|
|
|
|
const info = React.useMemo(
|
|
|
|
() => {
|
|
|
|
if(data === null) return (
|
|
|
|
<div className={Style.Description}>Loading...</div>
|
|
|
|
)
|
|
|
|
else if(error !== null) return (
|
|
|
|
<div className={Style.Description}>Error: {error}</div>
|
|
|
|
)
|
|
|
|
|
|
|
|
return <>
|
|
|
|
<div className={Style.Description}>
|
|
|
|
{data["description"]}
|
|
|
|
</div>
|
|
|
|
<div className={Style.Stars}>
|
2021-10-25 11:39:41 +00:00
|
|
|
<Anchor href={`https://github.com/${user}/${repo}/stargazers`}>
|
|
|
|
<FontAwesomeIcon icon={faStar}/> {data["stargazers_count"]}
|
|
|
|
</Anchor>
|
2021-08-29 03:31:10 +00:00
|
|
|
</div>
|
|
|
|
</>
|
|
|
|
},
|
2021-10-25 11:39:41 +00:00
|
|
|
[user, repo, data, error]
|
2021-08-29 03:31:10 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
return (
|
|
|
|
<Panel className={Style.Project} bluelibClassNames={color}>
|
|
|
|
<div className={Style.Title}>
|
|
|
|
<Anchor href={`https://github.com/${user}/${repo}`}>
|
|
|
|
{repo}
|
|
|
|
</Anchor>
|
|
|
|
</div>
|
|
|
|
{info}
|
|
|
|
</Panel>
|
|
|
|
)
|
|
|
|
}
|