mirror of
https://github.com/pds-nest/nest.git
synced 2024-11-22 13:04:19 +00:00
💥 Refactor more more more things
This commit is contained in:
parent
f27304e34c
commit
2bcfb3bdf7
18 changed files with 41 additions and 47 deletions
|
@ -6,7 +6,7 @@ import useRepositoryEditor from "../../hooks/useRepositoryEditor"
|
||||||
import Condition from "../../utils/Condition"
|
import Condition from "../../utils/Condition"
|
||||||
import ContextLanguage from "../../contexts/ContextLanguage"
|
import ContextLanguage from "../../contexts/ContextLanguage"
|
||||||
import BoxMap from "../base/BoxMap"
|
import BoxMap from "../base/BoxMap"
|
||||||
import useMapView from "../../hooks/useMapView"
|
import useMapAreaState from "../../hooks/useMapAreaState"
|
||||||
import osmZoomLevels from "../../utils/osmZoomLevels"
|
import osmZoomLevels from "../../utils/osmZoomLevels"
|
||||||
|
|
||||||
|
|
||||||
|
@ -18,7 +18,7 @@ import osmZoomLevels from "../../utils/osmZoomLevels"
|
||||||
* @constructor
|
* @constructor
|
||||||
*/
|
*/
|
||||||
export default function BoxConditionMap({ ...props }) {
|
export default function BoxConditionMap({ ...props }) {
|
||||||
const mapViewHook = useMapView()
|
const mapViewHook = useMapAreaState()
|
||||||
const { addCondition } = useRepositoryEditor()
|
const { addCondition } = useRepositoryEditor()
|
||||||
const { strings } = useContext(ContextLanguage)
|
const { strings } = useContext(ContextLanguage)
|
||||||
|
|
||||||
|
|
|
@ -24,7 +24,7 @@ import BoxFilterContains from "../interactive/BoxFilterContains"
|
||||||
import BoxFilterUser from "../interactive/BoxFilterUser"
|
import BoxFilterUser from "../interactive/BoxFilterUser"
|
||||||
import BoxFilterHashtag from "../interactive/BoxFilterHashtag"
|
import BoxFilterHashtag from "../interactive/BoxFilterHashtag"
|
||||||
import BoxFilterLocation from "../interactive/BoxFilterLocation"
|
import BoxFilterLocation from "../interactive/BoxFilterLocation"
|
||||||
import useMapView from "../../hooks/useMapView"
|
import useMapAreaState from "../../hooks/useMapAreaState"
|
||||||
import BoxFilterDatetime from "../interactive/BoxFilterDatetime"
|
import BoxFilterDatetime from "../interactive/BoxFilterDatetime"
|
||||||
import BoxFilterHasPlace from "../interactive/BoxFilterHasPlace"
|
import BoxFilterHasPlace from "../interactive/BoxFilterHasPlace"
|
||||||
|
|
||||||
|
@ -44,7 +44,7 @@ export default function RepositoryViewer({ id, className, ...props }) {
|
||||||
} = useArrayState([])
|
} = useArrayState([])
|
||||||
|
|
||||||
// FIXME: this has a severe performance impact, investigate
|
// FIXME: this has a severe performance impact, investigate
|
||||||
const mapViewHook = useMapView()
|
const mapViewHook = useMapAreaState()
|
||||||
|
|
||||||
// Repository
|
// Repository
|
||||||
const repositoryBr = useBackendResource(
|
const repositoryBr = useBackendResource(
|
||||||
|
|
|
@ -8,7 +8,7 @@ import LocalizationStrings from "../LocalizationStrings"
|
||||||
* - `setLang`: a function to change the current language
|
* - `setLang`: a function to change the current language
|
||||||
* - `strings`: an object containing all strings of the current language
|
* - `strings`: an object containing all strings of the current language
|
||||||
*
|
*
|
||||||
* Defaults to Italian.
|
* Defaults to Italian `it`.
|
||||||
*/
|
*/
|
||||||
export default createContext({
|
export default createContext({
|
||||||
lang: "it",
|
lang: "it",
|
||||||
|
|
|
@ -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)
|
export default createContext(null)
|
||||||
|
|
|
@ -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)
|
export default createContext(null)
|
||||||
|
|
|
@ -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
|
* - `server`: the base URL of the currently active backend server
|
||||||
* - `setServer`: a function to change `server`
|
* - `setServer`: a function to change `server`
|
||||||
* - `fetchData`: a function to fetch JSON data from the backend server
|
* - `fetchData`: a function to fetch JSON data from the backend server
|
||||||
|
|
|
@ -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.
|
* - `theme` - A string containing the name of the current theme.
|
||||||
* - `setTheme` - A function that allows changing the `theme`.
|
* - `setTheme` - A function that allows changing the `theme`.
|
||||||
*
|
*
|
||||||
|
|
|
@ -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
|
* - `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
|
* - `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
|
* - `logout`: a function accepting no parameters which logs the user out
|
||||||
|
|
|
@ -1,3 +0,0 @@
|
||||||
# Contexts
|
|
||||||
|
|
||||||
In questa cartella sono contenuti i `Context` globali di React.
|
|
|
@ -1,7 +1,6 @@
|
||||||
import { useCallback, useContext, useState } from "react"
|
import { useCallback, useContext, useState } from "react"
|
||||||
import ContextServer from "../contexts/ContextServer"
|
import ContextServer from "../contexts/ContextServer"
|
||||||
import ContextUser from "../contexts/ContextUser"
|
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
|
// Use the body param as either search parameter or request body
|
||||||
if(body) {
|
if(body) {
|
||||||
if(["GET", "HEAD"].includes(method.toUpperCase())) {
|
if(["GET", "HEAD"].includes(method.toUpperCase())) {
|
||||||
path += makeURLSearchParams(body).toString()
|
path += URLSearchParams.fromSerializableObject(body).toString()
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
init["body"] = JSON.stringify(body)
|
init["body"] = JSON.stringify(body)
|
||||||
|
|
|
@ -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) {
|
export default function useLocalStorageState(key, def) {
|
||||||
/**
|
/**
|
||||||
|
|
21
nest_frontend/hooks/useMapAreaState.js
Normal file
21
nest_frontend/hooks/useMapAreaState.js
Normal 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,
|
||||||
|
}
|
||||||
|
}
|
|
@ -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,
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,10 +1,9 @@
|
||||||
import { useContext } from "react"
|
import { useContext } from "react"
|
||||||
import ContextRepositoryEditor from "../contexts/ContextRepositoryEditor"
|
|
||||||
import ContextRepositoryViewer from "../contexts/ContextRepositoryViewer"
|
import ContextRepositoryViewer from "../contexts/ContextRepositoryViewer"
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Hook to quickly use {@link ContextRepositoryEditor}.
|
* Hook to quickly use {@link ContextRepositoryViewer}.
|
||||||
*/
|
*/
|
||||||
export default function useRepositoryViewer() {
|
export default function useRepositoryViewer() {
|
||||||
const context = useContext(ContextRepositoryViewer)
|
const context = useContext(ContextRepositoryViewer)
|
||||||
|
|
|
@ -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() {
|
export default function useStrings() {
|
||||||
return useContext(ContextLanguage).strings
|
return useContext(ContextLanguage).strings
|
||||||
|
|
|
@ -1,3 +0,0 @@
|
||||||
# Media
|
|
||||||
|
|
||||||
In questa cartella sono contenute le immagini statiche del sito web.
|
|
|
@ -1,3 +0,0 @@
|
||||||
# Routes
|
|
||||||
|
|
||||||
In questa cartella sono contenuti i `Component` che vengono renderati come pagine intere.
|
|
|
@ -1,3 +0,0 @@
|
||||||
# Utils
|
|
||||||
|
|
||||||
In questa cartella sono contenute alcune funzioni di utility per il sito.
|
|
Loading…
Reference in a new issue