1
Fork 0
mirror of https://github.com/pds-nest/nest.git synced 2024-11-22 04:54:18 +00:00
pds-2021-g2-nest/nest_frontend/routes/PageRepositories.js
2021-05-15 18:05:21 +02:00

44 lines
1.6 KiB
JavaScript

import React, { useCallback } from "react"
import Style from "./PageRepositories.module.css"
import classNames from "classnames"
import BoxRepositoriesActive from "../components/interactive/BoxRepositoriesActive"
import BoxRepositoriesArchived from "../components/interactive/BoxRepositoriesArchived"
import useBackendViewset from "../hooks/useBackendViewset"
export default function PageRepositories({ children, className, ...props }) {
const bv = useBackendViewset("/api/v1/repositories/", "id")
const archiveRepository = useCallback(
async (pk) => {
try {
await bv.apiRequest("PATCH", `/api/v1/repositories/${pk}`, {
"close": true,
})
await bv.refreshResource(pk)
}
catch(e) {
return { error: e }
}
return {}
},
[bv],
)
return (
<div className={classNames(Style.PageRepositories, className)} {...props}>
<BoxRepositoriesActive
repositories={bv.loaded ? bv.resources.filter(r => r.is_active) : null}
archiveRepository={archiveRepository}
destroyRepository={bv.destroyResource}
running={bv.running}
/>
<BoxRepositoriesArchived
repositories={bv.loaded ? bv.resources.filter(r => !r.is_active) : null}
archiveRepository={archiveRepository}
destroyRepository={bv.destroyResource}
running={bv.running}
/>
</div>
)
}