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"
|
2021-05-19 17:56:41 +00:00
|
|
|
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 { useParams } from "react-router"
|
|
|
|
import Loading from "../components/base/Loading"
|
2021-05-20 09:39:40 +00:00
|
|
|
import BoxVisualizationStats from "../components/interactive/BoxVisualizationStats"
|
|
|
|
import BoxVisualizationGraph from "../components/interactive/BoxVisualizationGraph"
|
|
|
|
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 tokenizeTweetWords from "../utils/countTweetWords"
|
|
|
|
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-19 17:56:41 +00:00
|
|
|
const {id} = useParams()
|
2021-05-20 09:39:40 +00:00
|
|
|
const {strings} = useContext(ContextLanguage)
|
2021-05-19 17:56:41 +00:00
|
|
|
|
2021-05-19 00:05:20 +00:00
|
|
|
const [visualizationTab, setVisualizationTab] = useState("wordcloud")
|
|
|
|
const [addFilterTab, setAddFilterTab] = useState("hashtag")
|
|
|
|
|
2021-05-19 17:56:41 +00:00
|
|
|
const repositoryBr = useBackendResource(
|
|
|
|
`/api/v1/repositories/${id}`,
|
2021-05-18 17:37:32 +00:00
|
|
|
{
|
2021-05-19 17:56:41 +00:00
|
|
|
retrieve: true,
|
|
|
|
edit: true,
|
|
|
|
destroy: true,
|
|
|
|
action: false,
|
|
|
|
}
|
|
|
|
)
|
|
|
|
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,
|
|
|
|
}
|
|
|
|
)
|
|
|
|
const tweets = tweetsBv.resources && tweetsBv.error ? [] : tweetsBv.resources
|
2021-05-18 17:37:32 +00:00
|
|
|
|
2021-05-20 10:15:13 +00:00
|
|
|
const words = useMemo(
|
|
|
|
() => objectToWordcloudFormat(countTweetWords(tweets)),
|
|
|
|
[tweets]
|
|
|
|
)
|
|
|
|
|
2021-05-19 17:56:41 +00:00
|
|
|
let contents;
|
|
|
|
if(!repositoryBr.firstLoad || !tweetsBv.firstLoad) {
|
|
|
|
contents = <>
|
|
|
|
<BoxHeader className={Style.Header}>
|
|
|
|
<Loading/>
|
|
|
|
</BoxHeader>
|
|
|
|
</>
|
|
|
|
}
|
|
|
|
else if(repository === null) {
|
|
|
|
// TODO: Translate this!
|
|
|
|
contents = <>
|
|
|
|
<BoxHeader className={Style.Header}>
|
|
|
|
<FontAwesomeIcon icon={faTrash}/> <i>This repository was deleted.</i>
|
|
|
|
</BoxHeader>
|
|
|
|
</>
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
contents = <>
|
2021-05-19 00:05:20 +00:00
|
|
|
<BoxHeader className={Style.Header}>
|
2021-05-19 17:56:41 +00:00
|
|
|
<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 09:39:40 +00:00
|
|
|
<BoxVisualizationWordcloud
|
|
|
|
className={Style.Wordcloud}
|
|
|
|
tweets={tweets}
|
2021-05-20 10:15:13 +00:00
|
|
|
words={words}
|
2021-05-20 09:39:40 +00:00
|
|
|
/>
|
|
|
|
: null}
|
|
|
|
{visualizationTab === "histogram" ?
|
|
|
|
<BoxVisualizationGraph
|
|
|
|
className={Style.Wordcloud}
|
|
|
|
tweets={tweets}
|
|
|
|
/>
|
|
|
|
: null}
|
|
|
|
{visualizationTab === "map" ?
|
|
|
|
<BoxVisualizationMap
|
|
|
|
className={Style.Wordcloud}
|
|
|
|
tweets={tweets}
|
|
|
|
/>
|
|
|
|
: null}
|
|
|
|
{visualizationTab === "stats" ?
|
|
|
|
<BoxVisualizationStats
|
|
|
|
className={Style.Wordcloud}
|
|
|
|
tweets={tweets}
|
2021-05-20 10:15:13 +00:00
|
|
|
words={words}
|
2021-05-20 09:39:40 +00:00
|
|
|
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>
|
2021-05-19 17:56:41 +00:00
|
|
|
</>
|
|
|
|
}
|
|
|
|
|
|
|
|
return (
|
|
|
|
<div className={classNames(Style.PageRepository, className)} {...props}>
|
|
|
|
{contents}
|
2021-05-15 16:05:13 +00:00
|
|
|
</div>
|
|
|
|
)
|
|
|
|
}
|