1
Fork 0
mirror of https://github.com/pds-nest/nest.git synced 2024-11-22 21:14:18 +00:00
pds-2021-g2-nest/nest_frontend/routes/PageRepository.js

143 lines
5 KiB
JavaScript
Raw Normal View History

2021-05-20 09:39:40 +00:00
import React, { useContext, useMemo, useState } from "react"
2021-05-15 16:05:13 +00:00
import Style from "./PageRepository.module.css"
import classNames from "classnames"
2021-05-18 17:15:53 +00:00
import BoxRepositoryTweets from "../components/interactive/BoxRepositoryTweets"
2021-05-19 00:05:20 +00:00
import BoxHeader from "../components/base/BoxHeader"
import PickerVisualization from "../components/interactive/PickerVisualization"
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"
2021-05-20 10:16:01 +00:00
import { FontAwesomeIcon } from "@fortawesome/react-fontawesome"
import { useParams } from "react-router"
import Loading from "../components/base/Loading"
2021-05-20 09:39:40 +00:00
import BoxVisualizationStats from "../components/interactive/BoxVisualizationStats"
2021-05-20 11:36:07 +00:00
import BoxVisualizationChart from "../components/interactive/BoxVisualizationChart"
2021-05-20 09:39:40 +00:00
import BoxVisualizationMap from "../components/interactive/BoxVisualizationMap"
import BoxVisualizationWordcloud from "../components/interactive/BoxVisualizationWordcloud"
import BoxFull from "../components/base/BoxFull"
import ContextLanguage from "../contexts/ContextLanguage"
2021-05-20 10:15:13 +00:00
import countTweetWords from "../utils/countTweetWords"
import objectToWordcloudFormat from "../utils/objectToWordcloudFormat"
2021-05-15 16:05:13 +00:00
export default function PageRepository({ className, ...props }) {
2021-05-20 10:16:01 +00:00
const { id } = useParams()
const { strings } = useContext(ContextLanguage)
2021-05-20 11:36:07 +00:00
const [visualizationTab, setVisualizationTab] = useState("stats")
2021-05-19 00:05:20 +00:00
const [addFilterTab, setAddFilterTab] = useState("hashtag")
const repositoryBr = useBackendResource(
`/api/v1/repositories/${id}`,
{
retrieve: true,
edit: true,
destroy: true,
action: false,
2021-05-20 10:16:01 +00:00
},
)
const repository = repositoryBr.error ? null : repositoryBr.resource
const tweetsBv = useBackendViewset(
`/api/v1/repositories/${id}/tweets/`,
"snowflake",
{
list: true,
create: false,
retrieve: false,
edit: false,
destroy: false,
command: false,
action: false,
2021-05-20 10:16:01 +00:00
},
)
const tweets = tweetsBv.resources && tweetsBv.error ? [] : tweetsBv.resources
2021-05-20 10:15:13 +00:00
const words = useMemo(
() => objectToWordcloudFormat(countTweetWords(tweets)),
2021-05-20 10:16:01 +00:00
[tweets],
2021-05-20 10:15:13 +00:00
)
2021-05-20 10:16:01 +00:00
let contents
if(!repositoryBr.firstLoad || !tweetsBv.firstLoad) {
contents = <>
<BoxHeader className={Style.Header}>
<Loading/>
</BoxHeader>
</>
}
else if(repository === null) {
contents = <>
<BoxHeader className={Style.Header}>
2021-05-20 16:28:08 +00:00
<FontAwesomeIcon icon={faTrash}/> <i>{strings.repoDeleted}</i>
</BoxHeader>
</>
}
else {
contents = <>
2021-05-19 00:05:20 +00:00
<BoxHeader className={Style.Header}>
<FontAwesomeIcon icon={repository.is_active ? faFolderOpen : faFolder}/> {repository.name}
2021-05-19 00:05:20 +00:00
</BoxHeader>
<BoxRepositoryTweets
className={Style.Tweets}
tweets={tweets}
/>
<PickerVisualization
className={Style.VisualizationPicker}
currentTab={visualizationTab}
setTab={setVisualizationTab}
/>
{visualizationTab === "wordcloud" ?
2021-05-20 10:16:01 +00:00
<BoxVisualizationWordcloud
className={Style.Wordcloud}
tweets={tweets}
words={words}
/>
: null}
2021-05-20 09:39:40 +00:00
{visualizationTab === "histogram" ?
2021-05-20 11:36:07 +00:00
<BoxVisualizationChart
2021-05-20 10:16:01 +00:00
className={Style.Wordcloud}
tweets={tweets}
/>
: null}
2021-05-20 09:39:40 +00:00
{visualizationTab === "map" ?
2021-05-20 10:16:01 +00:00
<BoxVisualizationMap
className={Style.Wordcloud}
tweets={tweets}
/>
: null}
2021-05-20 09:39:40 +00:00
{visualizationTab === "stats" ?
2021-05-20 10:16:01 +00:00
<BoxVisualizationStats
className={Style.Wordcloud}
tweets={tweets}
words={words}
totalTweetCount={tweets.length}
/>
: null}
2021-05-19 00:05:20 +00:00
<PickerFilter
className={Style.FilterPicker}
currentTab={addFilterTab}
setTab={setAddFilterTab}
/>
2021-05-20 09:39:40 +00:00
<BoxFull header={strings.notImplemented} className={Style.Filters}>
{strings.notImplemented}
</BoxFull>
<BoxFull header={strings.notImplemented} className={Style.AddFilter}>
{strings.notImplemented}
</BoxFull>
</>
}
return (
<div className={classNames(Style.PageRepository, className)} {...props}>
{contents}
2021-05-15 16:05:13 +00:00
</div>
)
}