import React, { useContext, useMemo, useState } from "react" import Style from "./RepositoryViewer.module.css" import classNames from "classnames" import ContextLanguage from "../../contexts/ContextLanguage" import useBackendResource from "../../hooks/useBackendResource" import useBackendViewset from "../../hooks/useBackendViewset" import objectToWordcloudFormat from "../../utils/objectToWordcloudFormat" import countTweetWords from "../../utils/countTweetWords" import BoxHeader from "../base/BoxHeader" import Loading from "../base/Loading" import { FontAwesomeIcon } from "@fortawesome/react-fontawesome" import { faFolder, faFolderOpen, faTrash } from "@fortawesome/free-solid-svg-icons" import BoxRepositoryTweets from "../interactive/BoxRepositoryTweets" import PickerVisualization from "../interactive/PickerVisualization" import BoxVisualizationWordcloud from "../interactive/BoxVisualizationWordcloud" import BoxVisualizationChart from "../interactive/BoxVisualizationChart" import BoxVisualizationMap from "../interactive/BoxVisualizationMap" import BoxVisualizationStats from "../interactive/BoxVisualizationStats" import PickerFilter from "../interactive/PickerFilter" import useArrayState from "../../hooks/useArrayState" import BoxFilters from "../interactive/BoxFilters" import ContextRepositoryViewer from "../../contexts/ContextRepositoryViewer" import BoxFilterContains from "../interactive/BoxFilterContains" import BoxFilterUser from "../interactive/BoxFilterUser" import BoxFilterHashtag from "../interactive/BoxFilterHashtag" import BoxFilterLocation from "../interactive/BoxFilterLocation" import useMapView from "../../hooks/useMapView" import BoxFilterDatetime from "../interactive/BoxFilterDatetime" import BoxFilterHasPlace from "../interactive/BoxFilterHasPlace" export default function RepositoryViewer({ id, className, ...props }) { const { strings } = useContext(ContextLanguage) // State const [visualizationTab, setVisualizationTab] = useState("stats") const [filterTab, setFilterTab] = useState("contains") const { value: filters, setValue: setFilters, appendValue: appendFilter, spliceValue: spliceFilter, removeValue: removeFilter, } = useArrayState([]) // FIXME: this has a severe performance impact, investigate const mapViewHook = useMapView() // Repository const repositoryBr = useBackendResource( `/api/v1/repositories/${id}`, { retrieve: true, edit: true, destroy: true, action: false, }, ) const repository = repositoryBr.error ? null : repositoryBr.resource // Tweets const rawTweetsBv = useBackendViewset( `/api/v1/repositories/${id}/tweets/`, "snowflake", { list: true, create: false, retrieve: false, edit: false, destroy: false, command: false, action: false, }, ) const rawTweets = rawTweetsBv.resources && rawTweetsBv.error ? [] : rawTweetsBv.resources // Filtering let tweets = rawTweets for(const filter of filters) { tweets = tweets.filter(tweet => filter.exec(tweet)) } // Words const words = useMemo( () => objectToWordcloudFormat(countTweetWords(tweets)), [tweets], ) let contents if(!repositoryBr.firstLoad || !rawTweetsBv.firstLoad) { contents = <> } else if(repository === null) { contents = <> {strings.repoDeleted} } else { contents = <> {repository.name} {visualizationTab === "wordcloud" ? : null} {visualizationTab === "chart" ? : null} {visualizationTab === "map" ? : null} {visualizationTab === "stats" ? : null} {filterTab === "contains" ? : null} {filterTab === "hashtag" ? : null} {filterTab === "user" ? : null} {filterTab === "time" ? : null} {filterTab === "place" ? : null} {filterTab === "location" ? : null} } return (
{contents}
) }