1
Fork 0
mirror of https://github.com/pds-nest/nest.git synced 2024-11-23 05:24:18 +00:00
pds-2021-g2-nest/code/frontend/src/components/interactive/BoxRepositoriesActive.js

56 lines
1.7 KiB
JavaScript
Raw Normal View History

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"
import RepositorySummaryBase from "./RepositorySummaryBase"
2021-04-29 14:58:31 +00:00
import Loading from "../base/Loading"
import BoxAlert from "../base/BoxAlert"
2021-05-02 16:10:09 +00:00
import { faSearch } from "@fortawesome/free-solid-svg-icons"
2021-05-07 23:40:49 +00:00
import useDataImmediately from "../../hooks/useDataImmediately"
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
*/
export default function BoxRepositoriesActive({ ...props }) {
2021-05-02 16:10:09 +00:00
const {user, fetchDataAuth} = useContext(ContextUser)
2021-05-07 23:40:49 +00:00
const {data, started, loading, error} = useDataImmediately(fetchDataAuth, "GET", "/api/v1/repositories/", {
2021-05-02 16:10:09 +00:00
"onlyActive": 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) {
2021-05-02 16:10:09 +00:00
contents = repositories.map(repo => (
<RepositorySummaryBase
{...repo}
icon={faSearch}
canArchive={true}
canEdit={true}
canDelete={repo["owner"]["username"] === user["username"]}
/>
))
}
else {
contents = <i>There's nothing here.</i>
}
}
return (
<BoxFull header={"Your active repositories"} {...props}>
{contents}
</BoxFull>
)
}