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

💥 Refactor more more more things

This commit is contained in:
Steffo 2021-05-22 04:44:08 +02:00
parent f27304e34c
commit 2bcfb3bdf7
Signed by: steffo
GPG key ID: 6965406171929D01
18 changed files with 41 additions and 47 deletions

View file

@ -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)

View file

@ -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(

View file

@ -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",

View file

@ -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)

View file

@ -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)

View file

@ -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

View file

@ -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`.
*

View file

@ -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

View file

@ -1,3 +0,0 @@
# Contexts
In questa cartella sono contenuti i `Context` globali di React.

View file

@ -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)

View file

@ -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) {
/**

View file

@ -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,
}
}

View file

@ -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,
}
}

View file

@ -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
}
}

View file

@ -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

View file

@ -1,3 +0,0 @@
# Media
In questa cartella sono contenute le immagini statiche del sito web.

View file

@ -1,3 +0,0 @@
# Routes
In questa cartella sono contenuti i `Component` che vengono renderati come pagine intere.

View file

@ -1,3 +0,0 @@
# Utils
In questa cartella sono contenute alcune funzioni di utility per il sito.