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

Failed!

{syncIcon} {trashIcon} {externalIcon}
); } class ArchiveCard extends React.Component { constructor(props) { super(props); this.state = { deleteOpen: false, syncOpen: false, } } syncURL = async () => { await postArchive(this.props.archive.url.url); await this.props.fetchURLs(); } deleteURL = async () => { await deleteArchive(this.props.archive.id); await this.props.fetchURLs(); } render() { let archive = this.props.archive; 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 ; } let readabilityUrl = archive.readability_path ? `/media/${archive.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 (

{archive.title || archive.url}

{uploadDate(archive.archive_datetime)} {readabilityIcon} {syncIcon} {deleteIcon} {externalIcon}
) } } class ArchiveCards extends React.Component { render() { return ( {this.props.archives.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, archives: 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({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 (<>
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(); 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 ( <>
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 ( ) } }