mirror of
https://github.com/lrnselfreliance/wrolpi.git
synced 2026-12-05 06:09:57 -05:00
Feature/archive search (#70)
* Working through archive search. * Using custom hook. * Setting archive.contents duration creation. * Archive search and domain list use custom hooks. * Watching search param using value, not history. * Search params are preserved on load. Search and domain can be cleared. * Fixing archive external link. * Archive search form is new generic SearchInput. * Reworking Archives empty states. * Simplifying Archives logic. * Fixing bug which displayed the wrong empty state during loading. * Archives can be synced and deleted. * Changing wording of archive delete. * Removing URL table. * Deleting domain if it has no archives. * Fixing FE use of archive.url. Fixing bug with get_domains. * Universal results are displayed on Welcome page. * Creating ExternalLink to open a link in a new tab.g * Increasing size of search headers. * Adding divider to ease reading. * Adding More button below search results. * Disabling More buttons when there are no results. * Ordering videos by rank so linked results are at the top. Signed-off-by: Roland <roland@learningselfreliance.com>
This commit is contained in:
parent
b594f9761a
commit
c23b014add
17 changed files with 666 additions and 904 deletions
|
|
@ -1,29 +1,31 @@
|
|||
import React from "react";
|
||||
import {Card, Confirm, Container, Form, Header, Icon, Image, Placeholder, Tab, Table} from "semantic-ui-react";
|
||||
import Paginator, {APIForm, objectToQuery, scrollToTop, uploadDate} from "./Common";
|
||||
import {deleteArchive, fetchDomains, postArchive, refreshArchives, searchArchives} from "../api";
|
||||
import React, {useState} from "react";
|
||||
import {Card, Confirm, Container, Icon, Image, Placeholder, Tab} from "semantic-ui-react";
|
||||
import Paginator, {ClearButton, ExternalLink, SearchInput, uploadDate} from "./Common";
|
||||
import {deleteArchive, postDownload, refreshArchives} from "../api";
|
||||
import Button from "semantic-ui-react/dist/commonjs/elements/Button";
|
||||
import {Link, NavLink} from "react-router-dom";
|
||||
import * as QueryString from "query-string";
|
||||
import {ArchivePlaceholder} from "./Placeholder";
|
||||
import Table from "semantic-ui-react/dist/commonjs/collections/Table";
|
||||
import {useArchives} from "../hooks/useArchives";
|
||||
import {useDomains} from "../hooks/useDomains";
|
||||
|
||||
|
||||
function FailedArchiveCard({url, syncURL, deleteURL}) {
|
||||
function FailedArchiveCard({archive, syncArchive, deleteArchive}) {
|
||||
|
||||
let syncIcon = (
|
||||
<Button onClick={() => syncURL(url.url)}>
|
||||
<Button onClick={syncArchive}>
|
||||
<Icon name='sync' size='big'/>
|
||||
</Button>
|
||||
);
|
||||
|
||||
let trashIcon = (
|
||||
<Button onClick={() => deleteURL(url.id)}>
|
||||
<Button onClick={deleteArchive}>
|
||||
<Icon name='trash' size='big'/>
|
||||
</Button>
|
||||
);
|
||||
|
||||
let externalIcon = (
|
||||
<a href={url.url} target='_blank' rel='noopener noreferrer'>
|
||||
<a href={archive.url} target='_blank' rel='noopener noreferrer'>
|
||||
<Icon name='sign-out' size='big'/>
|
||||
</a>
|
||||
);
|
||||
|
|
@ -32,7 +34,7 @@ function FailedArchiveCard({url, syncURL, deleteURL}) {
|
|||
<Card>
|
||||
<Card.Content>
|
||||
<Card.Header>
|
||||
{url.url}
|
||||
{archive.url}
|
||||
</Card.Header>
|
||||
<Card.Description>
|
||||
<p>Failed!</p>
|
||||
|
|
@ -45,345 +47,172 @@ function FailedArchiveCard({url, syncURL, deleteURL}) {
|
|||
);
|
||||
}
|
||||
|
||||
class ArchiveCard extends React.Component {
|
||||
constructor(props) {
|
||||
super(props);
|
||||
this.state = {
|
||||
deleteOpen: false,
|
||||
syncOpen: false,
|
||||
}
|
||||
function ArchiveCard({archive, syncArchive, deleteArchive}) {
|
||||
const [syncOpen, setSyncOpen] = useState(false);
|
||||
const [deleteOpen, setDeleteOpen] = useState(false);
|
||||
|
||||
const localSyncArchive = async () => {
|
||||
setSyncOpen(false);
|
||||
await syncArchive(archive.url);
|
||||
}
|
||||
const localDeleteArchive = async () => {
|
||||
setDeleteOpen(false);
|
||||
await deleteArchive(archive.id);
|
||||
}
|
||||
|
||||
syncURL = async () => {
|
||||
await postArchive(this.props.archive.url.url);
|
||||
await this.props.fetchURLs();
|
||||
let imageSrc = archive.screenshot_path ? `/media/${archive.screenshot_path}` : null;
|
||||
let singlefileUrl = archive.singlefile_path ? `/media/${archive.singlefile_path}` : null;
|
||||
|
||||
if (archive.status === 'failed') {
|
||||
return <FailedArchiveCard archive={archive} syncArchive={localSyncArchive} deleteArchive={localDeleteArchive}/>;
|
||||
}
|
||||
|
||||
deleteURL = async () => {
|
||||
await deleteArchive(this.props.archive.id);
|
||||
await this.props.fetchURLs();
|
||||
let readabilityUrl = archive.readability_path ? `/media/${archive.readability_path}` : null;
|
||||
let readabilityIcon = <Button icon disabled><Icon name='book' size='large'/></Button>;
|
||||
if (readabilityUrl) {
|
||||
readabilityIcon = (
|
||||
<Button icon href={readabilityUrl} target='_blank' rel='noopener noreferrer'>
|
||||
<Icon name='book' size='large'/>
|
||||
</Button>);
|
||||
}
|
||||
|
||||
render() {
|
||||
let archive = this.props.archive;
|
||||
let syncIcon = null;
|
||||
if (syncArchive) {
|
||||
syncIcon = (<>
|
||||
<Button icon onClick={() => setSyncOpen(true)}>
|
||||
<Icon name='sync' size='large'/>
|
||||
</Button>
|
||||
<Confirm
|
||||
open={syncOpen}
|
||||
content='Download the latest version of this URL?'
|
||||
confirmButton='Confirm'
|
||||
onCancel={() => setSyncOpen(false)}
|
||||
onConfirm={localSyncArchive}
|
||||
/>
|
||||
</>);
|
||||
}
|
||||
|
||||
let imageSrc = archive.screenshot_path ? `/media/${archive.screenshot_path}` : null;
|
||||
let singlefileUrl = archive.singlefile_path ? `/media/${archive.singlefile_path}` : null;
|
||||
|
||||
if (archive.status === 'failed') {
|
||||
return <FailedArchiveCard url={archive} syncURL={this.syncURL} deleteURL={this.deleteURL}/>;
|
||||
}
|
||||
|
||||
let readabilityUrl = archive.readability_path ? `/media/${archive.readability_path}` : null;
|
||||
let readabilityIcon = <Button icon disabled><Icon name='book' size='large'/></Button>;
|
||||
if (readabilityUrl) {
|
||||
readabilityIcon = (
|
||||
<Button icon href={readabilityUrl} target='_blank' rel='noopener noreferrer'>
|
||||
<Icon name='book' size='large'/>
|
||||
</Button>);
|
||||
}
|
||||
|
||||
let syncIcon = (
|
||||
<>
|
||||
<Button icon onClick={() => this.setState({syncOpen: true})}>
|
||||
<Icon name='sync' size='large'/>
|
||||
let deleteIcon = null;
|
||||
if (deleteArchive) {
|
||||
deleteIcon = (<>
|
||||
<Button icon onClick={() => setDeleteOpen(true)}>
|
||||
<Icon name='trash' size='large'/>
|
||||
</Button>
|
||||
<Confirm
|
||||
open={this.state.syncOpen}
|
||||
content='Download the latest version of this URL?'
|
||||
confirmButton='Confirm'
|
||||
onCancel={() => this.setState({syncOpen: false})}
|
||||
onConfirm={this.syncURL}
|
||||
open={deleteOpen}
|
||||
content='Are you sure you want to delete this Archive? All files will be deleted.'
|
||||
confirmButton='Delete'
|
||||
onCancel={() => setDeleteOpen(false)}
|
||||
onConfirm={localDeleteArchive}
|
||||
/>
|
||||
</>
|
||||
);
|
||||
|
||||
let deleteIcon = (
|
||||
<>
|
||||
<Button icon onClick={() => this.setState({deleteOpen: true})}>
|
||||
<Icon name='trash' size='large'/>
|
||||
</Button>
|
||||
<Confirm
|
||||
open={this.state.deleteOpen}
|
||||
content='Are you sure you want to delete this URL? All files will be deleted.'
|
||||
confirmButton='Delete'
|
||||
onCancel={() => this.setState({deleteOpen: false})}
|
||||
onConfirm={this.deleteURL}
|
||||
/>
|
||||
</>
|
||||
)
|
||||
;
|
||||
|
||||
let externalIcon = (
|
||||
<Button icon href={archive.url} target='_blank' rel='noopener noreferrer'>
|
||||
<Icon name='sign-out' size='large'/>
|
||||
</Button>
|
||||
);
|
||||
|
||||
return (
|
||||
<Card>
|
||||
<Card.Content>
|
||||
<a href={singlefileUrl} target='_blank' rel='noopener noreferrer'>
|
||||
<Image src={imageSrc} wrapped style={{position: 'relative', width: '100%'}}/>
|
||||
<Card.Header>
|
||||
<Container textAlign='left'>
|
||||
<p>{archive.title || archive.url}</p>
|
||||
</Container>
|
||||
</Card.Header>
|
||||
</a>
|
||||
<Card.Meta>
|
||||
{uploadDate(archive.archive_datetime)}
|
||||
</Card.Meta>
|
||||
<Card.Description>
|
||||
<Container textAlign='left'>
|
||||
{readabilityIcon}
|
||||
{syncIcon}
|
||||
{deleteIcon}
|
||||
{externalIcon}
|
||||
</Container>
|
||||
</Card.Description>
|
||||
</Card.Content>
|
||||
</Card>
|
||||
)
|
||||
}
|
||||
|
||||
let externalIcon = (
|
||||
<Button icon href={archive.url} target='_blank' rel='noopener noreferrer'>
|
||||
<Icon name='sign-out' size='large'/>
|
||||
</Button>
|
||||
);
|
||||
|
||||
return (
|
||||
<Card>
|
||||
<ExternalLink to={singlefileUrl} className='no-link-underscore card-link'>
|
||||
<Image src={imageSrc} wrapped style={{position: 'relative', width: '100%'}}/>
|
||||
</ExternalLink>
|
||||
<Card.Content>
|
||||
<Card.Header>
|
||||
<Container textAlign='left'>
|
||||
<ExternalLink to={singlefileUrl} className='no-link-underscore card-link'>
|
||||
<p>{archive.title || archive.url}</p>
|
||||
</ExternalLink>
|
||||
</Container>
|
||||
</Card.Header>
|
||||
<Card.Meta>
|
||||
{uploadDate(archive.archive_datetime)}
|
||||
</Card.Meta>
|
||||
<Card.Description>
|
||||
<Container textAlign='left'>
|
||||
{readabilityIcon}
|
||||
{syncIcon}
|
||||
{deleteIcon}
|
||||
{externalIcon}
|
||||
</Container>
|
||||
</Card.Description>
|
||||
</Card.Content>
|
||||
</Card>
|
||||
)
|
||||
}
|
||||
|
||||
class ArchiveCards extends React.Component {
|
||||
render() {
|
||||
return (
|
||||
<Card.Group>
|
||||
{this.props.archives.map((i) => {
|
||||
return <ArchiveCard key={i['id']} archive={i} fetchURLs={this.props.fetchURLs}/>
|
||||
})}
|
||||
</Card.Group>
|
||||
)
|
||||
function ArchiveCards({archives, syncArchive, deleteArchive}) {
|
||||
return (
|
||||
<Card.Group>
|
||||
{archives.map((i) => {
|
||||
return <ArchiveCard key={i['id']} archive={i} syncArchive={syncArchive} deleteArchive={deleteArchive}/>
|
||||
})}
|
||||
</Card.Group>
|
||||
)
|
||||
}
|
||||
|
||||
export function ArchivesList({archives, searchStr, syncArchive, localDeleteArchive}) {
|
||||
if (archives === null || archives === undefined) {
|
||||
// Fetching archives.
|
||||
return <ArchivePlaceholder/>;
|
||||
} else if (archives.length === 0 && searchStr) {
|
||||
// Search with no results.
|
||||
return <p>No archives found! Is your search too restrictive?</p>;
|
||||
} else if (archives.length === 0) {
|
||||
// No archives fetched.
|
||||
return <p>No archives found! Have you archived any webpages?</p>;
|
||||
} else {
|
||||
// Archives fetched successfully!
|
||||
return <ArchiveCards archives={archives} syncArchive={syncArchive} deleteArchive={localDeleteArchive}/>;
|
||||
}
|
||||
}
|
||||
|
||||
class Archives extends React.Component {
|
||||
export function Archives() {
|
||||
const {archivesData, setPage, totalPages, searchStr, activePage, setSearchStr, domain, setDomain, search} =
|
||||
useArchives();
|
||||
const {archives} = archivesData;
|
||||
|
||||
constructor(props) {
|
||||
super(props);
|
||||
const query = QueryString.parse(this.props.location.search);
|
||||
let activePage = query.page ? parseInt(query.page) : 1;
|
||||
let domain = query.domain || null;
|
||||
|
||||
this.state = {
|
||||
activePage: activePage,
|
||||
limit: 20,
|
||||
archives: null,
|
||||
totalPages: null,
|
||||
domain: domain,
|
||||
};
|
||||
this.fetchURLs = this.fetchURLs.bind(this);
|
||||
this.clearSearch = this.clearSearch.bind(this);
|
||||
this.changePage = this.changePage.bind(this);
|
||||
const syncArchive = async (url) => {
|
||||
await postDownload(url, 'archive');
|
||||
await search();
|
||||
}
|
||||
|
||||
async componentDidMount() {
|
||||
await this.fetchURLs();
|
||||
const localDeleteArchive = async (archive_id) => {
|
||||
await deleteArchive(archive_id);
|
||||
await search();
|
||||
}
|
||||
|
||||
async componentDidUpdate(prevProps, prevState, snapshot) {
|
||||
if (prevProps.location.search !== this.props.location.search) {
|
||||
await this.fetchURLs();
|
||||
}
|
||||
let domainClearButton = null;
|
||||
if (domain) {
|
||||
domainClearButton = <ClearButton
|
||||
onClick={() => setDomain(null)}
|
||||
style={{marginBottom: '1em'}}
|
||||
label={`Domain: ${domain}`}
|
||||
/>;
|
||||
}
|
||||
|
||||
async fetchURLs() {
|
||||
this.setState({archives: null});
|
||||
let offset = this.state.limit * this.state.activePage - this.state.limit;
|
||||
let [archives, total] = await searchArchives(offset, this.state.limit, this.state.domain);
|
||||
let totalPages = Math.round(total / this.state.limit) || 1;
|
||||
this.setState({archives: archives, totalPages: totalPages});
|
||||
}
|
||||
|
||||
clearSearch() {
|
||||
this.setState({activePage: 1, domain: null}, this.changePage);
|
||||
}
|
||||
|
||||
changePage(activePage) {
|
||||
if (activePage) {
|
||||
this.setState({activePage});
|
||||
}
|
||||
let {history, location} = this.props;
|
||||
|
||||
let search = {
|
||||
page: activePage > 1 ? activePage : null,
|
||||
domain: this.state.domain,
|
||||
};
|
||||
|
||||
history.push({
|
||||
pathname: location.pathname,
|
||||
search: objectToQuery(search),
|
||||
});
|
||||
scrollToTop();
|
||||
}
|
||||
|
||||
render() {
|
||||
let {archives, activePage, totalPages} = this.state;
|
||||
|
||||
if (archives === null) {
|
||||
return (<>
|
||||
<Header as='h1'>Latest Archives</Header>
|
||||
<ArchivePlaceholder/>
|
||||
</>)
|
||||
}
|
||||
|
||||
let pagination = null;
|
||||
if (totalPages) {
|
||||
pagination = (
|
||||
<div style={{marginTop: '3em', textAlign: 'center'}}>
|
||||
<Paginator
|
||||
activePage={activePage}
|
||||
changePage={this.changePage}
|
||||
totalPages={totalPages}
|
||||
/>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
let domainButton = null;
|
||||
if (this.state.domain) {
|
||||
domainButton = (
|
||||
<Button icon labelPosition='right' onClick={this.clearSearch} style={{marginBottom: '1em'}}>
|
||||
Search: {this.state.domain}
|
||||
<Icon name='close'/>
|
||||
</Button>
|
||||
)
|
||||
}
|
||||
|
||||
return (
|
||||
<>
|
||||
<Header as='h1'>Latest Archives</Header>
|
||||
{domainButton}
|
||||
<ArchiveCards archives={archives} fetchURLs={this.fetchURLs}/>
|
||||
{pagination}
|
||||
</>
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
class Domains extends React.Component {
|
||||
constructor(props) {
|
||||
super(props);
|
||||
this.state = {
|
||||
domains: null,
|
||||
total: null,
|
||||
};
|
||||
this.fetchDomains = this.fetchDomains.bind(this);
|
||||
}
|
||||
|
||||
async componentDidMount() {
|
||||
await this.fetchDomains();
|
||||
}
|
||||
|
||||
async fetchDomains() {
|
||||
this.setState({domains: null});
|
||||
let [domains, total] = await fetchDomains();
|
||||
this.setState({domains, total});
|
||||
}
|
||||
|
||||
row(domain) {
|
||||
return <Table.Row key={domain['domain']}>
|
||||
<Table.Cell>
|
||||
<Link to={`/archive?domain=${domain['domain']}`}>
|
||||
{domain['domain']}
|
||||
</Link>
|
||||
</Table.Cell>
|
||||
<Table.Cell>{domain['url_count']}</Table.Cell>
|
||||
</Table.Row>
|
||||
}
|
||||
|
||||
render() {
|
||||
if (this.state.domains) {
|
||||
return (
|
||||
<>
|
||||
<Header as='h1'>Domains</Header>
|
||||
<Table celled>
|
||||
<Table.Header>
|
||||
<Table.Row>
|
||||
<Table.HeaderCell>Domain</Table.HeaderCell>
|
||||
<Table.HeaderCell>URLs</Table.HeaderCell>
|
||||
</Table.Row>
|
||||
</Table.Header>
|
||||
|
||||
<Table.Body>
|
||||
{this.state.domains.map(this.row)}
|
||||
</Table.Body>
|
||||
</Table>
|
||||
</>
|
||||
)
|
||||
}
|
||||
|
||||
return (<>
|
||||
<Header as='h1'>Domains</Header>
|
||||
<Placeholder>
|
||||
<Placeholder.Header>
|
||||
<Placeholder.Line/>
|
||||
<Placeholder.Line/>
|
||||
</Placeholder.Header>
|
||||
</Placeholder>
|
||||
</>)
|
||||
}
|
||||
}
|
||||
|
||||
class ArchiveAddForm extends APIForm {
|
||||
constructor(props) {
|
||||
super(props);
|
||||
this.archivesRef = props.archivesRef;
|
||||
|
||||
this.state = {
|
||||
...this.state,
|
||||
inputs: {
|
||||
url: '',
|
||||
},
|
||||
errors: {},
|
||||
};
|
||||
this.fetchURLs = this.fetchURLs.bind(this);
|
||||
}
|
||||
|
||||
handleSubmit = async (e) => {
|
||||
e.preventDefault();
|
||||
this.setLoading();
|
||||
try {
|
||||
let response = await postArchive(this.state.inputs.url);
|
||||
if (response.status === 204) {
|
||||
this.setState({inputs: {url: ''}, success: true}, this.fetchURLs);
|
||||
} else {
|
||||
this.setState({loading: false, success: undefined, error: true});
|
||||
}
|
||||
} finally {
|
||||
this.clearLoading();
|
||||
}
|
||||
}
|
||||
|
||||
fetchURLs = async (e) => {
|
||||
await this.archivesRef.current.fetchURLs();
|
||||
}
|
||||
|
||||
render() {
|
||||
return (
|
||||
<>
|
||||
<Form onSubmit={this.handleSubmit}>
|
||||
<label htmlFor='url'>Archive URL</label>
|
||||
<Form.Group>
|
||||
<Form.Input
|
||||
name='url'
|
||||
placeholder='https://wrolpi.org'
|
||||
value={this.state.inputs.url}
|
||||
disabled={this.state.disabled}
|
||||
error={this.state.error}
|
||||
onChange={this.handleInputChange}
|
||||
success={this.state.success}
|
||||
/>
|
||||
<Form.Button primary disabled={this.state.disabled}>Archive</Form.Button>
|
||||
</Form.Group>
|
||||
</Form>
|
||||
</>
|
||||
)
|
||||
}
|
||||
return (
|
||||
<>
|
||||
<SearchInput initValue={searchStr} onSubmit={setSearchStr}/>
|
||||
{domainClearButton}
|
||||
<ArchivesList
|
||||
archives={archives}
|
||||
searchStr={searchStr}
|
||||
syncArchive={syncArchive}
|
||||
localDeleteArchive={localDeleteArchive}
|
||||
/>
|
||||
<div style={{marginTop: '3em', textAlign: 'center'}}>
|
||||
<Paginator
|
||||
activePage={activePage}
|
||||
changePage={setPage}
|
||||
totalPages={totalPages}
|
||||
/>
|
||||
</div>
|
||||
</>
|
||||
)
|
||||
}
|
||||
|
||||
class ManageArchives extends React.Component {
|
||||
|
|
@ -401,6 +230,51 @@ class ManageArchives extends React.Component {
|
|||
}
|
||||
}
|
||||
|
||||
function Domains() {
|
||||
|
||||
const [domains] = useDomains();
|
||||
|
||||
const row = (domain) => {
|
||||
return <Table.Row key={domain['domain']}>
|
||||
<Table.Cell>
|
||||
<Link to={`/archive?domain=${domain['domain']}`}>
|
||||
{domain['domain']}
|
||||
</Link>
|
||||
</Table.Cell>
|
||||
<Table.Cell>{domain['url_count']}</Table.Cell>
|
||||
</Table.Row>
|
||||
}
|
||||
|
||||
if (domains) {
|
||||
return (
|
||||
<>
|
||||
<Table celled>
|
||||
<Table.Header>
|
||||
<Table.Row>
|
||||
<Table.HeaderCell>Domain</Table.HeaderCell>
|
||||
<Table.HeaderCell>URLs</Table.HeaderCell>
|
||||
</Table.Row>
|
||||
</Table.Header>
|
||||
|
||||
<Table.Body>
|
||||
{domains.map(row)}
|
||||
</Table.Body>
|
||||
</Table>
|
||||
</>
|
||||
)
|
||||
}
|
||||
|
||||
return (<>
|
||||
<Placeholder>
|
||||
<Placeholder.Header>
|
||||
<Placeholder.Line/>
|
||||
<Placeholder.Line/>
|
||||
</Placeholder.Header>
|
||||
</Placeholder>
|
||||
</>)
|
||||
}
|
||||
|
||||
|
||||
export class ArchiveRoute extends React.Component {
|
||||
|
||||
constructor(props) {
|
||||
|
|
@ -410,7 +284,43 @@ export class ArchiveRoute extends React.Component {
|
|||
this.state = {
|
||||
activeIndex: this.matchPaneTo(),
|
||||
}
|
||||
this.archivesRef = React.createRef();
|
||||
|
||||
this.archivePanes = [
|
||||
{
|
||||
menuItem: {
|
||||
as: NavLink,
|
||||
content: 'Archives',
|
||||
id: 'archive',
|
||||
to: '/archive',
|
||||
exact: true,
|
||||
key: 'home',
|
||||
},
|
||||
render: () => <Tab.Pane><Archives/></Tab.Pane>
|
||||
},
|
||||
{
|
||||
menuItem: {
|
||||
as: NavLink,
|
||||
content: 'Domains',
|
||||
id: 'domains',
|
||||
to: '/archive/domains',
|
||||
exact: true,
|
||||
key: 'domains',
|
||||
},
|
||||
render: () => <Tab.Pane><Domains/></Tab.Pane>
|
||||
},
|
||||
{
|
||||
menuItem: {
|
||||
as: NavLink,
|
||||
content: 'Manage',
|
||||
id: 'manage',
|
||||
to: '/archive/manage',
|
||||
exact: true,
|
||||
key: 'manage',
|
||||
},
|
||||
render: () => <Tab.Pane><ManageArchives/></Tab.Pane>
|
||||
},
|
||||
];
|
||||
|
||||
}
|
||||
|
||||
componentDidUpdate(prevProps, prevState, snapshot) {
|
||||
|
|
@ -424,46 +334,9 @@ export class ArchiveRoute extends React.Component {
|
|||
}
|
||||
|
||||
render() {
|
||||
const panes = [
|
||||
{
|
||||
menuItem: {
|
||||
as: NavLink,
|
||||
content: 'Archives',
|
||||
id: 'archive',
|
||||
to: '/archive',
|
||||
exact: true,
|
||||
key: 'home',
|
||||
},
|
||||
render: () => <Tab.Pane><Archives {...this.props} ref={this.archivesRef}/></Tab.Pane>
|
||||
},
|
||||
{
|
||||
menuItem: {
|
||||
as: NavLink,
|
||||
content: 'Domains',
|
||||
id: 'domains',
|
||||
to: '/archive/domains',
|
||||
exact: true,
|
||||
key: 'domains',
|
||||
},
|
||||
render: () => <Tab.Pane><Domains {...this.props}/></Tab.Pane>
|
||||
},
|
||||
{
|
||||
menuItem: {
|
||||
as: NavLink,
|
||||
content: 'Manage',
|
||||
id: 'manage',
|
||||
to: '/archive/manage',
|
||||
exact: true,
|
||||
key: 'manage',
|
||||
},
|
||||
render: () => <Tab.Pane><ManageArchives {...this.props}/></Tab.Pane>
|
||||
},
|
||||
];
|
||||
|
||||
return (
|
||||
<Container style={{marginTop: '2em', marginBottom: '2em'}}>
|
||||
<ArchiveAddForm archivesRef={this.archivesRef}/>
|
||||
<Tab panes={panes} activeIndex={this.state.activeIndex}/>
|
||||
<Tab panes={this.archivePanes} activeIndex={this.state.activeIndex} renderActiveOnly={true}/>
|
||||
</Container>
|
||||
)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,6 +1,8 @@
|
|||
import React from "react";
|
||||
import {Card, Container, Image, Pagination, Progress} from 'semantic-ui-react';
|
||||
import React, {useState} from "react";
|
||||
import {Card, Container, Form, Icon, Image, Input, Pagination, Progress} from 'semantic-ui-react';
|
||||
import {Link} from "react-router-dom";
|
||||
import Button from "semantic-ui-react/dist/commonjs/elements/Button";
|
||||
import Grid from "semantic-ui-react/dist/commonjs/collections/Grid";
|
||||
|
||||
export const API_URI = `http://${window.location.host}/api`;
|
||||
export const VIDEOS_API = `${API_URI}/videos`;
|
||||
|
|
@ -99,7 +101,7 @@ export function VideoCard({video}) {
|
|||
let poster_url = video.poster_path ? `/media/${encodeURIComponent(video.poster_path)}` : null;
|
||||
|
||||
return (
|
||||
<Card style={{'width': '18em', 'margin': '1em'}}>
|
||||
<Card>
|
||||
<Link to={video_url}>
|
||||
<Image src={poster_url} wrapped style={{position: 'relative', width: '100%'}}/>
|
||||
</Link>
|
||||
|
|
@ -107,7 +109,7 @@ export function VideoCard({video}) {
|
|||
<Card.Content>
|
||||
<Card.Header>
|
||||
<Container textAlign='left'>
|
||||
<Link to={video_url} className="no-link-underscore video-card-link">
|
||||
<Link to={video_url} className="no-link-underscore card-link">
|
||||
<p>{video.title || video.stem || video.video_path}</p>
|
||||
</Link>
|
||||
</Container>
|
||||
|
|
@ -115,7 +117,7 @@ export function VideoCard({video}) {
|
|||
<Card.Description>
|
||||
<Container textAlign='left'>
|
||||
{channel &&
|
||||
<Link to={channel_url} className="no-link-underscore video-card-link">
|
||||
<Link to={channel_url} className="no-link-underscore card-link">
|
||||
<b>{channel.name}</b>
|
||||
</Link>}
|
||||
<p>{upload_date}</p>
|
||||
|
|
@ -126,17 +128,14 @@ export function VideoCard({video}) {
|
|||
)
|
||||
}
|
||||
|
||||
export class VideoCards extends React.Component {
|
||||
|
||||
render() {
|
||||
return (
|
||||
<Card.Group>
|
||||
{this.props.videos.map((v) => {
|
||||
return <VideoCard key={v['id']} video={v}/>
|
||||
})}
|
||||
</Card.Group>
|
||||
)
|
||||
}
|
||||
export function VideoCards({videos}) {
|
||||
return (
|
||||
<Card.Group>
|
||||
{videos.map((v) => {
|
||||
return <VideoCard key={v['id']} video={v}/>
|
||||
})}
|
||||
</Card.Group>
|
||||
)
|
||||
}
|
||||
|
||||
export function RequiredAsterisk() {
|
||||
|
|
@ -490,3 +489,88 @@ export function objectToQuery(d) {
|
|||
arr = arr.filter((i) => i !== '')
|
||||
return arr.join('&');
|
||||
}
|
||||
|
||||
export function ClearButton({onClick, style, label, icon = 'close'}) {
|
||||
return <Button icon
|
||||
labelPosition='right'
|
||||
onClick={onClick}
|
||||
style={style}
|
||||
>
|
||||
{label}
|
||||
<Icon name={icon}/>
|
||||
</Button>
|
||||
}
|
||||
|
||||
export function SearchInput({initValue, onSubmit, size}) {
|
||||
let [value, setValue] = useState(initValue || '');
|
||||
size = size || 'small';
|
||||
|
||||
const buttonClick = () => {
|
||||
// Clear the input when the "clear" button is clicked, search again.
|
||||
setValue('');
|
||||
onSubmit(value);
|
||||
}
|
||||
|
||||
// Button is "search" when input is dirty, otherwise it is "clear".
|
||||
let button = (
|
||||
<Button icon onClick={buttonClick} style={{marginLeft: '0.5em'}} type='reset' size={size}>
|
||||
<Icon name='close'/>
|
||||
</Button>
|
||||
);
|
||||
if (!initValue || initValue !== value) {
|
||||
button = (
|
||||
<Button icon style={{marginLeft: '0.5em'}} type='submit' disabled={value === ''} size={size}>
|
||||
<Icon name='search'/>
|
||||
</Button>
|
||||
);
|
||||
}
|
||||
|
||||
const localOnSubmit = (e) => {
|
||||
// Send the value up when submitting.
|
||||
e.preventDefault();
|
||||
onSubmit(value);
|
||||
}
|
||||
|
||||
return (
|
||||
<Form onSubmit={localOnSubmit}>
|
||||
<Form.Group inline style={{marginBottom: '1em'}}>
|
||||
<Input
|
||||
type='text'
|
||||
placeholder='Search...'
|
||||
onChange={(e) => setValue(e.target.value)}
|
||||
value={value}
|
||||
size={size}
|
||||
/>
|
||||
{button}
|
||||
</Form.Group>
|
||||
</Form>
|
||||
)
|
||||
}
|
||||
|
||||
export function ExternalLink(props) {
|
||||
return (
|
||||
<Link to={props.to} target='_blank' className={props.className} rel='noopener noreferrer'>
|
||||
{props.children}
|
||||
</Link>
|
||||
)
|
||||
}
|
||||
|
||||
export function MoreButton(props) {
|
||||
return (
|
||||
<Grid columns={1} textAlign='center'>
|
||||
<Grid.Row>
|
||||
<Grid.Column>
|
||||
<Button
|
||||
onClick={props.onClick}
|
||||
size='big'
|
||||
style={{marginTop: '1em'}}
|
||||
disabled={props.disabled}
|
||||
>
|
||||
{props.children}
|
||||
More
|
||||
</Button>
|
||||
</Grid.Column>
|
||||
</Grid.Row>
|
||||
</Grid>
|
||||
)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -137,62 +137,16 @@ export class VideoWrapper extends React.Component {
|
|||
}
|
||||
}
|
||||
|
||||
class VideosPreview extends React.Component {
|
||||
constructor(props) {
|
||||
super(props);
|
||||
this.state = {
|
||||
videos: null,
|
||||
};
|
||||
export function VideosPreview({videos}) {
|
||||
let body = <VideoPlaceholder/>
|
||||
if (videos && videos.length === 0) {
|
||||
body = <p>No videos available.</p>
|
||||
} else if (videos && videos.length > 0) {
|
||||
body = <VideoCards videos={videos}/>
|
||||
}
|
||||
|
||||
async componentDidMount() {
|
||||
await this.fetchVideos();
|
||||
}
|
||||
|
||||
render() {
|
||||
let header = <h2>{this.title}</h2>;
|
||||
let body = <VideoPlaceholder/>
|
||||
if (this.state.videos && this.state.videos.length === 0) {
|
||||
body = <p>No videos available.</p>
|
||||
} else if (this.state.videos && this.state.videos.length > 0) {
|
||||
body = <VideoCards videos={this.state.videos}/>
|
||||
}
|
||||
return <>
|
||||
{header}
|
||||
{body}
|
||||
</>
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
export class FavoriteVideosPreview extends VideosPreview {
|
||||
|
||||
constructor(props) {
|
||||
super(props);
|
||||
this.title = 'Favorite Videos'
|
||||
}
|
||||
|
||||
async fetchVideos() {
|
||||
let [videos] = await searchVideos(
|
||||
0, 3, null, null, '-favorite', ['favorite']);
|
||||
this.setState({videos});
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
export class ViewedVideosPreview extends VideosPreview {
|
||||
|
||||
constructor(props) {
|
||||
super(props);
|
||||
this.title = 'Recently Viewed Videos'
|
||||
}
|
||||
|
||||
async fetchVideos() {
|
||||
let [videos] = await searchVideos(
|
||||
0, 3, null, null, '-viewed');
|
||||
this.setState({videos});
|
||||
}
|
||||
|
||||
return <>
|
||||
{body}
|
||||
</>
|
||||
}
|
||||
|
||||
function FilterModal(props) {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue