diff --git a/client/homebrew/pages/archivePage/archivePage.jsx b/client/homebrew/pages/archivePage/archivePage.jsx index 29243eeb9..31c04c5b4 100644 --- a/client/homebrew/pages/archivePage/archivePage.jsx +++ b/client/homebrew/pages/archivePage/archivePage.jsx @@ -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
-
-
Title
-
{brew.title}
- -
Authors
-
{brew.authors.join(', ')}
- -
Edit Link
-
/edit/{brew.editId}
- -
Share Link
-
/share/{brew.shareId}
- -
Last Updated
-
{Moment(brew.updatedAt).fromNow()}
- -
Num of Views
-
{brew.views}
-
-
; - }, + renderFoundBrews() { + const brews = this.state.foundBrews; + + if (!brews || brews.length === 0) { + return
No brews found.
; + } + + return ( +
+ {brews.map((brew, index) => ( +
+
+
Title:
+
{brew.title}
+ +
Authors:
+
{brew.authors.join(', ')}
+ + Check the brew + +
Last Updated
+
{Moment(brew.updatedAt).fromNow()}
+ +
Num of Views
+
{brew.views}
+
+
+ ))} +
+ ); + }, renderForm: function() { return
@@ -79,15 +84,6 @@ const ArchivePage = createClass({ 'fa-spin fa-spinner' : this.state.searching, })} /> - - {this.state.error - &&
{this.state.error.toString()}
- } - - {this.state.foundBrew - ? this.renderFoundBrew() - :
No brew found.
- }
; }, @@ -121,8 +117,9 @@ const ArchivePage = createClass({

Your results, my lordship

- {this.renderResults()} +
+ {this.renderFoundBrews()}
diff --git a/client/homebrew/pages/archivePage/archivePage.less b/client/homebrew/pages/archivePage/archivePage.less index 50ddf4de1..d9d069789 100644 --- a/client/homebrew/pages/archivePage/archivePage.less +++ b/client/homebrew/pages/archivePage/archivePage.less @@ -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; + } + } + } } } } } -} \ No newline at end of file +} + + + + + + + + + + diff --git a/server/admin.api.js b/server/admin.api.js index c0615de1b..0c6fe1fc7 100644 --- a/server/admin.api.js +++ b/server/admin.api.js @@ -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)=>{