1
Fork 0
mirror of https://github.com/pds-nest/nest.git synced 2024-11-21 20:44:18 +00:00

✏ Rename useData to useBackend

This commit is contained in:
Stefano Pigozzi 2021-05-11 16:38:56 +02:00
parent 809d86758c
commit eda9ab227f
Signed by untrusted user who does not match committer: steffo
GPG key ID: 6965406171929D01
6 changed files with 15 additions and 15 deletions

View file

@ -5,7 +5,7 @@ import { FontAwesomeIcon } from "@fortawesome/react-fontawesome"
import Button from "../base/Button"
import { faArchive, faPencilAlt, faTrash } from "@fortawesome/free-solid-svg-icons"
import { useHistory } from "react-router"
import useData from "../../hooks/useData"
import useBackend from "../../hooks/useBackend"
import ContextUser from "../../contexts/ContextUser"
@ -33,9 +33,9 @@ export default function RepositorySummaryBase(
) {
const { fetchDataAuth } = useContext(ContextUser)
const history = useHistory()
const { fetchNow: archiveThis } = useData(fetchDataAuth, "PATCH", `/api/v1/repositories/${id}`, { "close": true })
const { fetchNow: unarchiveThis } = useData(fetchDataAuth, "PATCH", `/api/v1/repositories/${id}`, { "open": true })
const { fetchNow: deletThis } = useData(fetchDataAuth, "DELETE", `/api/v1/repositories/${id}`)
const { fetchNow: archiveThis } = useBackend(fetchDataAuth, "PATCH", `/api/v1/repositories/${id}`, { "close": true })
const { fetchNow: unarchiveThis } = useBackend(fetchDataAuth, "PATCH", `/api/v1/repositories/${id}`, { "open": true })
const { fetchNow: deletThis } = useBackend(fetchDataAuth, "DELETE", `/api/v1/repositories/${id}`)
const onEditClick = event => {
history.push(`/repositories/${id}/edit`)

View file

@ -10,7 +10,7 @@ import BoxConditions from "../interactive/BoxConditions"
import BoxRepositoryCreate from "../interactive/BoxRepositoryCreate"
import classNames from "classnames"
import ContextUser from "../../contexts/ContextUser"
import useData from "../../hooks/useData"
import useBackend from "../../hooks/useBackend"
export default function RepositoryEditor({
@ -61,7 +61,7 @@ export default function RepositoryEditor({
"owner": user,
"start": _start,
}
const { error, loading, fetchNow } = useData(fetchDataAuth, method, path, body)
const { error, loading, fetchNow } = useBackend(fetchDataAuth, method, path, body)
const save = useCallback(
() => {

View file

@ -10,7 +10,7 @@ import { useCallback, useState } from "react"
* @param body - The body of the HTTP request (it will be JSONified before being sent).
* @param init - Additional `init` parameters to pass to `fetch`.
*/
export default function useData(fetchData, method, path, body, init) {
export default function useBackend(fetchData, method, path, body, init) {
const [error, setError] = useState(null)
const [data, setData] = useState(null)
const [loading, setLoading] = useState(false)

View file

@ -1,9 +1,9 @@
import useData from "./useData"
import useBackend from "./useBackend"
import { useEffect } from "react"
/**
* Like {@link useData}, but runs as soon as the component is rendered.
* Like {@link useBackend}, but runs as soon as the component is rendered.
*
* @param fetchData - The function to use when fetching data.
* @param method - The HTTP method to use.
@ -11,8 +11,8 @@ import { useEffect } from "react"
* @param body - The body of the HTTP request (it will be JSONified before being sent).
* @param init - Additional `init` parameters to pass to `fetch`.
*/
export default function useDataImmediately(fetchData, method, path, body, init) {
const { data, error, loading, fetchNow } = useData(fetchData, method, path, body, init)
export default function useBackendImmediately(fetchData, method, path, body, init) {
const { data, error, loading, fetchNow } = useBackend(fetchData, method, path, body, init)
useEffect(
() => {

View file

@ -3,7 +3,7 @@ import Style from "./PageDashboard.module.css"
import classNames from "classnames"
import BoxHeader from "../components/base/BoxHeader"
import RepositoryEditor from "../components/providers/RepositoryEditor"
import useDataImmediately from "../hooks/useDataImmediately"
import useBackendImmediately from "../hooks/useBackendImmediately"
import ContextUser from "../contexts/ContextUser"
import BoxAlert from "../components/base/BoxAlert"
import Loading from "../components/base/Loading"
@ -11,7 +11,7 @@ import Loading from "../components/base/Loading"
export default function PageEdit({ id, className, ...props }) {
const { fetchDataAuth } = useContext(ContextUser)
const { data, error } = useDataImmediately(fetchDataAuth, "GET", `/api/v1/repositories/${id}`)
const { data, error } = useBackendImmediately(fetchDataAuth, "GET", `/api/v1/repositories/${id}`)
let contents
if(error) {

View file

@ -3,7 +3,7 @@ import Style from "./PageRepositories.module.css"
import classNames from "classnames"
import BoxRepositoriesActive from "../components/interactive/BoxRepositoriesActive"
import BoxRepositoriesArchived from "../components/interactive/BoxRepositoriesArchived"
import useDataImmediately from "../hooks/useDataImmediately"
import useBackendImmediately from "../hooks/useBackendImmediately"
import ContextUser from "../contexts/ContextUser"
import BoxAlert from "../components/base/BoxAlert"
import Loading from "../components/base/Loading"
@ -11,7 +11,7 @@ import Loading from "../components/base/Loading"
export default function PageRepositories({ children, className, ...props }) {
const { fetchDataAuth } = useContext(ContextUser)
const { data, error, fetchNow: refresh } = useDataImmediately(fetchDataAuth, "GET", "/api/v1/repositories/")
const { data, error, fetchNow: refresh } = useBackendImmediately(fetchDataAuth, "GET", "/api/v1/repositories/")
let contents
if(error) {