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"
|
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-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-26 20:08:52 +00:00
|
|
|
|
|
|
|
|
2021-04-29 14:58:31 +00:00
|
|
|
/**
|
|
|
|
* A {@link BoxFull} listing all the user's archived 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 BoxRepositoriesArchived({ ...props }) {
|
2021-05-02 16:10:09 +00:00
|
|
|
const {user, fetchDataAuth} = useContext(ContextUser)
|
2021-05-10 13:22:07 +00:00
|
|
|
const {data, error} = useDataImmediately(fetchDataAuth, "GET", "/api/v1/repositories/", {
|
2021-04-26 20:08:52 +00:00
|
|
|
"onlyDead": true,
|
|
|
|
})
|
|
|
|
|
|
|
|
let contents;
|
2021-05-10 12:13:12 +00:00
|
|
|
if(error) {
|
2021-04-26 20:08:52 +00:00
|
|
|
contents = <BoxAlert color={"Red"}>{error.toString()}</BoxAlert>
|
|
|
|
}
|
2021-05-10 12:13:12 +00:00
|
|
|
else if(data) {
|
2021-04-26 20:08:52 +00:00
|
|
|
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={false}
|
|
|
|
canDelete={repo["owner"]["username"] === user["username"]}
|
|
|
|
/>
|
|
|
|
))
|
2021-04-26 20:08:52 +00:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
contents = <i>There's nothing here.</i>
|
|
|
|
}
|
|
|
|
}
|
2021-05-10 12:13:12 +00:00
|
|
|
else {
|
|
|
|
contents = <Loading/>
|
|
|
|
}
|
2021-04-26 20:08:52 +00:00
|
|
|
|
|
|
|
return (
|
|
|
|
<BoxFull header={"Your archived repositories"} {...props}>
|
|
|
|
{contents}
|
|
|
|
</BoxFull>
|
|
|
|
)
|
|
|
|
}
|