mirror of
https://github.com/pds-nest/nest.git
synced 2024-11-22 04:54:18 +00:00
🧹 Reformat code
This commit is contained in:
parent
df4b9bb368
commit
6a99effc8b
22 changed files with 225 additions and 159 deletions
|
@ -28,12 +28,12 @@ export default function Badge({ icon, color, onClickDelete, children, className,
|
|||
</div>
|
||||
{
|
||||
onClickDelete ?
|
||||
<div>
|
||||
<ButtonSmallX
|
||||
onClick={onClickDelete}
|
||||
/>
|
||||
</div>
|
||||
: null
|
||||
<div>
|
||||
<ButtonSmallX
|
||||
onClick={onClickDelete}
|
||||
/>
|
||||
</div>
|
||||
: null
|
||||
}
|
||||
</div>
|
||||
)
|
||||
|
|
|
@ -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}
|
||||
|
|
|
@ -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)}>
|
||||
|
|
|
@ -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/>
|
||||
|
|
|
@ -8,7 +8,7 @@ const locationRegex = /[{](?<lat>[0-9.]+),(?<lng>[0-9.]+)[}]/
|
|||
|
||||
export default function BoxVisualizationMap({ tweets, ...props }) {
|
||||
// TODO: translate this
|
||||
const {strings} = useContext(ContextLanguage)
|
||||
const { strings } = useContext(ContextLanguage)
|
||||
|
||||
console.debug(tweets)
|
||||
const markers = tweets.filter(tweet => tweet.location).map(tweet => {
|
||||
|
@ -17,7 +17,7 @@ export default function BoxVisualizationMap({ tweets, ...props }) {
|
|||
console.error("No match for location ", tweet.location)
|
||||
return null
|
||||
}
|
||||
const {lat, lng} = match.groups
|
||||
const { lat, lng } = match.groups
|
||||
return (
|
||||
<Marker key={tweet["snowflake"]} position={[Number.parseFloat(lat), Number.parseFloat(lng)]}>
|
||||
<Popup>
|
||||
|
|
|
@ -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(
|
||||
|
@ -45,51 +44,61 @@ export default function BoxVisualizationStats({ tweets, words, totalTweetCount,
|
|||
console.debug(words)
|
||||
|
||||
const wordCount = useMemo(
|
||||
() => words.map(word => word.value).reduce((a, b) => a+b),
|
||||
[words]
|
||||
() => words.map(word => word.value).reduce((a, b) => a + b),
|
||||
[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
|
||||
|
|
|
@ -4,7 +4,7 @@ import ContextLanguage from "../../contexts/ContextLanguage"
|
|||
|
||||
|
||||
export default function BoxVisualizationWordcloud({ words, ...props }) {
|
||||
const {strings} = useContext(ContextLanguage)
|
||||
const { strings } = useContext(ContextLanguage)
|
||||
|
||||
return (
|
||||
<BoxWordcloud header={strings.wordcloud} words={words} {...props}/>
|
||||
|
|
|
@ -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>
|
||||
)
|
||||
}
|
||||
|
|
|
@ -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>
|
||||
)
|
||||
}
|
||||
|
|
|
@ -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"
|
||||
|
@ -45,37 +44,37 @@ export default function SummaryRepository(
|
|||
/>
|
||||
|
||||
{destroy ?
|
||||
<SummaryButton
|
||||
color={"Red"}
|
||||
icon={faTrash}
|
||||
onClick={() => destroy(repo["id"])}
|
||||
disabled={running}
|
||||
>
|
||||
{strings.delete}
|
||||
</SummaryButton>
|
||||
: null}
|
||||
<SummaryButton
|
||||
color={"Red"}
|
||||
icon={faTrash}
|
||||
onClick={() => destroy(repo["id"])}
|
||||
disabled={running}
|
||||
>
|
||||
{strings.delete}
|
||||
</SummaryButton>
|
||||
: null}
|
||||
|
||||
{archive ?
|
||||
<SummaryButton
|
||||
color={"Grey"}
|
||||
icon={faArchive}
|
||||
onClick={() => archive(repo["id"])}
|
||||
disabled={running}
|
||||
>
|
||||
{strings.archive}
|
||||
</SummaryButton>
|
||||
: null}
|
||||
<SummaryButton
|
||||
color={"Grey"}
|
||||
icon={faArchive}
|
||||
onClick={() => archive(repo["id"])}
|
||||
disabled={running}
|
||||
>
|
||||
{strings.archive}
|
||||
</SummaryButton>
|
||||
: null}
|
||||
|
||||
{edit ?
|
||||
<SummaryButton
|
||||
color={"Yellow"}
|
||||
icon={faPencilAlt}
|
||||
onClick={() => edit(repo["id"])}
|
||||
disabled={running}
|
||||
>
|
||||
{strings.edit}
|
||||
</SummaryButton>
|
||||
: null}
|
||||
<SummaryButton
|
||||
color={"Yellow"}
|
||||
icon={faPencilAlt}
|
||||
onClick={() => edit(repo["id"])}
|
||||
disabled={running}
|
||||
>
|
||||
{strings.edit}
|
||||
</SummaryButton>
|
||||
: null}
|
||||
|
||||
<SummaryRight/>
|
||||
</SummaryBase>
|
||||
|
|
|
@ -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"
|
||||
|
||||
|
|
|
@ -22,18 +22,18 @@ export default function SummaryUser({ user, destroyUser, running, ...props }) {
|
|||
upperLabel={strings.type}
|
||||
upperValue={user.isAdmin ? strings.admin : strings.user}
|
||||
/>
|
||||
<SummaryButton
|
||||
color={"Red"}
|
||||
icon={faTrash}
|
||||
onClick={async event => {
|
||||
event.stopPropagation()
|
||||
// TODO: Errors are not caught here. Where should they be displayed?
|
||||
await destroyUser(user["email"])
|
||||
}}
|
||||
disabled={running}
|
||||
>
|
||||
{strings.delete}
|
||||
</SummaryButton>
|
||||
<SummaryButton
|
||||
color={"Red"}
|
||||
icon={faTrash}
|
||||
onClick={async event => {
|
||||
event.stopPropagation()
|
||||
// TODO: Errors are not caught here. Where should they be displayed?
|
||||
await destroyUser(user["email"])
|
||||
}}
|
||||
disabled={running}
|
||||
>
|
||||
{strings.delete}
|
||||
</SummaryButton>
|
||||
<SummaryRight/>
|
||||
</SummaryBase>
|
||||
)
|
||||
|
|
|
@ -76,7 +76,7 @@ export default function useBackendRequest() {
|
|||
try {
|
||||
json = await response.json()
|
||||
}
|
||||
catch (error) {
|
||||
catch(error) {
|
||||
throw new DecodeError(response.status, response.statusText, error)
|
||||
}
|
||||
|
||||
|
|
|
@ -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,15 +8,17 @@ 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,
|
||||
{
|
||||
retrieve: allowRetrieve = true,
|
||||
edit: allowEdit = true,
|
||||
destroy: allowDestroy = true,
|
||||
action: allowAction = false,
|
||||
} = {}) {
|
||||
export default function useBackendResource(
|
||||
resourcePath,
|
||||
{
|
||||
retrieve: allowRetrieve = true,
|
||||
edit: allowEdit = true,
|
||||
destroy: allowDestroy = true,
|
||||
action: allowAction = false,
|
||||
} = {},
|
||||
) {
|
||||
|
||||
const {abort, running, apiRequest} = useBackendRequest()
|
||||
const { abort, running, apiRequest } = useBackendRequest()
|
||||
|
||||
const [firstLoad, setFirstLoad] = useState(false)
|
||||
const [resource, setResource] = useState(null)
|
||||
|
@ -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(
|
||||
|
|
|
@ -18,8 +18,9 @@ export default function useBackendViewset(resourcesPath, pkName,
|
|||
destroy: allowDestroy = true,
|
||||
command: allowCommand = false,
|
||||
action: allowAction = false,
|
||||
} = {}) {
|
||||
const {abort, running, apiRequest} = useBackendRequest()
|
||||
} = {},
|
||||
) {
|
||||
const { abort, running, apiRequest } = useBackendRequest()
|
||||
|
||||
const [firstLoad, setFirstLoad] = useState(false)
|
||||
const [resources, setResources] = useState([])
|
||||
|
@ -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(
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
import React, {useContext} from "react"
|
||||
import React, { useContext } from "react"
|
||||
import Style from "./PageDashboard.module.css"
|
||||
import classNames from "classnames"
|
||||
import BoxHeader from "../components/base/BoxHeader"
|
||||
|
|
|
@ -10,7 +10,7 @@ import ContextLanguage from "../contexts/ContextLanguage"
|
|||
export default function PageRepositories({ children, className, ...props }) {
|
||||
const bv = useBackendViewset("/api/v1/repositories/", "id")
|
||||
const history = useHistory()
|
||||
const {strings} = useContext(ContextLanguage)
|
||||
const { strings } = useContext(ContextLanguage)
|
||||
|
||||
const archive = useCallback(
|
||||
async (pk) => {
|
||||
|
|
|
@ -8,7 +8,7 @@ import PickerFilter from "../components/interactive/PickerFilter"
|
|||
import useBackendViewset from "../hooks/useBackendViewset"
|
||||
import useBackendResource from "../hooks/useBackendResource"
|
||||
import { faFolder, faFolderOpen, faTrash } from "@fortawesome/free-solid-svg-icons"
|
||||
import {FontAwesomeIcon} from "@fortawesome/react-fontawesome"
|
||||
import { FontAwesomeIcon } from "@fortawesome/react-fontawesome"
|
||||
import { useParams } from "react-router"
|
||||
import Loading from "../components/base/Loading"
|
||||
import BoxVisualizationStats from "../components/interactive/BoxVisualizationStats"
|
||||
|
@ -17,14 +17,13 @@ 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"
|
||||
|
||||
|
||||
export default function PageRepository({ className, ...props }) {
|
||||
const {id} = useParams()
|
||||
const {strings} = useContext(ContextLanguage)
|
||||
const { id } = useParams()
|
||||
const { strings } = useContext(ContextLanguage)
|
||||
|
||||
const [visualizationTab, setVisualizationTab] = useState("wordcloud")
|
||||
const [addFilterTab, setAddFilterTab] = useState("hashtag")
|
||||
|
@ -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}>
|
||||
|
@ -93,32 +92,32 @@ export default function PageRepository({ className, ...props }) {
|
|||
setTab={setVisualizationTab}
|
||||
/>
|
||||
{visualizationTab === "wordcloud" ?
|
||||
<BoxVisualizationWordcloud
|
||||
className={Style.Wordcloud}
|
||||
tweets={tweets}
|
||||
words={words}
|
||||
/>
|
||||
: null}
|
||||
<BoxVisualizationWordcloud
|
||||
className={Style.Wordcloud}
|
||||
tweets={tweets}
|
||||
words={words}
|
||||
/>
|
||||
: null}
|
||||
{visualizationTab === "histogram" ?
|
||||
<BoxVisualizationGraph
|
||||
className={Style.Wordcloud}
|
||||
tweets={tweets}
|
||||
/>
|
||||
: null}
|
||||
<BoxVisualizationGraph
|
||||
className={Style.Wordcloud}
|
||||
tweets={tweets}
|
||||
/>
|
||||
: null}
|
||||
{visualizationTab === "map" ?
|
||||
<BoxVisualizationMap
|
||||
className={Style.Wordcloud}
|
||||
tweets={tweets}
|
||||
/>
|
||||
: null}
|
||||
<BoxVisualizationMap
|
||||
className={Style.Wordcloud}
|
||||
tweets={tweets}
|
||||
/>
|
||||
: null}
|
||||
{visualizationTab === "stats" ?
|
||||
<BoxVisualizationStats
|
||||
className={Style.Wordcloud}
|
||||
tweets={tweets}
|
||||
words={words}
|
||||
totalTweetCount={tweets.length}
|
||||
/>
|
||||
: null}
|
||||
<BoxVisualizationStats
|
||||
className={Style.Wordcloud}
|
||||
tweets={tweets}
|
||||
words={words}
|
||||
totalTweetCount={tweets.length}
|
||||
/>
|
||||
: null}
|
||||
|
||||
<PickerFilter
|
||||
className={Style.FilterPicker}
|
||||
|
|
|
@ -6,8 +6,7 @@
|
|||
"a b"
|
||||
"a c"
|
||||
"d e"
|
||||
"d f"
|
||||
;
|
||||
"d f";
|
||||
|
||||
grid-gap: 10px;
|
||||
grid-template-columns: 1fr 1fr;
|
||||
|
|
|
@ -7,7 +7,7 @@ class ViewNotAllowedError extends NestError {
|
|||
view
|
||||
|
||||
constructor(view) {
|
||||
super();
|
||||
super()
|
||||
|
||||
this.view = view
|
||||
}
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -6,7 +6,7 @@ export default function objectToWordcloudFormat(words) {
|
|||
}
|
||||
result.push({
|
||||
text: word,
|
||||
value: words[word]
|
||||
value: words[word],
|
||||
})
|
||||
}
|
||||
return result
|
||||
|
|
Loading…
Reference in a new issue