import { Box, Typography } from '@material-ui/core' import { ReactElement, useContext, useState } from 'react' import { Download, Info, PlusSquare, Trash } from 'react-feather' import { useHistory } from 'react-router' import ExpandableList from '../../components/ExpandableList' import ExpandableListItem from '../../components/ExpandableListItem' import ExpandableListItemActions from '../../components/ExpandableListItemActions' import ExpandableListItemKey from '../../components/ExpandableListItemKey' import { SwarmButton } from '../../components/SwarmButton' import { Context as BeeContext } from '../../providers/Bee' import { Context as IdentityContext, Identity } from '../../providers/Feeds' import { ROUTES } from '../../routes' import { formatEnum } from '../../utils' import { persistIdentitiesWithoutUpdate } from '../../utils/identity' import { DeleteFeedDialog } from './DeleteFeedDialog' import { ExportFeedDialog } from './ExportFeedDialog' import { ImportFeedDialog } from './ImportFeedDialog' export default function Feeds(): ReactElement { const { identities, setIdentities } = useContext(IdentityContext) const { status } = useContext(BeeContext) const history = useHistory() const [selectedIdentity, setSelectedIdentity] = useState(null) const [showImport, setShowImport] = useState(false) const [showExport, setShowExport] = useState(false) const [showDelete, setShowDelete] = useState(false) function createNewFeed() { return history.push(ROUTES.FEEDS_NEW) } function viewFeed(uuid: string) { history.push(ROUTES.FEEDS_PAGE.replace(':uuid', uuid)) } function onDialogClose() { setShowDelete(false) setShowExport(false) setShowImport(false) setSelectedIdentity(null) } function onDelete(identity: Identity) { onDialogClose() const updatedFeeds = identities.filter(x => x.uuid !== identity.uuid) setIdentities(updatedFeeds) persistIdentitiesWithoutUpdate(updatedFeeds) } function onShowExport(identity: Identity) { setSelectedIdentity(identity) setShowExport(true) } function onShowDelete(identity: Identity) { setSelectedIdentity(identity) setShowDelete(true) } return (
{showImport && setShowImport(false)} />} {showExport && selectedIdentity && } {showDelete && selectedIdentity && ( onDelete(identity)} /> )} Feeds Create New Feed setShowImport(true)}> Import Feed {identities.map((x, i) => ( {x.feedHash && } {status.all && ( viewFeed(x.uuid)} iconType={Info}> View Feed Page )} onShowExport(x)} iconType={Download}> Export... onShowDelete(x)} iconType={Trash}> Delete... ))}
) }