import React, {useState} from 'react'; import {Link, Route, Routes, useParams} from "react-router-dom"; import { defaultSearchOrder, defaultVideoOrder, PageContainer, scrollToTop, SearchInput, TabLinks, useTitle, videoOrders } from "./Common" import VideoPage from "./VideoPlayer"; import {Confirm, Dropdown, PlaceholderHeader, PlaceholderLine, StatisticLabel, StatisticValue} from "semantic-ui-react"; import {Channels, EditChannel, NewChannel} from "./Channels"; import {useChannel, useQuery, useSearchVideos, useVideo, useVideoStatistics} from "../hooks/customHooks"; import {FilesView} from "./Files"; import Grid from "semantic-ui-react/dist/commonjs/collections/Grid"; import Icon from "semantic-ui-react/dist/commonjs/elements/Icon"; import {Button, Header, Loader, Placeholder, Segment, Statistic, StatisticGroup} from "./Theme"; import {deleteVideos} from "../api"; export function VideoWrapper() { const {videoId} = useParams(); const {videoFile, prevFile, nextFile, setFavorite} = useVideo(videoId); scrollToTop(); return } function Videos({filter}) { const {channelId} = useParams(); const {searchParams, updateQuery} = useQuery(); const [selectedVideos, setSelectedVideos] = useState([]); const [deleteOpen, setDeleteOpen] = useState(false); let searchOrder = defaultVideoOrder; if (searchParams.get('order')) { // Use whatever order the user specified. searchOrder = searchParams.get('order'); } else if (searchParams.get('q')) { // User used a search_str searchOrder = defaultSearchOrder; } let filtersEnabled = searchParams.getAll('filter'); filtersEnabled = filter ? [...filtersEnabled, filter] : filtersEnabled; const {searchStr, setSearchStr, videos, activePage, setPage, limit, setLimit, totalPages, setOrderBy, fetchVideos} = useSearchVideos(null, channelId, searchOrder, filtersEnabled); const setView = (value) => updateQuery({view: value}); const view = searchParams.get('view'); const {channel} = useChannel(channelId); const filterOptions = [ {text: 'Favorites', key: 'favorite', value: 'favorite'}, {text: 'Censored', key: 'censored', value: 'censored'}, ]; const setFilters = (value) => updateQuery({filter: value}); const menuColumns = <> setOrderBy(value)} /> ; let header; if (channel && channel.name) { const editLink = `/videos/channel/${channelId}/edit`; header = <>
{channel.name}
; } else if (channelId) { header = ; } const onSelect = (path, checked) => { let videoId; if (videos) { videos.forEach(i => { if (i && i['video'] && i['path'] === path) { videoId = i['video']['id']; } }); } if (checked && videoId) { setSelectedVideos([...selectedVideos, videoId]); } else { setSelectedVideos(selectedVideos.filter(i => i !== videoId)); } } const onDelete = async (e) => { e.preventDefault(); setDeleteOpen(false); await deleteVideos(selectedVideos); await fetchVideos(); setSelectedVideos([]); } const selectElm =
setDeleteOpen(false)} onConfirm={onDelete} />
; return <> {header} } function Statistics() { const {statistics} = useVideoStatistics(); const {videos, historical, channels} = statistics; if (!videos) { return } const videoNames = [ {key: 'videos', label: 'Downloaded Videos'}, {key: 'favorites', label: 'Favorite Videos'}, {key: 'sum_size', label: 'Total Size'}, {key: 'max_size', label: 'Largest Video'}, {key: 'week', label: 'Downloads Past Week'}, {key: 'month', label: 'Downloads Past Month'}, {key: 'year', label: 'Downloads Past Year'}, {key: 'sum_duration', label: 'Total Duration'}, ]; const historicalNames = [ {key: 'average_count', label: 'Average Monthly Downloads'}, {key: 'average_size', label: 'Average Monthly Usage'}, ]; const channelNames = [ {key: 'channels', label: 'Channels'}, ]; const buildSegment = (title, names, stats) => { return
{title}
{names.map( ({key, label}) => {stats[key]} {label} )}
} return ( <> {buildSegment('Videos', videoNames, videos)} {buildSegment('Historical Video', historicalNames, historical)} {buildSegment('Channels', channelNames, channels)} ) } export function VideosRoute(props) { useTitle('Videos'); const links = [ {text: 'Videos', to: '/videos', key: 'videos', end: true}, {text: 'Favorites', to: '/videos/favorites', key: 'favorites'}, {text: 'Channels', to: '/videos/channel', key: 'channel'}, {text: 'Statistics', to: '/videos/statistics', key: 'statistics'}, ]; return ( }/> }/> }/> }/> }/> }/> }/> ) }