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

🧹 Reformat code

This commit is contained in:
Steffo 2021-05-20 12:16:01 +02:00
parent df4b9bb368
commit 6a99effc8b
Signed by: steffo
GPG key ID: 6965406171929D01
22 changed files with 225 additions and 159 deletions

View file

@ -4,7 +4,15 @@ import BoxFull from "./BoxFull"
import { MapContainer, TileLayer } from "react-leaflet"
export default function BoxMap({ header, setMap, startingPosition = { lat: 41.89309, lng: 12.48289 }, startingZoom = 3, button, children, ...props }) {
export default function BoxMap({
header,
setMap,
startingPosition = { lat: 41.89309, lng: 12.48289 },
startingZoom = 3,
button,
children,
...props
}) {
return (
<BoxFull
header={header}

View file

@ -3,7 +3,15 @@ import Style from "./SummaryLabels.module.css"
import classNames from "classnames"
export default function SummaryLabels({ children, upperLabel, upperValue, lowerLabel, lowerValue, className, ...props }) {
export default function SummaryLabels({
children,
upperLabel,
upperValue,
lowerLabel,
lowerValue,
className,
...props
}) {
return (
<div className={classNames(Style.SummaryLabels, className)} {...props}>
<div className={classNames(Style.Label, Style.Upper)}>

View file

@ -1,7 +1,6 @@
import React, { useContext } from "react"
import React from "react"
import BoxFullScrollable from "../base/BoxFullScrollable"
import Loading from "../base/Loading"
import ContextLanguage from "../../contexts/ContextLanguage"
import SummaryRepository from "./SummaryRepository"
import Empty from "./Empty"
@ -21,7 +20,17 @@ import Empty from "./Empty"
* @returns {JSX.Element}
* @constructor
*/
export default function BoxRepositories({ repositories, view, archive, edit, destroy, loading, running, className, ...props }) {
export default function BoxRepositories({
repositories,
view,
archive,
edit,
destroy,
loading,
running,
className,
...props
}) {
let contents
if(loading) {
contents = <Loading/>

View file

@ -2,34 +2,33 @@ import React, { useMemo } from "react"
import FormLabelled from "../base/FormLabelled"
import FormLabel from "../base/formparts/FormLabel"
import BoxFullScrollable from "../base/BoxFullScrollable"
import tokenizeTweetWords from "../../utils/countTweetWords"
export default function BoxVisualizationStats({ tweets, words, totalTweetCount, ...props }) {
const tweetCount = useMemo(
() => tweets.length,
[tweets]
[tweets],
)
const tweetPct = useMemo(
() => tweetCount / totalTweetCount * 100,
[tweetCount, totalTweetCount]
[tweetCount, totalTweetCount],
)
const tweetLocationCount = useMemo(
() => tweets.filter(tweet => tweet.location).length,
[tweets]
[tweets],
)
const tweetLocationPct = useMemo(
() => tweetLocationCount / tweetCount * 100,
[tweetLocationCount, tweetCount]
[tweetLocationCount, tweetCount],
)
const tweetContent = useMemo(
() => tweets.filter(tweet => tweet.content),
[tweets]
[tweets],
)
const tweetContentCount = useMemo(
@ -46,50 +45,60 @@ export default function BoxVisualizationStats({ tweets, words, totalTweetCount,
const wordCount = useMemo(
() => words.map(word => word.value).reduce((a, b) => a + b),
[words]
[words],
)
const mostPopularWord = useMemo(
() => {
return words.sort((wa, wb) => {
if(wa.value > wb.value) return -1
if(wa.value < wb.value) return 1
if(wa.value > wb.value) {
return -1
}
if(wa.value < wb.value) {
return 1
}
return 0
})[0].text
},
[words]
[words],
)
const users = useMemo(
() => tweets.map(tweet => tweet.poster),
[tweets]
[tweets],
)
const uniqueUsers = useMemo(
() => [...new Set(users)],
[users]
[users],
)
const uniqueUsersCount = useMemo(
() => uniqueUsers.length,
[uniqueUsers]
[uniqueUsers],
)
const mostActiveUser = useMemo(
() => {
if(uniqueUsers.length === 0) return null
if(uniqueUsers.length === 0) {
return null
}
return uniqueUsers.map(user => {
return {
user: user,
count: tweets.filter(tweet => tweet.poster === user).length
count: tweets.filter(tweet => tweet.poster === user).length,
}
}).sort((a, b) => {
if(a.count > b.count) return -1
if(a.count < b.count) return 1
if(a.count > b.count) {
return -1
}
if(a.count < b.count) {
return 1
}
return 0
})[0]
},
[uniqueUsers, tweets]
[uniqueUsers, tweets],
)
// TODO: tweets with picture count

View file

@ -1,15 +1,24 @@
import React from "react"
import ButtonIconOnly from "../base/ButtonIconOnly"
import { faAt, faChartBar, faClock, faCloud, faHashtag, faMap, faMapPin } from "@fortawesome/free-solid-svg-icons"
import { faAt, faClock, faHashtag, faMapPin } from "@fortawesome/free-solid-svg-icons"
export default function PickerFilter({ currentTab, setTab, ...props }) {
return (
<div {...props}>
<ButtonIconOnly onClick={() => setTab("hashtag")} disabled={currentTab === "hashtag"} color={"Grey"} icon={faHashtag}/>
<ButtonIconOnly
onClick={() => setTab("hashtag")} disabled={currentTab ===
"hashtag"} color={"Grey"} icon={faHashtag}
/>
<ButtonIconOnly onClick={() => setTab("user")} disabled={currentTab === "user"} color={"Grey"} icon={faAt}/>
<ButtonIconOnly onClick={() => setTab("location")} disabled={currentTab === "location"} color={"Grey"} icon={faMapPin}/>
<ButtonIconOnly onClick={() => setTab("time")} disabled={currentTab === "time"} color={"Grey"} icon={faClock}/>
<ButtonIconOnly
onClick={() => setTab("location")} disabled={currentTab ===
"location"} color={"Grey"} icon={faMapPin}
/>
<ButtonIconOnly
onClick={() => setTab("time")} disabled={currentTab ===
"time"} color={"Grey"} icon={faClock}
/>
</div>
)
}

View file

@ -1,24 +1,24 @@
import React from "react"
import ButtonIconOnly from "../base/ButtonIconOnly"
import {
faAt,
faChartBar,
faClock,
faCloud,
faHashtag,
faMap,
faMapPin,
faStar,
} from "@fortawesome/free-solid-svg-icons"
import { faChartBar, faCloud, faMap, faStar } from "@fortawesome/free-solid-svg-icons"
export default function PickerVisualization({ currentTab, setTab, ...props }) {
return (
<div {...props}>
<ButtonIconOnly onClick={() => setTab("wordcloud")} disabled={currentTab === "wordcloud"} color={"Grey"} icon={faCloud}/>
<ButtonIconOnly onClick={() => setTab("histogram")} disabled={currentTab === "histogram"} color={"Grey"} icon={faChartBar}/>
<ButtonIconOnly
onClick={() => setTab("wordcloud")} disabled={currentTab ===
"wordcloud"} color={"Grey"} icon={faCloud}
/>
<ButtonIconOnly
onClick={() => setTab("histogram")} disabled={currentTab ===
"histogram"} color={"Grey"} icon={faChartBar}
/>
<ButtonIconOnly onClick={() => setTab("map")} disabled={currentTab === "map"} color={"Grey"} icon={faMap}/>
<ButtonIconOnly onClick={() => setTab("stats")} disabled={currentTab === "stats"} color={"Grey"} icon={faStar}/>
<ButtonIconOnly
onClick={() => setTab("stats")} disabled={currentTab ===
"stats"} color={"Grey"} icon={faStar}
/>
</div>
)
}

View file

@ -1,6 +1,5 @@
import React, { useContext } from "react"
import { faArchive, faFolder, faFolderOpen, faPencilAlt, faTrash } from "@fortawesome/free-solid-svg-icons"
import { useHistory } from "react-router"
import ContextLanguage from "../../contexts/ContextLanguage"
import SummaryBase from "../base/summary/SummaryBase"
import SummaryLeft from "../base/summary/SummaryLeft"

View file

@ -1,7 +1,7 @@
import React from "react"
import SummaryBase from "../base/summary/SummaryBase"
import SummaryLeft from "../base/summary/SummaryLeft"
import { faComment, faLocationArrow, faMapMarker, faMapMarkerAlt, faMapPin } from "@fortawesome/free-solid-svg-icons"
import { faComment, faLocationArrow, faMapMarkerAlt } from "@fortawesome/free-solid-svg-icons"
import SummaryText from "../base/summary/SummaryText"
import SummaryRight from "../base/summary/SummaryRight"

View file

@ -1,7 +1,4 @@
import { useCallback, useContext, useEffect, useState } from "react"
import ContextServer from "../contexts/ContextServer"
import ContextUser from "../contexts/ContextUser"
import makeURLSearchParams from "../utils/makeURLSearchParams"
import { useCallback, useEffect, useState } from "react"
import useBackendRequest from "./useBackendRequest"
@ -11,13 +8,15 @@ import useBackendRequest from "./useBackendRequest"
* @param resourcePath - The path of the resource file.
* @param allowViews - An object with maps views to a boolean detailing if they're allowed in the viewset or not.
*/
export default function useBackendResource(resourcePath,
export default function useBackendResource(
resourcePath,
{
retrieve: allowRetrieve = true,
edit: allowEdit = true,
destroy: allowDestroy = true,
action: allowAction = false,
} = {}) {
} = {},
) {
const { abort, running, apiRequest } = useBackendRequest()
@ -27,7 +26,9 @@ export default function useBackendResource(resourcePath,
const apiRetrieve = useCallback(
async (init) => {
if(!allowRetrieve) throw new ViewNotAllowedError("retrieve")
if(!allowRetrieve) {
throw new ViewNotAllowedError("retrieve")
}
return await apiRequest("GET", `${resourcePath}`, undefined, init)
},
[apiRequest, allowRetrieve, resourcePath],
@ -35,7 +36,9 @@ export default function useBackendResource(resourcePath,
const apiEdit = useCallback(
async (data, init) => {
if(!allowEdit) throw new ViewNotAllowedError("edit")
if(!allowEdit) {
throw new ViewNotAllowedError("edit")
}
return await apiRequest("PUT", `${resourcePath}`, data, init)
},
[apiRequest, allowEdit, resourcePath],
@ -43,7 +46,9 @@ export default function useBackendResource(resourcePath,
const apiDestroy = useCallback(
async (init) => {
if(!allowDestroy) throw new ViewNotAllowedError("destroy")
if(!allowDestroy) {
throw new ViewNotAllowedError("destroy")
}
return await apiRequest("DELETE", `${resourcePath}`, undefined, init)
},
[apiRequest, allowDestroy, resourcePath],
@ -51,10 +56,12 @@ export default function useBackendResource(resourcePath,
const apiAction = useCallback(
async (method, command, data, init) => {
if(!allowAction) throw new ViewNotAllowedError("action")
if(!allowAction) {
throw new ViewNotAllowedError("action")
}
return await apiRequest(method, `${resourcePath}/${command}`, data, init)
},
[apiRequest, allowAction, resourcePath]
[apiRequest, allowAction, resourcePath],
)
const retrieveResource = useCallback(

View file

@ -18,7 +18,8 @@ export default function useBackendViewset(resourcesPath, pkName,
destroy: allowDestroy = true,
command: allowCommand = false,
action: allowAction = false,
} = {}) {
} = {},
) {
const { abort, running, apiRequest } = useBackendRequest()
const [firstLoad, setFirstLoad] = useState(false)
@ -27,7 +28,9 @@ export default function useBackendViewset(resourcesPath, pkName,
const apiList = useCallback(
async (init) => {
if(!allowList) throw new ViewNotAllowedError("list")
if(!allowList) {
throw new ViewNotAllowedError("list")
}
return await apiRequest("GET", `${resourcesPath}`, undefined, init)
},
[apiRequest, allowList, resourcesPath],
@ -35,7 +38,9 @@ export default function useBackendViewset(resourcesPath, pkName,
const apiRetrieve = useCallback(
async (id, init) => {
if(!allowRetrieve) throw new ViewNotAllowedError("retrieve")
if(!allowRetrieve) {
throw new ViewNotAllowedError("retrieve")
}
return await apiRequest("GET", `${resourcesPath}${id}`, undefined, init)
},
[apiRequest, allowRetrieve, resourcesPath],
@ -43,7 +48,9 @@ export default function useBackendViewset(resourcesPath, pkName,
const apiCreate = useCallback(
async (data, init) => {
if(!allowCreate) throw new ViewNotAllowedError("create")
if(!allowCreate) {
throw new ViewNotAllowedError("create")
}
return await apiRequest("POST", `${resourcesPath}`, data, init)
},
[apiRequest, allowCreate, resourcesPath],
@ -51,7 +58,9 @@ export default function useBackendViewset(resourcesPath, pkName,
const apiEdit = useCallback(
async (id, data, init) => {
if(!allowEdit) throw new ViewNotAllowedError("edit")
if(!allowEdit) {
throw new ViewNotAllowedError("edit")
}
return await apiRequest("PUT", `${resourcesPath}${id}`, data, init)
},
[apiRequest, allowEdit, resourcesPath],
@ -59,7 +68,9 @@ export default function useBackendViewset(resourcesPath, pkName,
const apiDestroy = useCallback(
async (id, init) => {
if(!allowDestroy) throw new ViewNotAllowedError("destroy")
if(!allowDestroy) {
throw new ViewNotAllowedError("destroy")
}
return await apiRequest("DELETE", `${resourcesPath}${id}`, undefined, init)
},
[apiRequest, allowDestroy, resourcesPath],
@ -67,18 +78,22 @@ export default function useBackendViewset(resourcesPath, pkName,
const apiCommand = useCallback(
async (method, command, data, init) => {
if(!allowCommand) throw new ViewNotAllowedError("command")
if(!allowCommand) {
throw new ViewNotAllowedError("command")
}
return await apiRequest(method, `${resourcesPath}${command}`, data, init)
},
[apiRequest, allowCommand, resourcesPath]
[apiRequest, allowCommand, resourcesPath],
)
const apiAction = useCallback(
async (method, id, command, data, init) => {
if(!allowAction) throw new ViewNotAllowedError("action")
if(!allowAction) {
throw new ViewNotAllowedError("action")
}
return await apiRequest(method, `${resourcesPath}${id}/${command}`, data, init)
},
[apiRequest, allowAction, resourcesPath]
[apiRequest, allowAction, resourcesPath],
)
const listResources = useCallback(

View file

@ -17,7 +17,6 @@ import BoxVisualizationMap from "../components/interactive/BoxVisualizationMap"
import BoxVisualizationWordcloud from "../components/interactive/BoxVisualizationWordcloud"
import BoxFull from "../components/base/BoxFull"
import ContextLanguage from "../contexts/ContextLanguage"
import tokenizeTweetWords from "../utils/countTweetWords"
import countTweetWords from "../utils/countTweetWords"
import objectToWordcloudFormat from "../utils/objectToWordcloudFormat"
@ -36,7 +35,7 @@ export default function PageRepository({ className, ...props }) {
edit: true,
destroy: true,
action: false,
}
},
)
const repository = repositoryBr.error ? null : repositoryBr.resource
@ -51,16 +50,16 @@ export default function PageRepository({ className, ...props }) {
destroy: false,
command: false,
action: false,
}
},
)
const tweets = tweetsBv.resources && tweetsBv.error ? [] : tweetsBv.resources
const words = useMemo(
() => objectToWordcloudFormat(countTweetWords(tweets)),
[tweets]
[tweets],
)
let contents;
let contents
if(!repositoryBr.firstLoad || !tweetsBv.firstLoad) {
contents = <>
<BoxHeader className={Style.Header}>

View file

@ -6,8 +6,7 @@
"a b"
"a c"
"d e"
"d f"
;
"d f";
grid-gap: 10px;
grid-template-columns: 1fr 1fr;

View file

@ -7,7 +7,7 @@ class ViewNotAllowedError extends NestError {
view
constructor(view) {
super();
super()
this.view = view
}

View file

@ -11,8 +11,12 @@ export default function countTweetWords(tweets = {}) {
continue
}
for(const word of tweet.content.toLowerCase().split(/\s+/)) {
if(stopwords.includes(word)) continue
if(word.startsWith("https://")) continue
if(stopwords.includes(word)) {
continue
}
if(word.startsWith("https://")) {
continue
}
if(!words.hasOwnProperty(word)) {
words[word] = 0

View file

@ -6,7 +6,7 @@ export default function objectToWordcloudFormat(words) {
}
result.push({
text: word,
value: words[word]
value: words[word],
})
}
return result