2022-09-23 16:43:45 -06:00
|
|
|
import React, {useState} from 'react';
|
2022-08-06 05:22:07 +00:00
|
|
|
import {Link, Route, Routes, useParams} from "react-router-dom";
|
|
|
|
|
import {
|
2021-11-01 16:42:52 -06:00
|
|
|
defaultSearchOrder,
|
|
|
|
|
defaultVideoOrder,
|
2022-01-31 16:52:22 -07:00
|
|
|
PageContainer,
|
2021-11-01 16:42:52 -06:00
|
|
|
scrollToTop,
|
2022-08-06 05:22:07 +00:00
|
|
|
SearchInput,
|
2022-01-29 22:25:35 -07:00
|
|
|
TabLinks,
|
2022-08-06 05:22:07 +00:00
|
|
|
useTitle,
|
|
|
|
|
videoOrders
|
2021-11-01 16:42:52 -06:00
|
|
|
} from "./Common"
|
|
|
|
|
import VideoPage from "./VideoPlayer";
|
2022-09-23 16:43:45 -06:00
|
|
|
import {Confirm, Dropdown, PlaceholderHeader, PlaceholderLine, StatisticLabel, StatisticValue} from "semantic-ui-react";
|
2021-11-01 16:42:52 -06:00
|
|
|
import {Channels, EditChannel, NewChannel} from "./Channels";
|
2022-08-06 05:22:07 +00:00
|
|
|
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";
|
2022-09-23 16:43:45 -06:00
|
|
|
import {Button, Header, Loader, Placeholder, Segment, Statistic, StatisticGroup} from "./Theme";
|
|
|
|
|
import {deleteVideos} from "../api";
|
2022-08-06 05:22:07 +00:00
|
|
|
|
|
|
|
|
export function VideoWrapper() {
|
|
|
|
|
const {videoId} = useParams();
|
2022-09-28 09:38:05 -06:00
|
|
|
const {videoFile, prevFile, nextFile, setFavorite} = useVideo(videoId);
|
2022-08-06 05:22:07 +00:00
|
|
|
scrollToTop();
|
|
|
|
|
|
2022-09-28 09:38:05 -06:00
|
|
|
return <VideoPage videoFile={videoFile} prevFile={prevFile} nextFile={nextFile}
|
|
|
|
|
setFavorite={setFavorite} autoplay={true}/>
|
2021-11-01 16:42:52 -06:00
|
|
|
}
|
|
|
|
|
|
2022-08-06 05:22:07 +00:00
|
|
|
function Videos({filter}) {
|
|
|
|
|
const {channelId} = useParams();
|
|
|
|
|
const {searchParams, updateQuery} = useQuery();
|
2022-09-23 16:43:45 -06:00
|
|
|
const [selectedVideos, setSelectedVideos] = useState([]);
|
|
|
|
|
const [deleteOpen, setDeleteOpen] = useState(false);
|
2021-11-01 16:42:52 -06:00
|
|
|
|
2022-08-06 05:22:07 +00:00
|
|
|
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;
|
2021-11-01 16:42:52 -06:00
|
|
|
}
|
|
|
|
|
|
2022-08-06 05:22:07 +00:00
|
|
|
let filtersEnabled = searchParams.getAll('filter');
|
|
|
|
|
filtersEnabled = filter ? [...filtersEnabled, filter] : filtersEnabled;
|
2021-11-01 16:42:52 -06:00
|
|
|
|
2022-09-23 16:43:45 -06:00
|
|
|
const {searchStr, setSearchStr, videos, activePage, setPage, limit, setLimit, totalPages, setOrderBy, fetchVideos} =
|
2022-08-06 05:22:07 +00:00
|
|
|
useSearchVideos(null, channelId, searchOrder, filtersEnabled);
|
|
|
|
|
const setView = (value) => updateQuery({view: value});
|
|
|
|
|
const view = searchParams.get('view');
|
2021-11-01 16:42:52 -06:00
|
|
|
|
2022-08-06 05:22:07 +00:00
|
|
|
const {channel} = useChannel(channelId);
|
2021-11-01 16:42:52 -06:00
|
|
|
|
2022-08-06 05:22:07 +00:00
|
|
|
const filterOptions = [
|
|
|
|
|
{text: 'Favorites', key: 'favorite', value: 'favorite'},
|
|
|
|
|
{text: 'Censored', key: 'censored', value: 'censored'},
|
|
|
|
|
];
|
|
|
|
|
const setFilters = (value) => updateQuery({filter: value});
|
|
|
|
|
|
|
|
|
|
const menuColumns = <>
|
|
|
|
|
<Grid.Column mobile={8} computer={5}>
|
|
|
|
|
<SearchInput clearable searchStr={searchStr} onSubmit={setSearchStr} actionIcon='search'/>
|
|
|
|
|
</Grid.Column>
|
|
|
|
|
<Grid.Column mobile={6} computer={5}>
|
|
|
|
|
<Dropdown selection fluid
|
|
|
|
|
size='large'
|
|
|
|
|
placeholder='Sort by...'
|
|
|
|
|
value={searchOrder}
|
|
|
|
|
options={videoOrders}
|
|
|
|
|
onChange={(e, {value}) => setOrderBy(value)}
|
|
|
|
|
/>
|
|
|
|
|
</Grid.Column>
|
|
|
|
|
</>;
|
|
|
|
|
|
|
|
|
|
let header;
|
|
|
|
|
if (channel && channel.name) {
|
|
|
|
|
const editLink = `/videos/channel/${channelId}/edit`;
|
|
|
|
|
header = <>
|
|
|
|
|
<Header as='h1'>
|
|
|
|
|
{channel.name}
|
|
|
|
|
<Link to={editLink}>
|
|
|
|
|
<Icon name='edit' style={{marginLeft: '0.5em'}}/>
|
|
|
|
|
</Link>
|
|
|
|
|
</Header>
|
|
|
|
|
</>;
|
|
|
|
|
} else if (channelId) {
|
|
|
|
|
header = <Placeholder style={{marginBottom: '1em'}}>
|
|
|
|
|
<PlaceholderHeader>
|
|
|
|
|
<PlaceholderLine/>
|
|
|
|
|
</PlaceholderHeader>
|
|
|
|
|
</Placeholder>;
|
2021-11-01 16:42:52 -06:00
|
|
|
}
|
|
|
|
|
|
2022-09-23 16:43:45 -06:00
|
|
|
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 = <div style={{marginTop: '0.5em'}}>
|
|
|
|
|
<Button
|
|
|
|
|
color='red'
|
|
|
|
|
disabled={!selectedVideos || selectedVideos.length === 0}
|
|
|
|
|
onClick={() => setDeleteOpen(true)}
|
|
|
|
|
>Delete</Button>
|
|
|
|
|
<Confirm
|
|
|
|
|
open={deleteOpen}
|
|
|
|
|
content='Are you sure you want to delete these video files? This cannot be undone.'
|
|
|
|
|
confirmButton='Delete'
|
|
|
|
|
onCancel={() => setDeleteOpen(false)}
|
|
|
|
|
onConfirm={onDelete}
|
|
|
|
|
/>
|
|
|
|
|
</div>;
|
|
|
|
|
|
2022-01-03 15:13:02 -07:00
|
|
|
return <>
|
2022-08-06 05:22:07 +00:00
|
|
|
{header}
|
|
|
|
|
<FilesView
|
|
|
|
|
files={videos}
|
|
|
|
|
view={view}
|
|
|
|
|
limit={limit}
|
|
|
|
|
activePage={activePage}
|
|
|
|
|
totalPages={totalPages}
|
|
|
|
|
showView={true}
|
|
|
|
|
showLimit={true}
|
|
|
|
|
showSelect={true}
|
2022-09-23 16:43:45 -06:00
|
|
|
onSelect={onSelect}
|
|
|
|
|
selectElem={selectElm}
|
2022-08-06 05:22:07 +00:00
|
|
|
setView={setView}
|
|
|
|
|
setLimit={setLimit}
|
|
|
|
|
setPage={setPage}
|
|
|
|
|
filterOptions={filterOptions}
|
|
|
|
|
activeFilters={filtersEnabled}
|
|
|
|
|
setFilters={setFilters}
|
|
|
|
|
multipleFilters={true}
|
|
|
|
|
menuColumnsCount={3}
|
|
|
|
|
menuColumns={menuColumns}
|
|
|
|
|
>
|
|
|
|
|
</FilesView>
|
2022-01-03 15:13:02 -07:00
|
|
|
</>
|
2021-11-01 16:42:52 -06:00
|
|
|
}
|
|
|
|
|
|
2022-08-06 05:22:07 +00:00
|
|
|
function Statistics() {
|
|
|
|
|
const {statistics} = useVideoStatistics();
|
|
|
|
|
const {videos, historical, channels} = statistics;
|
2021-12-23 09:38:12 -07:00
|
|
|
|
2022-08-06 05:22:07 +00:00
|
|
|
if (!videos) {
|
|
|
|
|
return <Loader active inline='centered'/>
|
2021-12-23 09:38:12 -07:00
|
|
|
}
|
|
|
|
|
|
2022-08-06 05:22:07 +00:00
|
|
|
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'},
|
|
|
|
|
];
|
2021-11-01 16:42:52 -06:00
|
|
|
|
2022-08-06 05:22:07 +00:00
|
|
|
const buildSegment = (title, names, stats) => {
|
|
|
|
|
return <Segment>
|
|
|
|
|
<Header textAlign='center' as='h1'>{title}</Header>
|
|
|
|
|
<StatisticGroup>
|
|
|
|
|
{names.map(
|
|
|
|
|
({key, label}) =>
|
|
|
|
|
<Statistic key={key} style={{margin: '2em'}}>
|
|
|
|
|
<StatisticValue>{stats[key]}</StatisticValue>
|
|
|
|
|
<StatisticLabel>{label}</StatisticLabel>
|
|
|
|
|
</Statistic>
|
|
|
|
|
)}
|
|
|
|
|
</StatisticGroup>
|
|
|
|
|
</Segment>
|
2021-11-01 16:42:52 -06:00
|
|
|
}
|
|
|
|
|
|
2022-01-29 22:25:35 -07:00
|
|
|
return (
|
2022-08-06 05:22:07 +00:00
|
|
|
<>
|
|
|
|
|
{buildSegment('Videos', videoNames, videos)}
|
|
|
|
|
{buildSegment('Historical Video', historicalNames, historical)}
|
|
|
|
|
{buildSegment('Channels', channelNames, channels)}
|
|
|
|
|
</>
|
2022-01-29 22:25:35 -07:00
|
|
|
)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export function VideosRoute(props) {
|
2022-08-06 05:22:07 +00:00
|
|
|
useTitle('Videos');
|
2021-11-01 16:42:52 -06:00
|
|
|
|
2022-01-29 22:25:35 -07:00
|
|
|
const links = [
|
2022-08-06 05:22:07 +00:00
|
|
|
{text: 'Videos', to: '/videos', key: 'videos', end: true},
|
2022-02-02 14:02:51 -07:00
|
|
|
{text: 'Favorites', to: '/videos/favorites', key: 'favorites'},
|
|
|
|
|
{text: 'Channels', to: '/videos/channel', key: 'channel'},
|
2022-08-06 05:22:07 +00:00
|
|
|
{text: 'Statistics', to: '/videos/statistics', key: 'statistics'},
|
2022-01-29 22:25:35 -07:00
|
|
|
];
|
|
|
|
|
|
|
|
|
|
return (
|
2022-01-31 09:32:06 -07:00
|
|
|
<PageContainer>
|
2022-01-29 22:25:35 -07:00
|
|
|
<TabLinks links={links}/>
|
2022-08-06 05:22:07 +00:00
|
|
|
<Routes>
|
|
|
|
|
<Route path='/' exact element={<Videos/>}/>
|
|
|
|
|
<Route path='favorites' exact element={<Videos filter='favorite' header='Favorite Videos'/>}/>
|
|
|
|
|
<Route path='channel' exact element={<Channels/>}/>
|
|
|
|
|
<Route path='statistics' exact element={<Statistics/>}/>
|
|
|
|
|
<Route path='channel/new' exact element={<NewChannel/>}/>
|
|
|
|
|
<Route path='channel/:channelId/edit' exact element={<EditChannel/>}/>
|
|
|
|
|
<Route path='channel/:channelId/video' exact element={<Videos/>}/>
|
|
|
|
|
</Routes>
|
2022-01-31 09:32:06 -07:00
|
|
|
</PageContainer>
|
2022-01-29 22:25:35 -07:00
|
|
|
)
|
2021-11-01 16:42:52 -06:00
|
|
|
}
|
|
|
|
|
|