0
0
mirror of https://github.com/naturalcrit/homebrewery.git synced 2026-01-23 16:33:05 +00:00

Compare commits

...

43 Commits

Author SHA1 Message Date
G.Ambatte
eeec24ae78 Change fetch to use request-middleware instead 2024-02-13 09:14:31 +13:00
G.Ambatte
1d778e3249 Update API route 2024-02-13 09:13:47 +13:00
G.Ambatte
3bb44d8a17 Lint clean up 2024-02-13 09:06:33 +13:00
Víctor Losada Hernández
71c52b4587 fix html response 2024-02-12 08:44:18 +01:00
Víctor Losada Hernández
fe449abb47 trying to figure out pagination 2024-02-10 16:41:39 +01:00
Víctor Losada Hernández
46d1f89b77 minor fixes 2024-01-29 00:12:14 +01:00
Víctor Losada Hernández
bf1f2054de minor fixes 2024-01-28 16:14:54 +01:00
Víctor Losada Hernández
399caaaeff typo 2024-01-28 16:11:32 +01:00
Víctor Losada Hernández
27b4176e23 initial screen 2024-01-28 16:08:44 +01:00
Víctor Losada Hernández
a8bc6b4e1d h2 to h3 2024-01-28 16:04:21 +01:00
Víctor Losada Hernández
3ca8f72762 brewCount 2024-01-28 16:02:19 +01:00
Víctor Losada Hernández
8aec5dbba6 error 500 catch and show 2024-01-28 15:57:51 +01:00
Víctor Losada Hernández
cccebd8494 title and no brews UI 2024-01-28 11:18:37 +01:00
Víctor Losada Hernández
5fbbd92ea7 limit to 1000 2024-01-28 01:12:46 +01:00
Víctor Losada Hernández
81f26e0892 exclude last fix 2024-01-28 00:55:22 +01:00
Víctor Losada Hernández
9366284e1d quick fix 2024-01-28 00:26:35 +01:00
Víctor Losada Hernández
9aa5eea8c9 exclude fields and add a time limit 2024-01-27 23:31:56 +01:00
Víctor Losada Hernández
20f61bff07 limit to 2000 2024-01-27 21:46:28 +01:00
Víctor Losada Hernández
625819da91 Merge branch 'master' of https://github.com/naturalcrit/homebrewery into experimental-development 2024-01-27 19:14:48 +01:00
Víctor Losada Hernández
2c691d84f2 author fix 3 2024-01-27 19:14:38 +01:00
Víctor Losada Hernández
4630d2640b author another fix 2024-01-27 17:29:16 +01:00
Víctor Losada Hernández
043f24d5ca invited authors is not a thing 2024-01-27 16:56:38 +01:00
Víctor Losada Hernández
87e18c0521 no authors fix 2024-01-27 16:56:28 +01:00
Víctor Losada Hernández
7e30f860b2 typo fix 2024-01-27 16:26:06 +01:00
Víctor Losada Hernández
0ac0ffe53d limit to 3000 2024-01-27 16:25:06 +01:00
Víctor Losada Hernández
ae4e1b55e6 minor changes 2024-01-27 16:24:45 +01:00
Víctor Losada Hernández
756ced088c Merge branch 'experimental-development' of https://github.com/5e-Cleric/homebrewery into experimental-development 2024-01-27 14:31:34 +01:00
Víctor Losada Hernández
8ce6b22be7 reject modernity, embrace tradition 2024-01-27 14:31:32 +01:00
Trevor Buckner
6184d64f89 Merge branch 'master' into pr/3263 2024-01-25 16:43:21 -05:00
Víctor Losada Hernández
c00c2626b4 Merge branch 'master' into experimental-development 2024-01-24 22:56:30 +01:00
Víctor Losada Hernández
89fddd0210 limit search and adapt ui 2024-01-24 21:15:26 +01:00
Víctor Losada Hernández
0c167d803c limit the search 2024-01-24 21:15:00 +01:00
Víctor Losada Hernández
c50042c1e7 i love grid template area 2024-01-23 22:55:36 +01:00
Víctor Losada Hernández
0dc1b46466 stying updates, agnostic theme 2024-01-23 19:08:57 +01:00
Víctor Losada Hernández
4ed9fc7d0e fix url params 2024-01-23 18:35:09 +01:00
Víctor Losada Hernández
162929bdca trying to catch url with query 2024-01-23 14:02:27 +01:00
Víctor Losada Hernández
54a2f6940c from admin to archive api 2024-01-23 10:40:53 +01:00
Víctor Losada Hernández
0dff59d793 linting and space issues 2024-01-23 08:07:51 +01:00
Víctor Losada Hernández
7951c4a03a basic ui and small changes 2024-01-23 00:20:18 +01:00
Víctor Losada Hernández
66fd56fccb basic functionality 2024-01-22 23:52:42 +01:00
Víctor Losada Hernández
da699e999f basic looks 2024-01-22 23:20:36 +01:00
Víctor Losada Hernández
c6a5f50c76 admin page fix 2024-01-22 17:22:54 +01:00
Víctor Losada Hernández
74c7395ab9 admin look by title 2024-01-22 16:59:45 +01:00
8 changed files with 454 additions and 2 deletions

View File

@@ -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

View File

@@ -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} />} />

View 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;

View 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;
}
}
}
}
}
}
}

View File

@@ -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)}`}>

View File

@@ -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();

View File

@@ -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
View 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;