1
Fork 0
mirror of https://github.com/pds-nest/nest.git synced 2024-11-24 14:04:19 +00:00

🧹 Reformat code

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

View file

@ -22,7 +22,7 @@ export default function ButtonSidebar({ icon, children, to, className, ...props
path: to,
strict: true,
exact: true,
});
})
if(match) {
className = classNames(Style.Active, className)

View file

@ -17,7 +17,7 @@ import make_icon from "../../utils/make_icon"
* @constructor
*/
export default function InputWithIcon({ icon, className, ...props }) {
const [isFocused, setFocused] = useState(false);
const [isFocused, setFocused] = useState(false)
return (
<div className={classNames(Style.InputWithIcon, isFocused ? Style.Focused : null, className)}>

View file

@ -2,6 +2,7 @@ import React from "react"
import Style from "./Radio.module.css"
import classNames from "classnames"
/**
* A radio button.
*

View file

@ -15,7 +15,10 @@ import classNames from "classnames"
*/
export default function TextArea({ resize, children, className, ...props }) {
return (
<textarea className={classNames(Style.TextArea, resize ? Style.TextAreaResizable : Style.TextAreaNoResize, className)} {...props}>
<textarea
className={classNames(Style.TextArea, resize
? Style.TextAreaResizable
: Style.TextAreaNoResize, className)} {...props}>
{children}
</textarea>
)

View file

@ -1,7 +1,7 @@
import React, { useState } from "react"
import BoxFull from "../base/BoxFull"
import { FontAwesomeIcon } from "@fortawesome/react-fontawesome"
import { faAt, faClock, faPlus } from "@fortawesome/free-solid-svg-icons"
import { faClock, faPlus } from "@fortawesome/free-solid-svg-icons"
import InputWithIcon from "../base/InputWithIcon"
import FormInline from "../base/FormInline"
import Style from "./BoxConditionDatetime.module.css"

View file

@ -1,11 +1,10 @@
import React, { useCallback, useState, useRef, useMemo, useEffect } from "react"
import React, { useCallback, useEffect, useState } from "react"
import BoxFull from "../base/BoxFull"
import { FontAwesomeIcon } from "@fortawesome/react-fontawesome"
import { faMapPin, faPlus } from "@fortawesome/free-solid-svg-icons"
import FormInline from "../base/FormInline"
import Style from "./BoxConditionMap.module.css"
import ButtonIconOnly from "../base/ButtonIconOnly"
import { MapContainer, Marker, TileLayer } from "react-leaflet"
import { MapContainer, TileLayer } from "react-leaflet"
import useRepositoryEditor from "../../hooks/useRepositoryEditor"
import Condition from "../../utils/Condition"
@ -59,19 +58,21 @@ export default function BoxConditionMap({ ...props }) {
() => {
setPosition(map.getCenter())
},
[map]
[map],
)
const onZoom = useCallback(
() => {
setZoom(map.getZoom())
},
[map]
[map],
)
useEffect(
() => {
if(map === null) return
if(map === null) {
return
}
map.on("move", onMove)
map.on("zoom", onZoom)
@ -80,7 +81,7 @@ export default function BoxConditionMap({ ...props }) {
map.off("zoom", onZoom)
}
},
[map]
[map],
)
const onButtonClick = () => {
@ -90,7 +91,7 @@ export default function BoxConditionMap({ ...props }) {
addCondition(new Condition(
"COORDINATES",
`< ${radius} ${position.lat} ${position.lng}`
`< ${radius} ${position.lat} ${position.lng}`,
))
setPosition(STARTING_POSITION)
}

View file

@ -27,10 +27,12 @@ export default function BoxLoggedIn({ ...props }) {
You are currently logged in at <CurrentServer/> as <LoggedInUser/>.
</div>
<div>
<Button color={"Red"} onClick={() => {
<Button
color={"Red"} onClick={() => {
logout()
history.push("/login")
}} icon={faSignOutAlt}>Logout</Button>
}} icon={faSignOutAlt}
>Logout</Button>
</div>
</div>
</BoxFull>

View file

@ -27,7 +27,7 @@ export default function BoxLogin({ ...props }) {
const doLogin = async () => {
if(working) {
return;
return
}
setWorking(true)

View file

@ -17,7 +17,7 @@ import ContextUser from "../../contexts/ContextUser"
export default function BoxRepositoriesActive({ repositories, refresh, ...props }) {
const { user } = useContext(ContextUser)
let contents;
let contents
if(repositories.length > 0) {
contents = repositories.map(repo => (
<RepositorySummaryBase

View file

@ -17,7 +17,7 @@ import { faSearch } from "@fortawesome/free-solid-svg-icons"
export default function BoxRepositoriesArchived({ repositories, refresh, ...props }) {
const { user } = useContext(ContextUser)
let contents;
let contents
if(repositories.length > 0) {
contents = repositories.map(repo => (
<RepositorySummaryBase

View file

@ -34,7 +34,12 @@ export default function BoxRepositoryCreate({ ...props }) {
return (
<BoxFull header={"Create repository"} {...props}>
<FormLabelled onSubmit={e => {e.preventDefault(); save()}}>
<FormLabelled
onSubmit={e => {
e.preventDefault()
save()
}}
>
<FormLabel htmlFor={"repo-name"} text={"Repository name"}>
<InputWithIcon
id={"repo-name"}

View file

@ -15,7 +15,7 @@ import ContextServer from "../../contexts/ContextServer"
* @constructor
*/
export default function BoxSetServer({ ...props }) {
const {server, setServer} = useContext(ContextServer);
const { server, setServer } = useContext(ContextServer)
return (
<BoxFull header={"Choose server"} {...props}>

View file

@ -65,10 +65,12 @@ export default function ConditionBadge({ ...condition }) {
{displayedContent}
</div>
<div>
<ButtonSmallX onClick={() => {
<ButtonSmallX
onClick={() => {
console.debug(`Removing Condition: `, condition)
removeRawCondition(condition)
}}/>
}}
/>
</div>
</div>
)

View file

@ -12,7 +12,7 @@ import ContextServer from "../../contexts/ContextServer"
* @constructor
*/
export default function CurrentServer({ ...props }) {
const {server} = useContext(ContextServer);
const { server } = useContext(ContextServer)
return (
<b {...props}>

View file

@ -8,8 +8,7 @@
display: grid;
grid-template-areas:
"a b"
;
"a b";
grid-template-columns: 250px 1fr;
grid-gap: 10px;

View file

@ -12,7 +12,7 @@ import ContextUser from "../../contexts/ContextUser"
* @constructor
*/
export default function LoggedInUser({ ...props }) {
const {user} = useContext(ContextUser);
const { user } = useContext(ContextUser)
if(!user) {
return (

View file

@ -21,7 +21,7 @@ export default function Logo({ className, ...props }) {
// It's perfectly fine!
const { theme } = useContext(ContextTheme)
let logo;
let logo
if(theme === "ThemeDark") {
logo = LogoDark
}

View file

@ -29,7 +29,7 @@ import ContextUser from "../../contexts/ContextUser"
* @constructor
*/
export default function RepositorySummaryBase(
{ id, refresh, owner, icon, name, start, end, is_active, canDelete, canEdit, canArchive, className, ...props }
{ id, refresh, owner, icon, name, start, end, is_active, canDelete, canEdit, canArchive, className, ...props },
) {
const { fetchDataAuth } = useContext(ContextUser)
const history = useHistory()

View file

@ -17,8 +17,7 @@
"a b"
"a c"
"a d"
"a e"
;
"a e";
grid-template-columns: auto 1fr;
grid-template-rows: 5px 1fr 1fr 5px;

View file

@ -12,7 +12,7 @@ import ContextTheme from "../../contexts/ContextTheme"
* @constructor
*/
export default function SelectTheme({ ...props }) {
const {theme, setTheme} = useContext(ContextTheme);
const { theme, setTheme } = useContext(ContextTheme)
return (
<Select value={theme} onChange={e => setTheme(e.target.value)} {...props}>

View file

@ -73,7 +73,7 @@ export default function RepositoryEditor({
}
fetchNow()
},
[id, body, fetchNow]
[id, body, fetchNow],
)
@ -89,7 +89,7 @@ export default function RepositoryEditor({
setRawConditions(conditions)
setEvaluationMode(evaluationMode)
},
[name, isActive, start, end, conditions, evaluationMode]
[name, isActive, start, end, conditions, evaluationMode],
)
/**
@ -104,7 +104,7 @@ export default function RepositoryEditor({
}
// Check for duplicates
let duplicate = null;
let duplicate = null
for(const oldCond of _conditions) {
if(newCond.type === oldCond.type && newCond.content === oldCond.content) {
duplicate = oldCond
@ -119,11 +119,12 @@ export default function RepositoryEditor({
console.debug("Adding ", newCond, " to the Repository Conditions")
appendRawCondition(newCond)
},
[_conditions]
[_conditions],
)
return (
<ContextRepositoryEditor.Provider value={{
<ContextRepositoryEditor.Provider
value={{
id,
name: _name, setName,
isActive: _isActive, setActive,
@ -133,7 +134,8 @@ export default function RepositoryEditor({
evaluationMode: _evaluationMode, setEvaluationMode,
error, loading,
revert, save,
}}>
}}
>
<div className={classNames(Style.RepositoryEditor, className)}>
<BoxConditionMap className={Style.SearchByZone}/>
<BoxConditionHashtag className={Style.SearchByHashtags}/>

View file

@ -6,8 +6,7 @@
"b d"
"b e"
"b f"
"b g"
;
"b g";
grid-template-columns: 400px 1fr;
grid-template-rows: auto auto auto 1fr auto;

View file

@ -1,4 +1,4 @@
import {createContext} from "react";
import { createContext } from "react"
/**

View file

@ -1,4 +1,4 @@
import {createContext} from "react";
import { createContext } from "react"
/**

View file

@ -1,4 +1,4 @@
import {createContext} from "react";
import { createContext } from "react"
/**
@ -14,6 +14,6 @@ import {createContext} from "react";
const ContextTheme = createContext({
isSet: false,
theme: "ThemeDark",
setTheme: () => console.error("Trying to setTheme while outside a ContextTheme.Provider!")
setTheme: () => console.error("Trying to setTheme while outside a ContextTheme.Provider!"),
})
export default ContextTheme

View file

@ -1,4 +1,4 @@
import {createContext} from "react";
import { createContext } from "react"
/**

View file

@ -14,10 +14,10 @@ export default function useArrayState(def) {
newSingle => {
console.debug("Appending ", newSingle, " to ArrayState")
setValue(
oldArray => [...oldArray, newSingle]
oldArray => [...oldArray, newSingle],
)
},
[]
[],
)
const spliceValue = useCallback(
@ -28,20 +28,20 @@ export default function useArrayState(def) {
// TODO: Hope this doesn't break anything...
oldArray.splice(position, 1)
return oldArray
}
},
)
},
[]
[],
)
const removeValue = useCallback(
remValue => {
console.debug("Removing ", remValue, " from ArrayState")
setValue(
oldArray => oldArray.filter(item => JSON.stringify(item) !== JSON.stringify(remValue))
oldArray => oldArray.filter(item => JSON.stringify(item) !== JSON.stringify(remValue)),
)
},
[]
[],
)
return { value, setValue, appendValue, spliceValue, removeValue }

View file

@ -1,4 +1,4 @@
import { useCallback, useEffect, useState } from "react"
import { useCallback, useState } from "react"
/**
@ -28,15 +28,17 @@ export default function useData(fetchData, method, path, body, init) {
const _data = await fetchData(method, path, body, init)
console.debug(`Displaying data of ${method} ${path}: `, _data)
setData(_data)
} catch(e) {
}
catch(e) {
console.debug(`Displaying error of ${method} ${path}: `, e)
setError(e)
} finally {
}
finally {
console.debug(`Stopping loading of ${method} ${path}...`)
setLoading(false)
}
},
[fetchData, method, path, body, init]
[fetchData, method, path, body, init],
)
/**
@ -52,7 +54,7 @@ export default function useData(fetchData, method, path, body, init) {
await load()
},
[load]
[load],
)
return { data, error, loading, fetchNow }

View file

@ -16,11 +16,13 @@ export default function useDataImmediately(fetchData, method, path, body, init)
useEffect(
() => {
if(!(loading || data || error)) {
if(!(
loading || data || error
)) {
fetchNow()
}
},
[data, error, loading, fetchNow]
[data, error, loading, fetchNow],
)
return { data, error, loading, fetchNow }

View file

@ -28,7 +28,7 @@ export default function useLocalStorageState(key, def) {
}
}
const [value, setValue] = useState(load());
const [value, setValue] = useState(load())
/**
* Save a value to the {@link localStorage}.
@ -43,7 +43,7 @@ export default function useLocalStorageState(key, def) {
console.warn(`Can't save ${key}; localStorage doesn't seem to be available...`)
}
},
[key]
[key],
)
/**
@ -54,7 +54,7 @@ export default function useLocalStorageState(key, def) {
setValue(value)
save(value)
},
[save]
[save],
)
return [value, setAndSave]

View file

@ -3,8 +3,7 @@
grid-template-areas:
"a"
"b"
;
"b";
grid-gap: 10px;

View file

@ -3,8 +3,7 @@
grid-template-areas:
"a"
"b"
;
"b";
grid-template-rows: auto 1fr;
grid-gap: 10px;

View file

@ -6,17 +6,14 @@ import RepositoryEditor from "../components/providers/RepositoryEditor"
import useDataImmediately from "../hooks/useDataImmediately"
import ContextUser from "../contexts/ContextUser"
import BoxAlert from "../components/base/BoxAlert"
import RepositorySummaryBase from "../components/interactive/RepositorySummaryBase"
import { faSearch } from "@fortawesome/free-solid-svg-icons"
import Loading from "../components/base/Loading"
import BoxFull from "../components/base/BoxFull"
export default function PageEdit({ id, className, ...props }) {
const { fetchDataAuth } = useContext(ContextUser)
const { data, error } = useDataImmediately(fetchDataAuth, "GET", `/api/v1/repositories/${id}`)
let contents;
let contents
if(error) {
contents = <BoxAlert color={"Red"}>{error.toString()}</BoxAlert>
}

View file

@ -13,7 +13,7 @@ export default function PageRepositories({ children, className, ...props }) {
const { fetchDataAuth } = useContext(ContextUser)
const { data, error, fetchNow: refresh } = useDataImmediately(fetchDataAuth, "GET", "/api/v1/repositories/")
let contents;
let contents
if(error) {
contents = <BoxAlert color={"Red"}>{error}</BoxAlert>
}

View file

@ -3,8 +3,7 @@
grid-template-areas:
"a"
"b"
;
"b";
grid-gap: 10px;

View file

@ -23,7 +23,9 @@ export default function convertToLocalISODate(date) {
const tzHours = Math.abs(Math.floor(tz / 60)).toString().padStart(2, "0")
// Find the minutes
const tzMinutes = (tz % 60).toString().padStart(2, "0")
const tzMinutes = (
tz % 60
).toString().padStart(2, "0")
// Replace the naive part with the aware part
return naive.replace("Z", `${tz < 0 ? "-" : "+"}${tzHours}${tzMinutes}`)

View file

@ -4,7 +4,7 @@ import { FontAwesomeIcon } from "@fortawesome/react-fontawesome"
export default function make_icon(icon, className) {
if(isValidElement(icon)) {
return <span className={className}>icon</span>;
return <span className={className}>icon</span>
}
else if(icon) {
return (
@ -12,6 +12,6 @@ export default function make_icon(icon, className) {
)
}
else {
return null;
return null
}
}