1
Fork 0
mirror of https://github.com/pds-nest/nest.git synced 2024-11-26 06:54:18 +00:00
pds-2021-g2-nest/code/frontend/src/routes/PageRepositories.js

33 lines
1.4 KiB
JavaScript
Raw Normal View History

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:38:56 +00:00
import useBackendImmediately from "../hooks/useBackendImmediately"
2021-05-11 14:33:12 +00:00
import ContextUser from "../contexts/ContextUser"
2021-05-11 15:05:38 +00:00
import renderContents from "../utils/renderContents"
2021-04-21 16:21:30 +00:00
export default function PageRepositories({ children, className, ...props }) {
2021-05-11 14:37:15 +00:00
const { fetchDataAuth } = useContext(ContextUser)
2021-05-11 15:05:38 +00:00
const repositoryRequest = useBackendImmediately(fetchDataAuth, "GET", "/api/v1/repositories/")
const contents = renderContents(
repositoryRequest,
data => {
const repositories = [...data["owner"], ...data["spectator"]]
const active = repositories.filter(r => r.is_active)
const archived = repositories.filter(r => !r.is_active)
return <>
<BoxRepositoriesActive repositories={active} refresh={repositoryRequest.fetchNow}/>
<BoxRepositoriesArchived repositories={archived} refresh={repositoryRequest.fetchNow}/>
</>
},
)
2021-05-11 14:33:12 +00:00
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>
)
}