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

47 lines
1.6 KiB
JavaScript
Raw Normal View History

import React, { useCallback, useContext } from "react"
2021-04-21 16:21:30 +00:00
import Style from "./PageRepositories.module.css"
import classNames from "classnames"
import useBackendViewset from "../hooks/useBackendViewset"
import BoxRepositories from "../components/interactive/BoxRepositories"
import { useHistory } from "react-router"
import ContextLanguage from "../contexts/ContextLanguage"
2021-04-21 16:21:30 +00:00
export default function PageRepositories({ children, className, ...props }) {
const bv = useBackendViewset("/api/v1/repositories/", "id")
const history = useHistory()
const {strings} = useContext(ContextLanguage)
const archive = useCallback(
async (pk) => {
await bv.apiRequest("PATCH", `/api/v1/repositories/${pk}`, {
"close": true,
})
await bv.refreshResource(pk)
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}>
<BoxRepositories
header={strings.menuActive}
loading={!bv.firstLoad}
running={bv.running}
repositories={bv.resources.filter(r => r.is_active)}
view={pk => history.push(`/repositories/${pk}`)}
archive={archive}
edit={bv.editResource}
/>
<BoxRepositories
header={strings.menuArchived}
loading={!bv.firstLoad}
running={bv.running}
repositories={bv.resources.filter(r => !r.is_active)}
view={pk => history.push(`/repositories/${pk}`)}
destroy={bv.destroyResource}
/>
2021-04-21 16:21:30 +00:00
</div>
)
}