diff --git a/client/admin/brewUtils/brewCleanup/brewCleanup.jsx b/client/admin/brewUtils/brewCleanup/brewCleanup.jsx index e2acb2a9d..7d6c34f55 100644 --- a/client/admin/brewUtils/brewCleanup/brewCleanup.jsx +++ b/client/admin/brewUtils/brewCleanup/brewCleanup.jsx @@ -5,71 +5,89 @@ import Moment from 'moment'; const BrewCleanup = ({})=>{ const [junkBrewCollection, setJunkBrewCollection] = useState([]); const [lostBrewCollection, setLostBrewCollection] = useState([]); - const [pending, setPending] = useState(false); + const [pendingJunk, setPendingJunk] = useState(false); + const [pendingLost, setPendingLost] = useState(false); const [error, setError] = useState(null); const find = async (type)=>{ - setPending(true); + if(type === 'junk') try { + setPendingJunk(true); const res = await request.get('/admin/cleanupJunk'); setJunkBrewCollection(res.body.brewCollection); } catch (err) { setError(err); } finally { - setPending(false); + setPendingJunk(false); } if(type === 'lost') try { - + setPendingLost(true); const res = await request.get('/admin/cleanupLost'); setLostBrewCollection(res.body.brewCollection); } catch (err) { setError(err); } finally { - setPending(false); + setPendingLost(false); } }; const cleanup = async (type)=>{ - setPending(true); if(type === 'junk') try { - console.log('deleting junk') + setPendingJunk(true); + console.log('deleting junk'); const res = await request.post('/admin/cleanupJunk'); } catch (err) { setError(err); } finally { - setPending(false); + setPendingJunk(false); setJunkBrewCollection([]); } if(type === 'lost') try { + setPendingLost(true); const res = await request.post('/admin/cleanupLost'); } catch (err) { setError(err); } finally { - setPending(false); + setPendingLost(false); setLostBrewCollection([]); } }; const renderBrewList = (type)=>{ - const brewList = type === 'lost' ? lostBrewCollection : junkBrewCollection; if(!brewList || brewList.length === 0) { - console.log(brewList); - return null; + return <> +

{`Results - No brews found` }

+ + + + + + + + + + + + + + +
TitleLast Updatelast viewedStorage
"No brews found"
+ ; } - - + console.log(type); + console.log(brewList); return <> -

{`Results - ${brewList.length} brews` }

+

{`Results - ${brewList.length} brews` }

@@ -91,35 +109,33 @@ const BrewCleanup = ({})=>{ - ; + })}
{Moment(brew.updatedAt).fromNow()} {brew.lastViewed ? Moment(brew.lastViewed).fromNow() : 'No last viewed date'} {brew.googleId ? 'Google' : 'Homebrewery'}
; }; const renderFound = (type)=>{ - - if(type === 'junk' && junkBrewCollection.length === 0 || type === 'lost' && lostBrewCollection.length === 0) return
No Matching Brews found.
; + const deleteButton = !(type === 'junk' && junkBrewCollection.length === 0 || type === 'lost' && lostBrewCollection.length === 0); return
- - - Found {type === 'junk' ? junkBrewCollection.length : lostBrewCollection.length} Brews that could be removed. + } {renderBrewList(type)}
; }; const renderJunkBrewCleanup = ()=>{ return

Junk brews

-

Removes very short brews to tidy up the database

+

Queries unauthored brews that have not been viewed or
updated in 30 days and are shorter than 140 bytes (up to 300)