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, searchURLs} 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"; function FailedUrlCard({url, syncURL, deleteURL}) { let syncIcon = ( ); let trashIcon = ( ); let externalIcon = ( ); return ( {url.url}

Failed!

{syncIcon} {trashIcon} {externalIcon}
); } class URLCard extends React.Component { constructor(props) { super(props); this.state = { latest: props.url ? props.url.latest : null, deleteOpen: false, syncOpen: false, } } syncURL = async () => { await postArchive(this.props.url.url); await this.props.fetchURLs(); } deleteURL = async () => { await deleteArchive(this.props.url.id); await this.props.fetchURLs(); } render() { let url = this.props.url; let latest = url && url.latest ? url.latest : null; let imageSrc = latest.screenshot_path ? `/media/${latest.screenshot_path}` : null; let singlefileUrl = latest.singlefile_path ? `/media/${latest.singlefile_path}` : null; if (latest == null || latest.status === 'failed') { return ; } let readabilityUrl = latest.readability_path ? `/media/${latest.readability_path}` : null; let readabilityIcon = ; if (readabilityUrl) { readabilityIcon = ( ); } let syncIcon = ( <> this.setState({syncOpen: false})} onConfirm={this.syncURL} /> ); let deleteIcon = ( <> this.setState({deleteOpen: false})} onConfirm={this.deleteURL} /> ) ; let externalIcon = ( ); return (

{url.latest.title || url.url}

{uploadDate(latest.archive_datetime)} {readabilityIcon} {syncIcon} {deleteIcon} {externalIcon}
) } } class URLCards extends React.Component { render() { return ( {this.props.urls.map((i) => { return })} ) } } class Archives extends React.Component { 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, urls: null, totalPages: null, domain: domain, }; this.fetchURLs = this.fetchURLs.bind(this); this.clearSearch = this.clearSearch.bind(this); this.changePage = this.changePage.bind(this); } async componentDidMount() { await this.fetchURLs(); } async componentDidUpdate(prevProps, prevState, snapshot) { if (prevProps.location.search !== this.props.location.search) { await this.fetchURLs(); } } async fetchURLs() { this.setState({urls: null}); let offset = this.state.limit * this.state.activePage - this.state.limit; let [urls, total] = await searchURLs(offset, this.state.limit, this.state.domain); let totalPages = Math.round(total / this.state.limit) || 1; this.setState({urls, 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 {urls, activePage, totalPages} = this.state; if (urls === null) { return (<>
Latest Archives
) } let pagination = null; if (totalPages) { pagination = (
) } let domainButton = null; if (this.state.domain) { domainButton = ( ) } return ( <>
Latest Archives
{domainButton} {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 {domain['domain']} {domain['url_count']} } render() { if (this.state.domains) { return ( <>
Domains
Domain URLs {this.state.domains.map(this.row)}
) } return (<>
Domains
) } } 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(); await postArchive(this.state.inputs.url); this.setState({inputs: {url: ''}}, this.fetchURLs); } fetchURLs = async (e) => { await this.archivesRef.current.fetchURLs(); } render() { return ( <>
Archive
) } } class ManageArchives extends React.Component { async refresh() { await refreshArchives(); } render() { return (<> ) } } export class ArchiveRoute extends React.Component { constructor(props) { super(props); this.panesTos = ['/archive', '/archive/domains', '/archive/manage']; this.state = { activeIndex: this.matchPaneTo(), } this.archivesRef = React.createRef(); } componentDidUpdate(prevProps, prevState, snapshot) { if (prevProps.location.pathname !== this.props.location.pathname) { this.setState({activeIndex: this.matchPaneTo()}); } } matchPaneTo = () => { return this.panesTos.indexOf(this.props.location.pathname); } render() { const panes = [ { menuItem: { as: NavLink, content: 'Archives', id: 'archive', to: '/archive', exact: true, key: 'home', }, render: () => }, { menuItem: { as: NavLink, content: 'Domains', id: 'domains', to: '/archive/domains', exact: true, key: 'domains', }, render: () => }, { menuItem: { as: NavLink, content: 'Manage', id: 'manage', to: '/archive/manage', exact: true, key: 'manage', }, render: () => }, ]; return ( ) } }