2021-04-26 20:08:52 +00:00
|
|
|
import React, { useContext } from "react"
|
2021-04-29 14:58:31 +00:00
|
|
|
import BoxFull from "../base/BoxFull"
|
|
|
|
import ContextUser from "../../contexts/ContextUser"
|
|
|
|
import useData from "../../hooks/useData"
|
2021-04-26 20:08:52 +00:00
|
|
|
import RepositorySummaryBase from "./RepositorySummaryBase"
|
2021-04-29 14:58:31 +00:00
|
|
|
import Loading from "../base/Loading"
|
|
|
|
import BoxAlert from "../base/BoxAlert"
|
2021-04-26 20:08:52 +00:00
|
|
|
|
|
|
|
|
2021-04-29 14:58:31 +00:00
|
|
|
/**
|
|
|
|
* A {@link BoxFull} listing all the user's active repositories.
|
|
|
|
*
|
|
|
|
* @param props - Additional props to pass to the box.
|
|
|
|
* @returns {JSX.Element}
|
|
|
|
* @constructor
|
|
|
|
*/
|
2021-04-26 20:08:52 +00:00
|
|
|
export default function BoxRepositoriesActive({ ...props }) {
|
|
|
|
const {fetchDataAuth} = useContext(ContextUser)
|
2021-04-30 13:49:18 +00:00
|
|
|
const {data, started, loading, error} = useData(fetchDataAuth, "GET", "/api/v1/repositories/", {
|
2021-04-26 20:08:52 +00:00
|
|
|
"onlyAlive": true,
|
|
|
|
})
|
|
|
|
|
|
|
|
let contents;
|
|
|
|
if(!started || loading) {
|
|
|
|
contents = <Loading/>
|
|
|
|
}
|
|
|
|
else if(error) {
|
|
|
|
contents = <BoxAlert color={"Red"}>{error.toString()}</BoxAlert>
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
let repositories = [...data["owner"], ...data["spectator"]]
|
|
|
|
if(repositories.length > 0) {
|
|
|
|
contents = repositories.map(repo => <RepositorySummaryBase {...repo}/>)
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
contents = <i>There's nothing here.</i>
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return (
|
|
|
|
<BoxFull header={"Your active repositories"} {...props}>
|
|
|
|
{contents}
|
|
|
|
</BoxFull>
|
|
|
|
)
|
|
|
|
}
|