1
Fork 0
mirror of https://github.com/pds-nest/nest.git synced 2024-11-26 23:14:19 +00:00
pds-2021-g2-nest/nest_frontend/routes/PageRepositories.js

45 lines
1.6 KiB
JavaScript
Raw Normal View History

2021-05-13 15:05:33 +00:00
import React, { useCallback } 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"
import useBackendViewset from "../hooks/useBackendViewset"
2021-04-21 16:21:30 +00:00
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 {}
2021-05-11 15:05:38 +00:00
},
2021-05-15 16:05:13 +00:00
[bv],
2021-05-11 15:05:38 +00:00
)
2021-05-11 14:33:12 +00:00
2021-04-21 16:21:30 +00:00
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}
/>
2021-04-21 16:21:30 +00:00
</div>
)
}