2021-05-11 14:33:12 +00:00
|
|
|
import React, { useContext } from "react"
|
2021-04-21 16:21:30 +00:00
|
|
|
import Style from "./PageRepositories.module.css"
|
|
|
|
import classNames from "classnames"
|
2021-04-29 14:58:31 +00:00
|
|
|
import BoxRepositoriesActive from "../components/interactive/BoxRepositoriesActive"
|
|
|
|
import BoxRepositoriesArchived from "../components/interactive/BoxRepositoriesArchived"
|
2021-05-11 14:33:12 +00:00
|
|
|
import useDataImmediately from "../hooks/useDataImmediately"
|
|
|
|
import ContextUser from "../contexts/ContextUser"
|
|
|
|
import BoxAlert from "../components/base/BoxAlert"
|
|
|
|
import Loading from "../components/base/Loading"
|
2021-04-21 16:21:30 +00:00
|
|
|
|
|
|
|
|
|
|
|
export default function PageRepositories({ children, className, ...props }) {
|
2021-05-11 14:33:12 +00:00
|
|
|
const {fetchDataAuth} = useContext(ContextUser)
|
|
|
|
const {data, error, fetchNow: refresh} = useDataImmediately(fetchDataAuth, "GET", "/api/v1/repositories/")
|
|
|
|
|
|
|
|
let contents;
|
|
|
|
if(error) {
|
|
|
|
contents = <BoxAlert color={"Red"}>{error}</BoxAlert>
|
|
|
|
}
|
|
|
|
else if(data) {
|
|
|
|
const repositories = [...data["owner"], ...data["spectator"]]
|
|
|
|
const active = repositories.filter(r => r.is_active)
|
|
|
|
const archived = repositories.filter(r => !r.is_active)
|
|
|
|
contents = <>
|
|
|
|
<BoxRepositoriesActive repositories={active} refresh={refresh}/>
|
|
|
|
<BoxRepositoriesArchived repositories={archived} refresh={refresh}/>
|
|
|
|
</>
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
contents = <Loading/>
|
|
|
|
}
|
|
|
|
|
2021-04-21 16:21:30 +00:00
|
|
|
return (
|
|
|
|
<div className={classNames(Style.PageRepositories, className)} {...props}>
|
2021-05-11 14:33:12 +00:00
|
|
|
{contents}
|
2021-04-21 16:21:30 +00:00
|
|
|
</div>
|
|
|
|
)
|
|
|
|
}
|