mirror of
https://github.com/naturalcrit/homebrewery.git
synced 2026-01-23 16:33:05 +00:00
Compare commits
43 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
eeec24ae78 | ||
|
|
1d778e3249 | ||
|
|
3bb44d8a17 | ||
|
|
71c52b4587 | ||
|
|
fe449abb47 | ||
|
|
46d1f89b77 | ||
|
|
bf1f2054de | ||
|
|
399caaaeff | ||
|
|
27b4176e23 | ||
|
|
a8bc6b4e1d | ||
|
|
3ca8f72762 | ||
|
|
8aec5dbba6 | ||
|
|
cccebd8494 | ||
|
|
5fbbd92ea7 | ||
|
|
81f26e0892 | ||
|
|
9366284e1d | ||
|
|
9aa5eea8c9 | ||
|
|
20f61bff07 | ||
|
|
625819da91 | ||
|
|
2c691d84f2 | ||
|
|
4630d2640b | ||
|
|
043f24d5ca | ||
|
|
87e18c0521 | ||
|
|
7e30f860b2 | ||
|
|
0ac0ffe53d | ||
|
|
ae4e1b55e6 | ||
|
|
756ced088c | ||
|
|
8ce6b22be7 | ||
|
|
6184d64f89 | ||
|
|
c00c2626b4 | ||
|
|
89fddd0210 | ||
|
|
0c167d803c | ||
|
|
c50042c1e7 | ||
|
|
0dc1b46466 | ||
|
|
4ed9fc7d0e | ||
|
|
162929bdca | ||
|
|
54a2f6940c | ||
|
|
0dff59d793 | ||
|
|
7951c4a03a | ||
|
|
66fd56fccb | ||
|
|
da699e999f | ||
|
|
c6a5f50c76 | ||
|
|
74c7395ab9 |
@@ -34,6 +34,8 @@ const Stats = createClass({
|
||||
<dl>
|
||||
<dt>Total Brew Count</dt>
|
||||
<dd>{this.state.stats.totalBrews}</dd>
|
||||
<dt>Total Brews Published Count</dt>
|
||||
<dd>{this.state.stats.totalPublishedBrews || 'no published brews'}</dd>
|
||||
</dl>
|
||||
|
||||
{this.state.fetching
|
||||
|
||||
@@ -11,6 +11,7 @@ const SharePage = require('./pages/sharePage/sharePage.jsx');
|
||||
const NewPage = require('./pages/newPage/newPage.jsx');
|
||||
const ErrorPage = require('./pages/errorPage/errorPage.jsx');
|
||||
const PrintPage = require('./pages/printPage/printPage.jsx');
|
||||
const ArchivePage = require('./pages/archivePage/archivePage.jsx');
|
||||
const AccountPage = require('./pages/accountPage/accountPage.jsx');
|
||||
|
||||
const WithRoute = (props)=>{
|
||||
@@ -74,6 +75,7 @@ const Homebrew = createClass({
|
||||
<Route path='/user/:username' element={<WithRoute el={UserPage} brews={this.props.brews} />} />
|
||||
<Route path='/print/:id' element={<WithRoute el={PrintPage} brew={this.props.brew} />} />
|
||||
<Route path='/print' element={<WithRoute el={PrintPage} />} />
|
||||
<Route path='/archive' element={<WithRoute el={ArchivePage}/>}/>
|
||||
<Route path='/changelog' element={<WithRoute el={SharePage} brew={this.props.brew} />} />
|
||||
<Route path='/faq' element={<WithRoute el={SharePage} brew={this.props.brew} />} />
|
||||
<Route path='/account' element={<WithRoute el={AccountPage} brew={this.props.brew} uiItems={this.props.brew.uiItems} />} />
|
||||
|
||||
201
client/homebrew/pages/archivePage/archivePage.jsx
Normal file
201
client/homebrew/pages/archivePage/archivePage.jsx
Normal file
@@ -0,0 +1,201 @@
|
||||
require('./archivePage.less');
|
||||
|
||||
const React = require('react');
|
||||
const createClass = require('create-react-class');
|
||||
const _ = require('lodash');
|
||||
const cx = require('classnames');
|
||||
|
||||
const Nav = require('naturalcrit/nav/nav.jsx');
|
||||
const Navbar = require('../../navbar/navbar.jsx');
|
||||
const RecentNavItem = require('../../navbar/recent.navitem.jsx').both;
|
||||
const Account = require('../../navbar/account.navitem.jsx');
|
||||
const NewBrew = require('../../navbar/newbrew.navitem.jsx');
|
||||
const HelpNavItem = require('../../navbar/help.navitem.jsx');
|
||||
const BrewItem = require('../basePages/listPage/brewItem/brewItem.jsx');
|
||||
|
||||
const request = require('../../utils/request-middleware.js');
|
||||
|
||||
const ArchivePage = createClass({
|
||||
displayName : 'ArchivePage',
|
||||
getDefaultProps : function () {
|
||||
return {};
|
||||
},
|
||||
getInitialState : function () {
|
||||
return {
|
||||
title : this.props.query.title || '',
|
||||
brewCollection : null,
|
||||
page : 1,
|
||||
totalPages : 1,
|
||||
searching : false,
|
||||
error : null,
|
||||
};
|
||||
},
|
||||
componentDidMount : function() {
|
||||
|
||||
},
|
||||
handleChange(e) {
|
||||
this.setState({ title: e.target.value });
|
||||
},
|
||||
|
||||
updateStateWithBrews : function (brews, page, totalPages) {
|
||||
this.setState({
|
||||
brewCollection : brews || null,
|
||||
page : page || 1,
|
||||
totalPages : totalPages || 1,
|
||||
searching : false
|
||||
});
|
||||
},
|
||||
|
||||
loadPage : async function(page) {
|
||||
if(this.state.title == '') {} else {
|
||||
|
||||
try {
|
||||
//this.updateUrl();
|
||||
this.setState({ searching: true, error: null });
|
||||
const title = encodeURIComponent(this.state.title);
|
||||
await request.get(`/api/archive?title=${title}&page=${page}`)
|
||||
.then((response)=>{
|
||||
if(response.ok) {
|
||||
this.updateStateWithBrews(response.body.brews, page, response.body.totalPages);
|
||||
}
|
||||
});
|
||||
} catch (error) {
|
||||
console.log(`LoadPage error: ${error}`);
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
updateUrl : function() {
|
||||
const url = new URL(window.location.href);
|
||||
const urlParams = new URLSearchParams(url.search);
|
||||
|
||||
// Set the title and page parameters
|
||||
urlParams.set('title', this.state.title);
|
||||
urlParams.set('page', this.state.page);
|
||||
|
||||
url.search = urlParams.toString(); // Convert URLSearchParams to string
|
||||
window.history.replaceState(null, null, url);
|
||||
},
|
||||
|
||||
renderFoundBrews() {
|
||||
const { title, brewCollection, page, totalPages, error } = this.state;
|
||||
|
||||
if(title === '') {return (<div className='foundBrews noBrews'><h3>Whenever you want, just start typing...</h3></div>);}
|
||||
|
||||
if(error !== null) {
|
||||
return (
|
||||
<div className='foundBrews noBrews'>
|
||||
<div><h3>I'm sorry, your request didn't work</h3>
|
||||
<br /><p>Your search is not specific enough. Too many brews meet this criteria for us to display them.</p>
|
||||
</div></div>
|
||||
);
|
||||
}
|
||||
|
||||
if(!brewCollection || brewCollection.length === 0) {
|
||||
return (
|
||||
<div className='foundBrews noBrews'>
|
||||
<h3>We haven't found brews meeting your request.</h3>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
return (
|
||||
<div className='foundBrews'>
|
||||
<span className='brewCount'>{`Brews Found: ${brewCollection.length}`}</span>
|
||||
|
||||
{brewCollection.map((brew, index)=>(
|
||||
<BrewItem brew={brew} key={index} reportError={this.props.reportError} />
|
||||
))}
|
||||
<div className='paginationControls'>
|
||||
{page > 1 && (
|
||||
<button onClick={()=>this.loadPage(page - 1)}>Previous Page</button>
|
||||
)}
|
||||
<span className='currentPage'>Page {page}</span>
|
||||
{page < totalPages && (
|
||||
<button onClick={()=>this.loadPage(page + 1)}>Next Page</button>
|
||||
)}
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
},
|
||||
|
||||
|
||||
renderForm : function () {
|
||||
return (
|
||||
<div className='brewLookup'>
|
||||
<h2>Brew Lookup</h2>
|
||||
<label>Title of the brew</label>
|
||||
<input
|
||||
type='text'
|
||||
value={this.state.title}
|
||||
onChange={this.handleChange}
|
||||
onKeyDown={(e)=>{
|
||||
if(e.key === 'Enter') {
|
||||
this.handleChange(e);
|
||||
this.loadPage(1);
|
||||
}
|
||||
}}
|
||||
placeholder='v3 Reference Document'
|
||||
/>
|
||||
{/* In the future, we should be able to filter the results by adding tags.
|
||||
<label>Tags</label><input type='text' value={this.state.query} placeholder='add a tag to filter'/>
|
||||
<input type="checkbox" id="v3" /><label>v3 only</label>
|
||||
*/}
|
||||
|
||||
<button onClick={()=>{ this.handleChange({ target: { value: this.state.title } }); this.loadPage(1); }}>
|
||||
<i
|
||||
className={cx('fas', {
|
||||
'fa-search' : !this.state.searching,
|
||||
'fa-spin fa-spinner' : this.state.searching,
|
||||
})}
|
||||
/>
|
||||
</button>
|
||||
</div>
|
||||
);
|
||||
},
|
||||
|
||||
|
||||
|
||||
renderNavItems : function () {
|
||||
return (
|
||||
<Navbar>
|
||||
<Nav.section>
|
||||
<Nav.item className='brewTitle'>Archive: Search for brews</Nav.item>
|
||||
</Nav.section>
|
||||
<Nav.section>
|
||||
<NewBrew />
|
||||
<HelpNavItem />
|
||||
<RecentNavItem />
|
||||
<Account />
|
||||
</Nav.section>
|
||||
</Navbar>
|
||||
);
|
||||
},
|
||||
|
||||
render : function () {
|
||||
return (
|
||||
<div className='archivePage'>
|
||||
<link href='/themes/V3/Blank/style.css' rel='stylesheet'/>
|
||||
<link href='/themes/V3/5ePHB/style.css' rel='stylesheet'/>
|
||||
{this.renderNavItems()}
|
||||
|
||||
<div className='content'>
|
||||
<div className='welcome'>
|
||||
<h1>Welcome to the Archive</h1>
|
||||
</div>
|
||||
<div className='flexGroup'>
|
||||
<div className='form dataGroup'>{this.renderForm()}</div>
|
||||
<div className='resultsContainer dataGroup'>
|
||||
<div className='title'>
|
||||
<h2>Your results, my lordship</h2>
|
||||
</div>
|
||||
{this.renderFoundBrews()}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
},
|
||||
});
|
||||
|
||||
module.exports = ArchivePage;
|
||||
173
client/homebrew/pages/archivePage/archivePage.less
Normal file
173
client/homebrew/pages/archivePage/archivePage.less
Normal file
@@ -0,0 +1,173 @@
|
||||
body {
|
||||
height: 100vh;
|
||||
|
||||
.content {
|
||||
height: 100%;
|
||||
}
|
||||
}
|
||||
|
||||
.archivePage {
|
||||
overflow-y: hidden;
|
||||
height: 100%;
|
||||
background-color: #2C3E50;
|
||||
|
||||
h1,h2,h3 {
|
||||
font-family: 'Open Sans';
|
||||
color: white;
|
||||
font-weight: 900;
|
||||
}
|
||||
|
||||
.content {
|
||||
display: grid;
|
||||
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;
|
||||
filter:drop-shadow(0 0 5px black);
|
||||
}
|
||||
}
|
||||
|
||||
.flexGroup {
|
||||
height: 100%;
|
||||
display: grid;
|
||||
grid-template-columns: 500px 2fr;
|
||||
background: #2C3E50;
|
||||
|
||||
.dataGroup {
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
background: white;
|
||||
|
||||
&.form .brewLookup {
|
||||
padding: 50px;
|
||||
|
||||
h2 {
|
||||
font-size: 30px;
|
||||
border-bottom: 2px solid;
|
||||
margin-block: 20px;
|
||||
}
|
||||
|
||||
label {
|
||||
margin-right: 10px;
|
||||
}
|
||||
|
||||
input+button {
|
||||
margin-left: 20px;
|
||||
}
|
||||
}
|
||||
|
||||
&.resultsContainer {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
border-left: 2px solid;
|
||||
height: 100%;
|
||||
font-family: "BookInsanityRemake";
|
||||
font-size: .34cm;
|
||||
|
||||
.title {
|
||||
height: 10vh;
|
||||
background-color: #333;
|
||||
display: grid;
|
||||
place-items: center;
|
||||
|
||||
h2 {
|
||||
font-size: 30px;
|
||||
}
|
||||
}
|
||||
.foundBrews {
|
||||
position: relative;
|
||||
background-color: #2C3E50;
|
||||
width: 100%;
|
||||
max-height: 100%;
|
||||
height: 66.7vh;
|
||||
padding: 50px;
|
||||
overflow-y:scroll;
|
||||
|
||||
h3 {
|
||||
font-size: 25px;
|
||||
}
|
||||
|
||||
&.noBrews {
|
||||
display:grid;
|
||||
place-items:center;
|
||||
}
|
||||
|
||||
.brewCount {
|
||||
position: fixed;
|
||||
bottom: 0;
|
||||
right: 17px;
|
||||
font-size: 11px;
|
||||
font-weight: 800;
|
||||
color: white;
|
||||
background-color: #333;
|
||||
padding: 8px 10px;
|
||||
z-index: 1000;
|
||||
font-family: 'Open Sans';
|
||||
|
||||
&:empty {
|
||||
display: none;
|
||||
}
|
||||
}
|
||||
|
||||
.limit {
|
||||
position: fixed;
|
||||
bottom: 0;
|
||||
left: 502px;
|
||||
font-size: 11px;
|
||||
font-weight: 800;
|
||||
color: white;
|
||||
background-color: #333;
|
||||
padding: 8px 10px;
|
||||
z-index: 1000;
|
||||
font-family: 'Open Sans';
|
||||
|
||||
&:empty {
|
||||
display: none;
|
||||
}
|
||||
}
|
||||
.brewItem {
|
||||
background-image: url('/assets/parchmentBackground.jpg');
|
||||
width: 48%;
|
||||
margin-right: 40px;
|
||||
color: black;
|
||||
|
||||
&:nth-child(even) {
|
||||
margin-right: 0;
|
||||
}
|
||||
h2 {
|
||||
font-size: 0.75cm;
|
||||
line-height: 0.988em;
|
||||
font-family: "MrEavesRemake";
|
||||
font-weight: 800;
|
||||
color: var(--HB_Color_HeaderText);
|
||||
}
|
||||
|
||||
.info {
|
||||
font-family: ScalySansRemake;
|
||||
font-size: 1.2em;
|
||||
|
||||
>span {
|
||||
margin-right: 12px;
|
||||
line-height: 1.5em;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
hr {
|
||||
visibility: hidden;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -111,6 +111,8 @@ const BrewItem = createClass({
|
||||
brew.tags = brew.tags?.filter((tag)=>tag); //remove tags that are empty strings
|
||||
}
|
||||
const dateFormatString = 'YYYY-MM-DD HH:mm:ss';
|
||||
const authors = brew.authors.length > 0 ? brew.authors : 'No authors';
|
||||
|
||||
|
||||
return <div className='brewItem'>
|
||||
{brew.thumbnail &&
|
||||
@@ -135,7 +137,18 @@ const BrewItem = createClass({
|
||||
</> : <></>
|
||||
}
|
||||
<span title={`Authors:\n${brew.authors?.join('\n')}`}>
|
||||
<i className='fas fa-user'/> {brew.authors.map((item) => <a href={`/user/${item}`}>{item}</a>)}
|
||||
<i className='fas fa-user'/> {Array.isArray(authors) ? (
|
||||
<span>
|
||||
{authors.map((author, index) => (
|
||||
<span key={index}>
|
||||
<a href={`/share/${author}`}>{author}</a>
|
||||
{index < authors.length - 1 && ', '}
|
||||
</span>
|
||||
))}
|
||||
</span>
|
||||
) : (
|
||||
<span>{authors}</span>
|
||||
)}
|
||||
</span>
|
||||
<br />
|
||||
<span title={`Last viewed: ${moment(brew.lastViewed).local().format(dateFormatString)}`}>
|
||||
|
||||
@@ -84,7 +84,7 @@ router.get('/admin/lookup/:id', mw.adminOnly, async (req, res, next)=>{
|
||||
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)=>{
|
||||
const query = uncompressedBrewQuery.clone();
|
||||
|
||||
@@ -67,6 +67,7 @@ app.use((req, res, next)=>{
|
||||
|
||||
app.use(homebrewApi);
|
||||
app.use(require('./admin.api.js'));
|
||||
app.use(require('./archive.api.js'));
|
||||
|
||||
const HomebrewModel = require('./homebrew.model.js').model;
|
||||
const welcomeText = require('fs').readFileSync('client/homebrew/pages/homePage/welcome_msg.md', 'utf8');
|
||||
@@ -481,6 +482,11 @@ app.use(async (err, req, res, next)=>{
|
||||
res.status(err.status || err.response?.status || 500).send(err);
|
||||
return;
|
||||
}
|
||||
if(err.originalUrl?.startsWith('/archive/')) {
|
||||
// console.log('archive error');
|
||||
res.status(err.status || err.response?.status || 500).send(err);
|
||||
return;
|
||||
}
|
||||
|
||||
// console.log('non-API error');
|
||||
const status = err.status || err.code || 500;
|
||||
@@ -504,6 +510,8 @@ app.use(async (err, req, res, next)=>{
|
||||
res.send(page);
|
||||
});
|
||||
|
||||
|
||||
|
||||
app.use((req, res)=>{
|
||||
if(!res.headersSent) {
|
||||
console.error('Headers have not been sent, responding with a server error.', req.url);
|
||||
|
||||
53
server/archive.api.js
Normal file
53
server/archive.api.js
Normal file
@@ -0,0 +1,53 @@
|
||||
const HomebrewModel = require('./homebrew.model.js').model;
|
||||
const router = require('express').Router();
|
||||
const asyncHandler = require('express-async-handler');
|
||||
|
||||
const archive = {
|
||||
archiveApi : router,
|
||||
/* Searches for matching title, also attempts to partial match */
|
||||
findBrews : async (req, res, next)=>{
|
||||
try {
|
||||
const title = req.query.title || '';
|
||||
const page = parseInt(req.query.page) || 1;
|
||||
console.log('try:', page);
|
||||
const pageSize = 10; // Set a default page size
|
||||
const skip = (page - 1) * pageSize;
|
||||
|
||||
const titleQuery = {
|
||||
title : { $regex: decodeURIComponent(title), $options: 'i' },
|
||||
published : true
|
||||
};
|
||||
|
||||
const projection = {
|
||||
editId : 0,
|
||||
googleId : 0,
|
||||
text : 0,
|
||||
textBin : 0,
|
||||
};
|
||||
|
||||
const brews = await HomebrewModel.find(titleQuery, projection)
|
||||
.skip(skip)
|
||||
.limit(pageSize)
|
||||
.maxTimeMS(5000)
|
||||
.exec();
|
||||
|
||||
if(!brews || brews.length === 0) {
|
||||
// No published documents found with the given title
|
||||
return res.status(404).json({ error: 'Published documents not found' });
|
||||
}
|
||||
|
||||
const totalDocuments = await HomebrewModel.countDocuments(title);
|
||||
|
||||
const totalPages = Math.ceil(totalDocuments / pageSize);
|
||||
|
||||
return res.json({ brews, page, totalPages });
|
||||
} catch (error) {
|
||||
console.error(error);
|
||||
return res.status(500).json({ error: 'Internal Server Error' });
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
router.get('/api/archive', asyncHandler(archive.findBrews));
|
||||
|
||||
module.exports = router;
|
||||
Reference in New Issue
Block a user