From eda9ab227f9661443c7c9ea58293c82248910000 Mon Sep 17 00:00:00 2001 From: Stefano Pigozzi <256895@studenti.unimore.it> Date: Tue, 11 May 2021 16:38:56 +0200 Subject: [PATCH] =?UTF-8?q?=E2=9C=8F=20Rename=20useData=20to=20useBackend?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../src/components/interactive/RepositorySummaryBase.js | 8 ++++---- .../frontend/src/components/providers/RepositoryEditor.js | 4 ++-- code/frontend/src/hooks/{useData.js => useBackend.js} | 2 +- .../{useDataImmediately.js => useBackendImmediately.js} | 8 ++++---- code/frontend/src/routes/PageEdit.js | 4 ++-- code/frontend/src/routes/PageRepositories.js | 4 ++-- 6 files changed, 15 insertions(+), 15 deletions(-) rename code/frontend/src/hooks/{useData.js => useBackend.js} (96%) rename code/frontend/src/hooks/{useDataImmediately.js => useBackendImmediately.js} (67%) diff --git a/code/frontend/src/components/interactive/RepositorySummaryBase.js b/code/frontend/src/components/interactive/RepositorySummaryBase.js index 1eb66dd..fd18990 100644 --- a/code/frontend/src/components/interactive/RepositorySummaryBase.js +++ b/code/frontend/src/components/interactive/RepositorySummaryBase.js @@ -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`) diff --git a/code/frontend/src/components/providers/RepositoryEditor.js b/code/frontend/src/components/providers/RepositoryEditor.js index d3c2b90..45b1e67 100644 --- a/code/frontend/src/components/providers/RepositoryEditor.js +++ b/code/frontend/src/components/providers/RepositoryEditor.js @@ -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( () => { diff --git a/code/frontend/src/hooks/useData.js b/code/frontend/src/hooks/useBackend.js similarity index 96% rename from code/frontend/src/hooks/useData.js rename to code/frontend/src/hooks/useBackend.js index 07da6b5..0bac108 100644 --- a/code/frontend/src/hooks/useData.js +++ b/code/frontend/src/hooks/useBackend.js @@ -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) diff --git a/code/frontend/src/hooks/useDataImmediately.js b/code/frontend/src/hooks/useBackendImmediately.js similarity index 67% rename from code/frontend/src/hooks/useDataImmediately.js rename to code/frontend/src/hooks/useBackendImmediately.js index dd5e84d..d6addf4 100644 --- a/code/frontend/src/hooks/useDataImmediately.js +++ b/code/frontend/src/hooks/useBackendImmediately.js @@ -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( () => { diff --git a/code/frontend/src/routes/PageEdit.js b/code/frontend/src/routes/PageEdit.js index 14c68d7..74eaeb2 100644 --- a/code/frontend/src/routes/PageEdit.js +++ b/code/frontend/src/routes/PageEdit.js @@ -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) { diff --git a/code/frontend/src/routes/PageRepositories.js b/code/frontend/src/routes/PageRepositories.js index 8917551..d68a3fc 100644 --- a/code/frontend/src/routes/PageRepositories.js +++ b/code/frontend/src/routes/PageRepositories.js @@ -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) {