0
0
mirror of https://github.com/naturalcrit/homebrewery.git synced 2026-06-22 00:38:38 +00:00

proper cleaning function

This commit is contained in:
Víctor Losada Hernández
2026-05-27 22:43:57 +02:00
parent fff0b4d670
commit e7680ef80b
2 changed files with 50 additions and 8 deletions
@@ -1,8 +1,10 @@
import React, { useState } from 'react';
import request from 'superagent';
import Moment from 'moment';
const BrewCleanup = ({})=>{
const [count, setCount] = useState(0);
const [brewCollection, setBrewCollection] = useState([]);
const [pending, setPending] = useState(false);
const [primed, setPrimed] = useState(false);
const [error, setError] = useState(null);
@@ -14,6 +16,7 @@ const BrewCleanup = ({})=>{
const res = await request.get('/admin/cleanup');
setCount(res.body.count);
setBrewCollection(res.body.brewCollection);
setPrimed(true);
} catch (err) {
setError(err);
@@ -36,6 +39,43 @@ const BrewCleanup = ({})=>{
setPrimed(false);
}
};
const renderBrewList = ()=>{
if(!brewCollection) {
console.log(brewCollection)
return null;
}
return <>
<h2>{`Results - ${brewCollection.length} brews` }</h2>
<table className='resultsTable'>
<thead>
<tr>
<th>Title</th>
<th>Share</th>
<th>Last Update</th>
<th>Created</th>
<th>Storage</th>
</tr>
</thead>
<tbody>
{brewCollection
.sort((a, b)=>{ // Sort brews from most recently updated
if(a.updatedAt > b.updatedAt) return -1;
return 1;
})
.map((brew, idx)=>{
return <tr key={idx}>
<td><strong>{brew.title || 'No Title'}</strong></td>
<td><a href={`/share/${brew.shareId}`}>{brew.shareId}</a></td>
<td style={{ width: '200px' }}>{Moment(brew.updatedAt).fromNow()}</td>
<td>{brew.createdAt ? Moment(brew.createdAt).fromNow() : 'No creation date'}</td>
<td>{brew.googleId ? 'Google' : 'Homebrewery'}</td>
</tr>;
})}
</tbody>
</table>
</>;
};
const renderPrimed = ()=>{
if(!primed) return;
@@ -49,6 +89,7 @@ const BrewCleanup = ({})=>{
}
</button>
<span>Found {count} Brews that could be removed. </span>
{renderBrewList()}
</div>;
};