import React, { useState } from 'react'; import request from 'superagent'; import Moment from 'moment'; const BrewCleanup = ({})=>{ const [junkBrewCollection, setJunkBrewCollection] = useState([]); const [lostBrewCollection, setLostBrewCollection] = useState([]); const [pending, setPending] = useState(false); const [error, setError] = useState(null); const find = async (type)=>{ setPending(true); if(type === 'junk') try { const res = await request.get('/admin/cleanupJunk'); setJunkBrewCollection(res.body.brewCollection); } catch (err) { setError(err); } finally { setPending(false); } if(type === 'lost') try { const res = await request.get('/admin/cleanupLost'); setLostBrewCollection(res.body.brewCollection); } catch (err) { setError(err); } finally { setPending(false); } }; const cleanup = async (type)=>{ setPending(true); if(type === 'junk') try { console.log('deleting junk') const res = await request.post('/admin/cleanupJunk'); } catch (err) { setError(err); } finally { setPending(false); setJunkBrewCollection([]); } if(type === 'lost') try { const res = await request.post('/admin/cleanupLost'); } catch (err) { setError(err); } finally { setPending(false); setLostBrewCollection([]); } }; const renderBrewList = (type)=>{ const brewList = type === 'lost' ? lostBrewCollection : junkBrewCollection; if(!brewList || brewList.length === 0) { console.log(brewList); return null; } return <>
| Title | Last Update | last viewed | Storage |
|---|---|---|---|
| {brew.title || 'No Title'} | {Moment(brew.updatedAt).fromNow()} | {brew.lastViewed ? Moment(brew.lastViewed).fromNow() : 'No last viewed date'} | {brew.googleId ? 'Google' : 'Homebrewery'} |
Removes very short brews to tidy up the database
{renderFound('junk')} {error &&Removes very short brews to tidy up the database
{renderFound('lost')} {error &&