diff --git a/nest_frontend/components/interactive/BoxConditionMap.js b/nest_frontend/components/interactive/BoxConditionMap.js index d2a699b..3dc9ebc 100644 --- a/nest_frontend/components/interactive/BoxConditionMap.js +++ b/nest_frontend/components/interactive/BoxConditionMap.js @@ -6,7 +6,7 @@ import useRepositoryEditor from "../../hooks/useRepositoryEditor" import Condition from "../../utils/Condition" import ContextLanguage from "../../contexts/ContextLanguage" import BoxMap from "../base/BoxMap" -import useMapView from "../../hooks/useMapView" +import useMapAreaState from "../../hooks/useMapAreaState" import osmZoomLevels from "../../utils/osmZoomLevels" @@ -18,7 +18,7 @@ import osmZoomLevels from "../../utils/osmZoomLevels" * @constructor */ export default function BoxConditionMap({ ...props }) { - const mapViewHook = useMapView() + const mapViewHook = useMapAreaState() const { addCondition } = useRepositoryEditor() const { strings } = useContext(ContextLanguage) diff --git a/nest_frontend/components/providers/RepositoryViewer.js b/nest_frontend/components/providers/RepositoryViewer.js index f2dff8d..b8ad41f 100644 --- a/nest_frontend/components/providers/RepositoryViewer.js +++ b/nest_frontend/components/providers/RepositoryViewer.js @@ -24,7 +24,7 @@ import BoxFilterContains from "../interactive/BoxFilterContains" import BoxFilterUser from "../interactive/BoxFilterUser" import BoxFilterHashtag from "../interactive/BoxFilterHashtag" import BoxFilterLocation from "../interactive/BoxFilterLocation" -import useMapView from "../../hooks/useMapView" +import useMapAreaState from "../../hooks/useMapAreaState" import BoxFilterDatetime from "../interactive/BoxFilterDatetime" import BoxFilterHasPlace from "../interactive/BoxFilterHasPlace" @@ -44,7 +44,7 @@ export default function RepositoryViewer({ id, className, ...props }) { } = useArrayState([]) // FIXME: this has a severe performance impact, investigate - const mapViewHook = useMapView() + const mapViewHook = useMapAreaState() // Repository const repositoryBr = useBackendResource( diff --git a/nest_frontend/contexts/ContextLanguage.js b/nest_frontend/contexts/ContextLanguage.js index a48fb29..0b55bb4 100644 --- a/nest_frontend/contexts/ContextLanguage.js +++ b/nest_frontend/contexts/ContextLanguage.js @@ -8,7 +8,7 @@ import LocalizationStrings from "../LocalizationStrings" * - `setLang`: a function to change the current language * - `strings`: an object containing all strings of the current language * - * Defaults to Italian. + * Defaults to Italian `it`. */ export default createContext({ lang: "it", diff --git a/nest_frontend/contexts/ContextRepositoryEditor.js b/nest_frontend/contexts/ContextRepositoryEditor.js index c8db99b..3364c6b 100644 --- a/nest_frontend/contexts/ContextRepositoryEditor.js +++ b/nest_frontend/contexts/ContextRepositoryEditor.js @@ -2,6 +2,8 @@ import { createContext } from "react" /** - * Context to quickly pass props to the children of {@link RepositoryEditor}. + * React Context representing containing all variables of a {@link RepositoryEditor}. + * + * It is `null` outside a RepositoryEditor. */ export default createContext(null) diff --git a/nest_frontend/contexts/ContextRepositoryViewer.js b/nest_frontend/contexts/ContextRepositoryViewer.js index a425822..17e387b 100644 --- a/nest_frontend/contexts/ContextRepositoryViewer.js +++ b/nest_frontend/contexts/ContextRepositoryViewer.js @@ -2,6 +2,8 @@ import { createContext } from "react" /** - * Context to quickly pass props to the children of {@link RepositoryViewer}. + * React Context representing containing all variables of a {@link RepositoryViewer}. + * + * It is `null` outside a RepositoryViewer. */ export default createContext(null) diff --git a/nest_frontend/contexts/ContextServer.js b/nest_frontend/contexts/ContextServer.js index c9a8402..7623b76 100644 --- a/nest_frontend/contexts/ContextServer.js +++ b/nest_frontend/contexts/ContextServer.js @@ -2,7 +2,7 @@ import { createContext } from "react" /** - * A context containing an object with the following values: + * A React Context containing an object with the following values: * - `server`: the base URL of the currently active backend server * - `setServer`: a function to change `server` * - `fetchData`: a function to fetch JSON data from the backend server diff --git a/nest_frontend/contexts/ContextTheme.js b/nest_frontend/contexts/ContextTheme.js index 85f9a6b..bd5d07c 100644 --- a/nest_frontend/contexts/ContextTheme.js +++ b/nest_frontend/contexts/ContextTheme.js @@ -2,7 +2,7 @@ import { createContext } from "react" /** - * A context containing an object with the following elements: + * A React Context containing an object with the following elements: * - `theme` - A string containing the name of the current theme. * - `setTheme` - A function that allows changing the `theme`. * diff --git a/nest_frontend/contexts/ContextUser.js b/nest_frontend/contexts/ContextUser.js index 9a883c5..5174353 100644 --- a/nest_frontend/contexts/ContextUser.js +++ b/nest_frontend/contexts/ContextUser.js @@ -2,7 +2,7 @@ import { createContext } from "react" /** - * A context containing an object with the following values: + * A React Context containing an object with the following values: * - `user`: an object containing data about the currently logged in user * - `login`: a function accepting `email, password` as parameters which tries to login the user * - `logout`: a function accepting no parameters which logs the user out diff --git a/nest_frontend/contexts/README.md b/nest_frontend/contexts/README.md deleted file mode 100644 index 85f071e..0000000 --- a/nest_frontend/contexts/README.md +++ /dev/null @@ -1,3 +0,0 @@ -# Contexts - -In questa cartella sono contenuti i `Context` globali di React. diff --git a/nest_frontend/hooks/useBackendRequest.js b/nest_frontend/hooks/useBackendRequest.js index 9c85044..1ee6489 100644 --- a/nest_frontend/hooks/useBackendRequest.js +++ b/nest_frontend/hooks/useBackendRequest.js @@ -1,7 +1,6 @@ import { useCallback, useContext, useState } from "react" import ContextServer from "../contexts/ContextServer" import ContextUser from "../contexts/ContextUser" -import makeURLSearchParams from "../utils/makeURLSearchParams" /** @@ -45,7 +44,7 @@ export default function useBackendRequest() { // Use the body param as either search parameter or request body if(body) { if(["GET", "HEAD"].includes(method.toUpperCase())) { - path += makeURLSearchParams(body).toString() + path += URLSearchParams.fromSerializableObject(body).toString() } else { init["body"] = JSON.stringify(body) diff --git a/nest_frontend/hooks/useLocalStorageState.js b/nest_frontend/hooks/useLocalStorageState.js index 66f5be0..4c30613 100644 --- a/nest_frontend/hooks/useLocalStorageState.js +++ b/nest_frontend/hooks/useLocalStorageState.js @@ -2,7 +2,8 @@ import { useCallback, useState } from "react" /** - * Hook with the same API as {@link React.useState} which stores its value in the browser's {@link localStorage}. + * Hook with the same API as {@link React.useState} which additionally stores its value in the browser's + * {@link localStorage}. */ export default function useLocalStorageState(key, def) { /** diff --git a/nest_frontend/hooks/useMapAreaState.js b/nest_frontend/hooks/useMapAreaState.js new file mode 100644 index 0000000..f1b8354 --- /dev/null +++ b/nest_frontend/hooks/useMapAreaState.js @@ -0,0 +1,21 @@ +import { useState } from "react" +import Coordinates from "../objects/Coordinates" +import MapArea from "../objects/MapArea" + + +/** + * Hook which holds values required to create a {@link MapArea}. + */ +export default function useMapAreaState() { + const [zoom, setZoom] = useState(3) + const [center, setCenter] = useState(new Coordinates(0, 0)) + const mapArea = MapArea.fromZoomLevel(zoom, center) + + return { + zoom, + setZoom, + center, + setCenter, + mapArea, + } +} \ No newline at end of file diff --git a/nest_frontend/hooks/useMapView.js b/nest_frontend/hooks/useMapView.js deleted file mode 100644 index 990a931..0000000 --- a/nest_frontend/hooks/useMapView.js +++ /dev/null @@ -1,18 +0,0 @@ -import { useState } from "react" -import { DEFAULT_MAP_CENTER, DEFAULT_MAP_ZOOM } from "../utils/defaultMapLocation" -import osmZoomLevels from "../utils/osmZoomLevels" - - -export default function useMapView() { - const [center, setCenter] = useState(DEFAULT_MAP_CENTER) - const [zoom, setZoom] = useState(DEFAULT_MAP_ZOOM) - const radius = osmZoomLevels[zoom] - - return { - center, - setCenter, - zoom, - setZoom, - radius, - } -} \ No newline at end of file diff --git a/nest_frontend/hooks/useRepositoryViewer.js b/nest_frontend/hooks/useRepositoryViewer.js index 20e84f5..f4ae358 100644 --- a/nest_frontend/hooks/useRepositoryViewer.js +++ b/nest_frontend/hooks/useRepositoryViewer.js @@ -1,10 +1,9 @@ import { useContext } from "react" -import ContextRepositoryEditor from "../contexts/ContextRepositoryEditor" import ContextRepositoryViewer from "../contexts/ContextRepositoryViewer" /** - * Hook to quickly use {@link ContextRepositoryEditor}. + * Hook to quickly use {@link ContextRepositoryViewer}. */ export default function useRepositoryViewer() { const context = useContext(ContextRepositoryViewer) @@ -12,4 +11,4 @@ export default function useRepositoryViewer() { throw new Error("This component must be placed inside a RepositoryViewer.") } return context -} \ No newline at end of file +} diff --git a/nest_frontend/hooks/useStrings.js b/nest_frontend/hooks/useStrings.js index 4a02c4a..ce3618d 100644 --- a/nest_frontend/hooks/useStrings.js +++ b/nest_frontend/hooks/useStrings.js @@ -3,7 +3,7 @@ import ContextLanguage from "../contexts/ContextLanguage" /** - * Hook to quickly use the strings of {@link ContextLanguage}. + * Hook to quickly use the `strings` attribute of {@link ContextLanguage}. */ export default function useStrings() { return useContext(ContextLanguage).strings diff --git a/nest_frontend/media/README.md b/nest_frontend/media/README.md deleted file mode 100644 index 7a5a05a..0000000 --- a/nest_frontend/media/README.md +++ /dev/null @@ -1,3 +0,0 @@ -# Media - -In questa cartella sono contenute le immagini statiche del sito web. \ No newline at end of file diff --git a/nest_frontend/routes/README.md b/nest_frontend/routes/README.md deleted file mode 100644 index 3ae1b2c..0000000 --- a/nest_frontend/routes/README.md +++ /dev/null @@ -1,3 +0,0 @@ -# Routes - -In questa cartella sono contenuti i `Component` che vengono renderati come pagine intere. diff --git a/nest_frontend/utils/README.md b/nest_frontend/utils/README.md deleted file mode 100644 index a34cb5a..0000000 --- a/nest_frontend/utils/README.md +++ /dev/null @@ -1,3 +0,0 @@ -# Utils - -In questa cartella sono contenute alcune funzioni di utility per il sito.