2021-05-19 17:56:41 +00:00
|
|
|
import React, { useCallback, useContext } from "react"
|
2021-04-21 16:21:30 +00:00
|
|
|
import Style from "./PageRepositories.module.css"
|
|
|
|
import classNames from "classnames"
|
2021-05-12 23:07:17 +00:00
|
|
|
import useBackendViewset from "../hooks/useBackendViewset"
|
2021-05-19 17:56:41 +00:00
|
|
|
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 }) {
|
2021-05-12 23:07:17 +00:00
|
|
|
const bv = useBackendViewset("/api/v1/repositories/", "id")
|
2021-05-19 17:56:41 +00:00
|
|
|
const history = useHistory()
|
|
|
|
const {strings} = useContext(ContextLanguage)
|
2021-05-12 23:07:17 +00:00
|
|
|
|
2021-05-19 17:56:41 +00:00
|
|
|
const archive = useCallback(
|
2021-05-12 23:07:17 +00:00
|
|
|
async (pk) => {
|
2021-05-19 17:56:41 +00:00
|
|
|
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}>
|
2021-05-19 17:56:41 +00:00
|
|
|
<BoxRepositories
|
|
|
|
header={strings.menuActive}
|
|
|
|
loading={!bv.firstLoad}
|
2021-05-12 23:07:17 +00:00
|
|
|
running={bv.running}
|
2021-05-19 17:56:41 +00:00
|
|
|
repositories={bv.resources.filter(r => r.is_active)}
|
|
|
|
view={pk => history.push(`/repositories/${pk}`)}
|
|
|
|
archive={archive}
|
|
|
|
edit={bv.editResource}
|
2021-05-12 23:07:17 +00:00
|
|
|
/>
|
2021-05-19 17:56:41 +00:00
|
|
|
<BoxRepositories
|
|
|
|
header={strings.menuArchived}
|
|
|
|
loading={!bv.firstLoad}
|
2021-05-12 23:07:17 +00:00
|
|
|
running={bv.running}
|
2021-05-19 17:56:41 +00:00
|
|
|
repositories={bv.resources.filter(r => !r.is_active)}
|
|
|
|
view={pk => history.push(`/repositories/${pk}`)}
|
|
|
|
destroy={bv.destroyResource}
|
2021-05-12 23:07:17 +00:00
|
|
|
/>
|
2021-04-21 16:21:30 +00:00
|
|
|
</div>
|
|
|
|
)
|
|
|
|
}
|