0
0
mirror of https://github.com/naturalcrit/homebrewery.git synced 2025-12-27 22:22:42 +00:00

basic functionality

This commit is contained in:
Víctor Losada Hernández
2024-01-22 23:52:42 +01:00
parent da699e999f
commit 66fd56fccb
3 changed files with 94 additions and 52 deletions

View File

@@ -3,7 +3,7 @@ const React = require('react');
const createClass = require('create-react-class');
const _ = require('lodash');
const cx = require('classnames');
const moment = require('moment');
const Moment = require('moment');
const Nav = require('naturalcrit/nav/nav.jsx');
const Navbar = require('../../navbar/navbar.jsx');
@@ -13,21 +13,19 @@ const Account = require('../../navbar/account.navitem.jsx');
const NewBrew = require('../../navbar/newbrew.navitem.jsx');
const HelpNavItem = require('../../navbar/help.navitem.jsx');
const NaturalCritIcon = require('naturalcrit/svg/naturalcrit.svg.jsx');
const request = require('superagent');
const ArchivePage = createClass({
displayName : 'ArchivePage',
getDefaultProps : function() {
return {
query : '',
foundBrew : null,
searching : false,
error : null
};
return {};
},
getInitialState : function() {
return {
uiItems : this.props.uiItems
query : '',
foundBrews : null,
searching : false,
error : null
};
},
handleChange(e){
@@ -36,35 +34,42 @@ const ArchivePage = createClass({
lookup(){
this.setState({ searching: true, error: null });
request.get(`/admin/lookup/${this.state.query}`)
.then((res)=>this.setState({ foundBrew: res.body }))
request.get(`/admin/archive/${this.state.query}`)
.then((res)=>this.setState({ foundBrews: res.body }))
.catch((err)=>this.setState({ error: err }))
.finally(()=>this.setState({ searching: false }));
},
renderFoundBrew(){
const brew = this.state.foundBrew;
return <div className='foundBrew'>
<dl>
<dt>Title</dt>
<dd>{brew.title}</dd>
<dt>Authors</dt>
<dd>{brew.authors.join(', ')}</dd>
<dt>Edit Link</dt>
<dd><a href={`/edit/${brew.editId}`} target='_blank' rel='noopener noreferrer'>/edit/{brew.editId}</a></dd>
<dt>Share Link</dt>
<dd><a href={`/share/${brew.shareId}`} target='_blank' rel='noopener noreferrer'>/share/{brew.shareId}</a></dd>
<dt>Last Updated</dt>
<dd>{Moment(brew.updatedAt).fromNow()}</dd>
<dt>Num of Views</dt>
<dd>{brew.views}</dd>
</dl>
</div>;
},
renderFoundBrews() {
const brews = this.state.foundBrews;
if (!brews || brews.length === 0) {
return <div>No brews found.</div>;
}
return (
<div className='foundBrews'>
{brews.map((brew, index) => (
<div key={index} className='brewItem'>
<dl>
<dt>Title:</dt>
<dd>{brew.title}</dd>
<dt>Authors:</dt>
<dd>{brew.authors.join(', ')}</dd>
<a href={`/share/${brew.shareId}`}>Check the brew</a>
<dt>Last Updated</dt>
<dd>{Moment(brew.updatedAt).fromNow()}</dd>
<dt>Num of Views</dt>
<dd>{brew.views}</dd>
</dl>
</div>
))}
</div>
);
},
renderForm: function() {
return <div className='brewLookup'>
@@ -79,15 +84,6 @@ const ArchivePage = createClass({
'fa-spin fa-spinner' : this.state.searching,
})} />
</button>
{this.state.error
&& <div className='error'>{this.state.error.toString()}</div>
}
{this.state.foundBrew
? this.renderFoundBrew()
: <div className='noBrew'>No brew found.</div>
}
</div>;
},
@@ -121,8 +117,9 @@ const ArchivePage = createClass({
<div className='resultsContainer dataGroup'>
<div className='title'>
<h2>Your results, my lordship</h2>
{this.renderResults()}
</div>
{this.renderFoundBrews()}
</div>
</div>
</div>

View File

@@ -1,5 +1,3 @@
.archivePage {
height:100%;
background-color: #2C3E50;
@@ -8,10 +6,13 @@
grid-template-rows: 20vh 1fr;
.welcome {
display:grid;
place-items: center;
background: url('https://i.imgur.com/MJ4YHu7.jpg');
background-size:100%;
background-position:center;
height:20vh;
border-bottom:5px solid #333;
h1 {
font-size:40px;
@@ -32,10 +33,10 @@
background:white;
&.form .brewLookup {
padding:100px;
padding:50px;
h2 {
font-size:20px;
font-size:30px;
font-weight: 900;
border-bottom:2px solid;
margin-block: 20px;
@@ -62,13 +63,38 @@
place-items: center;
h2 {
font-size:20px;
font-size:30px;
color:white;
font-weight:900;
}
}
.foundBrews {
display:flex;
flex-direction: column;
width:100%;
.brewItem {
width:200px;
dt {
font-size:20px;
font-weight:900;
}
}
}
}
}
}
}
}
}

View File

@@ -78,7 +78,26 @@ router.get('/admin/lookup/:id', mw.adminOnly, async (req, res, next) => {
});
/* Searches for matching title, also attempts to partial match */
router.get('/admin/archive/:title', mw.adminOnly, async (req, res, next) => {
try {
const brews = await HomebrewModel.find({
title: { $regex: req.params.title, $options: 'i' },
published: true
}).exec();
if (!brews || brews.length === 0) {
// No published documents found with the given title
return res.status(404).json({ error: 'Published documents not found' });
}
return res.json(brews);
} catch (error) {
console.error(error);
return res.status(500).json({ error: 'Internal Server Error' });
}
});
/* Find 50 brews that aren't compressed yet */
router.get('/admin/finduncompressed', mw.adminOnly, (req, res)=>{