From 74c7395ab982197fe97075686a1fd4dd5748a61b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?V=C3=ADctor=20Losada=20Hern=C3=A1ndez?= Date: Mon, 22 Jan 2024 16:59:45 +0100 Subject: [PATCH 001/252] admin look by title --- client/admin/brewLookup/brewLookup.jsx | 8 +++++ client/admin/stats/stats.jsx | 2 ++ server/admin.api.js | 42 ++++++++++++++++++++++---- 3 files changed, 46 insertions(+), 6 deletions(-) diff --git a/client/admin/brewLookup/brewLookup.jsx b/client/admin/brewLookup/brewLookup.jsx index c9212d990..427c05915 100644 --- a/client/admin/brewLookup/brewLookup.jsx +++ b/client/admin/brewLookup/brewLookup.jsx @@ -66,6 +66,14 @@ const BrewLookup = createClass({ 'fa-spin fa-spinner' : this.state.searching, })} /> + + + {this.state.error &&
{this.state.error.toString()}
diff --git a/client/admin/stats/stats.jsx b/client/admin/stats/stats.jsx index 85ce10610..609d7fe43 100644 --- a/client/admin/stats/stats.jsx +++ b/client/admin/stats/stats.jsx @@ -34,6 +34,8 @@ const Stats = createClass({
Total Brew Count
{this.state.stats.totalBrews}
+
Total Brews Published Count
+
{this.state.stats.totalPublishedBrews || 'no published brews'}
{this.state.fetching diff --git a/server/admin.api.js b/server/admin.api.js index b9b2afbd7..4835411d6 100644 --- a/server/admin.api.js +++ b/server/admin.api.js @@ -64,6 +64,13 @@ router.get('/admin/lookup/:id', mw.adminOnly, (req, res, next)=>{ }); }); +/* Searches for matching title, also attempts to partial match */ +router.get('/admin/lookup/:id', mw.adminOnly, (req, res, next)=>{ + HomebrewModel.findOne({ $or : { title: { '$regex': /./, '$options': 'i' } } }).exec((err, brew)=>{ + return res.json(brew); + }); +}); + /* Find 50 brews that aren't compressed yet */ router.get('/admin/finduncompressed', mw.adminOnly, (req, res)=>{ uncompressedBrewQuery.exec((err, objs)=>{ @@ -91,13 +98,36 @@ router.put('/admin/compress/:id', (req, res)=>{ }); }); -router.get('/admin/stats', mw.adminOnly, (req, res)=>{ - HomebrewModel.count({}, (err, count)=>{ - return res.json({ - totalBrews : count - }); - }); +router.get('/admin/stats', mw.adminOnly, async (req, res) => { + try { + const totalBrewsCount = await HomebrewModel.countDocuments({}); + const publishedBrewsCount = await HomebrewModel.countDocuments({ published: true }); + + return res.json({ + totalBrews: totalBrewsCount, + totalPublishedBrews: publishedBrewsCount + }); + } catch (error) { + console.error(error); + return res.status(500).json({ error: 'Internal Server Error' }); + } }); + + + +/* +router.get('/admin/stats', mw.adminOnly, async (req, res) => { + try { + const count = await HomebrewModel.countDocuments({}); + return res.json({ + totalBrews: count + }); + } catch (error) { + console.error(error); + return res.status(500).json({ error: 'Internal Server Error' }); + } +}); +*/ router.get('/admin', mw.adminOnly, (req, res)=>{ templateFn('admin', { From c6a5f50c76ad887dd540df383c880c5175eca7f4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?V=C3=ADctor=20Losada=20Hern=C3=A1ndez?= Date: Mon, 22 Jan 2024 17:22:54 +0100 Subject: [PATCH 002/252] admin page fix --- client/admin/brewLookup/brewLookup.jsx | 8 ------ server/admin.api.js | 35 ++++++++++++++++---------- 2 files changed, 22 insertions(+), 21 deletions(-) diff --git a/client/admin/brewLookup/brewLookup.jsx b/client/admin/brewLookup/brewLookup.jsx index 427c05915..c9212d990 100644 --- a/client/admin/brewLookup/brewLookup.jsx +++ b/client/admin/brewLookup/brewLookup.jsx @@ -66,14 +66,6 @@ const BrewLookup = createClass({ 'fa-spin fa-spinner' : this.state.searching, })} /> - - - {this.state.error &&
{this.state.error.toString()}
diff --git a/server/admin.api.js b/server/admin.api.js index 4835411d6..c0615de1b 100644 --- a/server/admin.api.js +++ b/server/admin.api.js @@ -55,22 +55,31 @@ router.post('/admin/cleanup', mw.adminOnly, (req, res)=>{ }); /* Searches for matching edit or share id, also attempts to partial match */ -router.get('/admin/lookup/:id', mw.adminOnly, (req, res, next)=>{ - HomebrewModel.findOne({ $or : [ - { editId: { '$regex': req.params.id, '$options': 'i' } }, - { shareId: { '$regex': req.params.id, '$options': 'i' } }, - ] }).exec((err, brew)=>{ - return res.json(brew); - }); + +router.get('/admin/lookup/:id', mw.adminOnly, async (req, res, next) => { + try { + const brew = await HomebrewModel.findOne({ + $or: [ + { editId: { $regex: req.params.id, $options: 'i' } }, + { shareId: { $regex: req.params.id, $options: 'i' } }, + ] + }).exec(); + + if (!brew) { + // No document found + return res.status(404).json({ error: 'Document not found' }); + } + + return res.json(brew); + } catch (error) { + console.error(error); + return res.status(500).json({ error: 'Internal Server Error' }); + } }); -/* Searches for matching title, also attempts to partial match */ -router.get('/admin/lookup/:id', mw.adminOnly, (req, res, next)=>{ - HomebrewModel.findOne({ $or : { title: { '$regex': /./, '$options': 'i' } } }).exec((err, brew)=>{ - return res.json(brew); - }); -}); + + /* Find 50 brews that aren't compressed yet */ router.get('/admin/finduncompressed', mw.adminOnly, (req, res)=>{ uncompressedBrewQuery.exec((err, objs)=>{ From da699e999f6513c65b0e63fd8d5ee765fd004e0f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?V=C3=ADctor=20Losada=20Hern=C3=A1ndez?= Date: Mon, 22 Jan 2024 23:20:36 +0100 Subject: [PATCH 003/252] basic looks --- client/homebrew/homebrew.jsx | 2 + .../pages/archivePage/archivePage.jsx | 133 ++++++++++++++++++ .../pages/archivePage/archivePage.less | 74 ++++++++++ 3 files changed, 209 insertions(+) create mode 100644 client/homebrew/pages/archivePage/archivePage.jsx create mode 100644 client/homebrew/pages/archivePage/archivePage.less diff --git a/client/homebrew/homebrew.jsx b/client/homebrew/homebrew.jsx index a08a39ea0..257128766 100644 --- a/client/homebrew/homebrew.jsx +++ b/client/homebrew/homebrew.jsx @@ -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({ } /> } /> } /> + }/> } /> } /> } /> diff --git a/client/homebrew/pages/archivePage/archivePage.jsx b/client/homebrew/pages/archivePage/archivePage.jsx new file mode 100644 index 000000000..29243eeb9 --- /dev/null +++ b/client/homebrew/pages/archivePage/archivePage.jsx @@ -0,0 +1,133 @@ +require('./archivePage.less'); +const React = require('react'); +const createClass = require('create-react-class'); +const _ = require('lodash'); +const cx = require('classnames'); +const moment = require('moment'); + +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 NaturalCritIcon = require('naturalcrit/svg/naturalcrit.svg.jsx'); + +const ArchivePage = createClass({ + displayName : 'ArchivePage', + getDefaultProps : function() { + return { + query : '', + foundBrew : null, + searching : false, + error : null + }; + }, + getInitialState : function() { + return { + uiItems : this.props.uiItems + }; + }, + handleChange(e){ + this.setState({ query: e.target.value }); + }, + lookup(){ + this.setState({ searching: true, error: null }); + + request.get(`/admin/lookup/${this.state.query}`) + .then((res)=>this.setState({ foundBrew: 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}
+
+
; + }, + + renderForm: function() { + return
+

Brew Lookup

+ + {/* In the future, we should be able to filter the results by adding tags. + + */} + + + {this.state.error + &&
{this.state.error.toString()}
+ } + + {this.state.foundBrew + ? this.renderFoundBrew() + :
No brew found.
+ } +
; + }, + + renderResults : function() { + + }, + + renderNavItems : function() { + return + + + + + + + ; + }, + + render : function() { + return
+ {this.renderNavItems()} + +
+
+

Welcome to the Archive

+
+
+
+ {this.renderForm()} +
+
+
+

Your results, my lordship

+ {this.renderResults()} +
+
+
+
+
+ } +}); + +module.exports = ArchivePage; \ No newline at end of file diff --git a/client/homebrew/pages/archivePage/archivePage.less b/client/homebrew/pages/archivePage/archivePage.less new file mode 100644 index 000000000..50ddf4de1 --- /dev/null +++ b/client/homebrew/pages/archivePage/archivePage.less @@ -0,0 +1,74 @@ + + +.archivePage { + height:100%; + background-color: #2C3E50; + .content { + display:grid; + grid-template-rows: 20vh 1fr; + + .welcome { + background: url('https://i.imgur.com/MJ4YHu7.jpg'); + background-size:100%; + background-position:center; + height:20vh; + + h1 { + font-size:40px; + font-weight:900; + color:white; + filter: drop-shadow(0 0 5px black); + } + } + + .flexGroup { + height:100%; + display:grid; + grid-template-columns:1fr 2fr; + + .dataGroup { + width:100%; + height:100%; + background:white; + + &.form .brewLookup { + padding:100px; + + h2 { + font-size:20px; + font-weight: 900; + 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:76.8vh; + + .title { + height:20%; + background-color: #333; + display:grid; + place-items: center; + + h2 { + font-size:20px; + color:white; + font-weight:900; + } + } + } + } + } + } +} \ No newline at end of file From 66fd56fccbfd2a0b5a11854f21f56f51d33a97e3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?V=C3=ADctor=20Losada=20Hern=C3=A1ndez?= Date: Mon, 22 Jan 2024 23:52:42 +0100 Subject: [PATCH 004/252] basic functionality --- .../pages/archivePage/archivePage.jsx | 87 +++++++++---------- .../pages/archivePage/archivePage.less | 38 ++++++-- server/admin.api.js | 21 ++++- 3 files changed, 94 insertions(+), 52 deletions(-) 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)=>{ From 7951c4a03ab60d319c9805354d987d06d4190bd7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?V=C3=ADctor=20Losada=20Hern=C3=A1ndez?= Date: Tue, 23 Jan 2024 00:20:18 +0100 Subject: [PATCH 005/252] basic ui and small changes --- .../pages/archivePage/archivePage.jsx | 11 ++++++++++- .../pages/archivePage/archivePage.less | 19 ++++++++++++++++--- 2 files changed, 26 insertions(+), 4 deletions(-) diff --git a/client/homebrew/pages/archivePage/archivePage.jsx b/client/homebrew/pages/archivePage/archivePage.jsx index 31c04c5b4..7a5da8916 100644 --- a/client/homebrew/pages/archivePage/archivePage.jsx +++ b/client/homebrew/pages/archivePage/archivePage.jsx @@ -55,7 +55,16 @@ const ArchivePage = createClass({
{brew.title}
Authors:
-
{brew.authors.join(', ')}
+
+ {brew.authors.map((author, index) => ( + + + {author} + + {index < brew.authors.length - 1 && ', '} + + ))} +
Check the brew diff --git a/client/homebrew/pages/archivePage/archivePage.less b/client/homebrew/pages/archivePage/archivePage.less index d9d069789..f4cc75ab1 100644 --- a/client/homebrew/pages/archivePage/archivePage.less +++ b/client/homebrew/pages/archivePage/archivePage.less @@ -57,7 +57,7 @@ height:76.8vh; .title { - height:20%; + height:100px; background-color: #333; display:grid; place-items: center; @@ -70,12 +70,25 @@ } .foundBrews { + background-color: #2C3E50; display:flex; - flex-direction: column; + flex-direction: row; + flex-wrap:wrap; width:100%; + min-height:500px; + height:max-content; + padding:50px; + padding-bottom:unset; + overflow-y:scroll; .brewItem { - width:200px; + background-image: url('/assets/parchmentBackground.jpg'); + width:500px; + height:auto; + min-height:unset; + overflow:visible; + margin-right:50px; + dt { font-size:20px; From 0dff59d793ec4b33a85e1b7babfef5fd901c1576 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?V=C3=ADctor=20Losada=20Hern=C3=A1ndez?= Date: Tue, 23 Jan 2024 08:07:51 +0100 Subject: [PATCH 006/252] linting and space issues --- .../pages/archivePage/archivePage.jsx | 275 ++++++++++-------- .../pages/archivePage/archivePage.less | 2 +- 2 files changed, 158 insertions(+), 119 deletions(-) diff --git a/client/homebrew/pages/archivePage/archivePage.jsx b/client/homebrew/pages/archivePage/archivePage.jsx index 7a5da8916..9926de3a8 100644 --- a/client/homebrew/pages/archivePage/archivePage.jsx +++ b/client/homebrew/pages/archivePage/archivePage.jsx @@ -1,139 +1,178 @@ require('./archivePage.less'); -const React = require('react'); +const React = require('react'); const createClass = require('create-react-class'); -const _ = require('lodash'); -const cx = require('classnames'); -const Moment = require('moment'); - -const Nav = require('naturalcrit/nav/nav.jsx'); -const Navbar = require('../../navbar/navbar.jsx'); +const _ = require('lodash'); +const cx = require('classnames'); +const Moment = require('moment'); +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 Account = require('../../navbar/account.navitem.jsx'); +const NewBrew = require('../../navbar/newbrew.navitem.jsx'); +const HelpNavItem = require('../../navbar/help.navitem.jsx'); const request = require('superagent'); const ArchivePage = createClass({ - displayName : 'ArchivePage', - getDefaultProps : function() { - return {}; - }, - getInitialState : function() { - return { - query : '', - foundBrews : null, - searching : false, - error : null - }; - }, - handleChange(e){ - this.setState({ query: e.target.value }); - }, - lookup(){ - this.setState({ searching: true, error: null }); + displayName: 'ArchivePage', + getDefaultProps: function () { + return {}; + }, + getInitialState: function () { + return { + query : '', + foundBrews : null, + searching : false, + error : null, + }; + }, + handleChange(e) { + this.setState({ query: e.target.value }); + }, + lookup() { + this.setState({ searching: true, error: null }); - 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 })); - }, - 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.map((author, index) => ( - - - {author} - - {index < brew.authors.length - 1 && ', '} + 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 })); + }, + 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.map((author, index) => ( + + + {author} + + {index < brew.authors.length - 1 && ', '} + + ))} +
+ + + Check the brew + + +
Systems:
+
{brew.systems.join(', ')}
+ + {brew.tags?.length ? ( + <> +
+ + {brew.tags.map((tag, idx) => { + const matches = tag.match(/^(?:([^:]+):)?([^:]+)$/); + return ( + + {matches[2]} - ))} -
- - Check the brew - -
Last Updated
-
{Moment(brew.updatedAt).fromNow()}
- -
Num of Views
-
{brew.views}
-
-
- ))} + ); + })} +
+ + ) : ( + <> + )} + +
Last Updated:
+
{Moment(brew.updatedAt).fromNow()}
+ +
Num of Views:
+
{brew.views}
+ - ); - }, + ))} + + ); + }, - renderForm: function() { - return
-

Brew Lookup

- - {/* In the future, we should be able to filter the results by adding tags. - + renderForm: function () { + return ( +
+

Brew Lookup

+ + + {/* In the future, we should be able to filter the results by adding tags. + */} - -
; - }, + +
+ ); + }, - renderResults : function() { + renderResults: function () {}, - }, - - renderNavItems : function() { - return - - - - - - - ; - }, + renderNavItems: function () { + return ( + + + + + + + + + ); + }, - render : function() { - return
- {this.renderNavItems()} + render: function () { + return ( +
+ {this.renderNavItems()} -
-
-

Welcome to the Archive

-
-
-
- {this.renderForm()} -
-
-
-

Your results, my lordship

- -
- {this.renderFoundBrews()} -
-
+
+
+

Welcome to the Archive

+
+
+
{this.renderForm()}
+
+
+

Your results, my lordship

+
+ {this.renderFoundBrews()}
+
- } +
+ ); + }, }); -module.exports = ArchivePage; \ No newline at end of file +module.exports = ArchivePage; diff --git a/client/homebrew/pages/archivePage/archivePage.less b/client/homebrew/pages/archivePage/archivePage.less index f4cc75ab1..08b10d86d 100644 --- a/client/homebrew/pages/archivePage/archivePage.less +++ b/client/homebrew/pages/archivePage/archivePage.less @@ -83,7 +83,7 @@ .brewItem { background-image: url('/assets/parchmentBackground.jpg'); - width:500px; + width:450px; height:auto; min-height:unset; overflow:visible; From 54a2f6940c264466267b3f7072adf0dc8f8c7398 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?V=C3=ADctor=20Losada=20Hern=C3=A1ndez?= Date: Tue, 23 Jan 2024 10:40:53 +0100 Subject: [PATCH 007/252] from admin to archive api --- .../pages/archivePage/archivePage.jsx | 74 ++----------------- server/admin.api.js | 22 ------ server/app.js | 8 ++ server/archive.api.js | 31 ++++++++ 4 files changed, 46 insertions(+), 89 deletions(-) create mode 100644 server/archive.api.js diff --git a/client/homebrew/pages/archivePage/archivePage.jsx b/client/homebrew/pages/archivePage/archivePage.jsx index 9926de3a8..b413056b5 100644 --- a/client/homebrew/pages/archivePage/archivePage.jsx +++ b/client/homebrew/pages/archivePage/archivePage.jsx @@ -3,7 +3,6 @@ const React = require('react'); const createClass = require('create-react-class'); const _ = require('lodash'); const cx = require('classnames'); -const Moment = require('moment'); const Nav = require('naturalcrit/nav/nav.jsx'); const Navbar = require('../../navbar/navbar.jsx'); @@ -11,6 +10,7 @@ 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 ListPage = require('../basePages/listPage/listPage.jsx'); const request = require('superagent'); @@ -22,7 +22,7 @@ const ArchivePage = createClass({ getInitialState: function () { return { query : '', - foundBrews : null, + brewCollection : null, searching : false, error : null, }; @@ -34,80 +34,20 @@ const ArchivePage = createClass({ this.setState({ searching: true, error: null }); request - .get(`/admin/archive/${this.state.query}`) - .then((res) => this.setState({ foundBrews: res.body })) + .get(`/archive/${this.state.query}`) + .then((res) => this.setState({ brewCollection: res.body })) .catch((err) => this.setState({ error: err })) .finally(() => this.setState({ searching: false })); }, renderFoundBrews() { - const brews = this.state.foundBrews; + const brews = this.state.brewCollection; if (!brews || brews.length === 0) { return
No brews found.
; } - return ( -
- {brews.map((brew, index) => ( -
-
-
Title:
-
{brew.title}
- -
Authors:
-
- {brew.authors.map((author, index) => ( - - - {author} - - {index < brew.authors.length - 1 && ', '} - - ))} -
- - - Check the brew - - -
Systems:
-
{brew.systems.join(', ')}
- - {brew.tags?.length ? ( - <> -
- - {brew.tags.map((tag, idx) => { - const matches = tag.match(/^(?:([^:]+):)?([^:]+)$/); - return ( - - {matches[2]} - - ); - })} -
- - ) : ( - <> - )} - -
Last Updated:
-
{Moment(brew.updatedAt).fromNow()}
- -
Num of Views:
-
{brew.views}
-
-
- ))} -
- ); + return ; + }, renderForm: function () { diff --git a/server/admin.api.js b/server/admin.api.js index 0c6fe1fc7..0884ca03f 100644 --- a/server/admin.api.js +++ b/server/admin.api.js @@ -76,28 +76,6 @@ router.get('/admin/lookup/:id', mw.adminOnly, async (req, res, next) => { return res.status(500).json({ error: 'Internal Server Error' }); } }); - - -/* 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)=>{ diff --git a/server/app.js b/server/app.js index 970c2cd9c..84ea4662b 100644 --- a/server/app.js +++ b/server/app.js @@ -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'); @@ -480,6 +481,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; @@ -503,6 +509,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); diff --git a/server/archive.api.js b/server/archive.api.js new file mode 100644 index 000000000..e4c6b704b --- /dev/null +++ b/server/archive.api.js @@ -0,0 +1,31 @@ +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 brews = await HomebrewModel.find({ + title: { $regex: req.params.query, $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' }); + } + } +} +router.get('/archive/:query', asyncHandler(archive.findBrews)); + + +module.exports = archive; \ No newline at end of file From 162929bdcaeb67f8ad77660ac1b23ff7662a2298 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?V=C3=ADctor=20Losada=20Hern=C3=A1ndez?= Date: Tue, 23 Jan 2024 14:02:27 +0100 Subject: [PATCH 008/252] trying to catch url with query --- client/homebrew/homebrew.jsx | 1 + .../pages/archivePage/archivePage.jsx | 33 +++++++++++++++++-- server/archive.api.js | 3 +- 3 files changed, 33 insertions(+), 4 deletions(-) diff --git a/client/homebrew/homebrew.jsx b/client/homebrew/homebrew.jsx index 257128766..039d81e2c 100644 --- a/client/homebrew/homebrew.jsx +++ b/client/homebrew/homebrew.jsx @@ -76,6 +76,7 @@ const Homebrew = createClass({ } /> } /> }/> + }/> } /> } /> } /> diff --git a/client/homebrew/pages/archivePage/archivePage.jsx b/client/homebrew/pages/archivePage/archivePage.jsx index b413056b5..e79b8bf34 100644 --- a/client/homebrew/pages/archivePage/archivePage.jsx +++ b/client/homebrew/pages/archivePage/archivePage.jsx @@ -27,6 +27,20 @@ const ArchivePage = createClass({ error : null, }; }, + componentDidMount: function () { + const url = new URL(window.location.href); + const pathSegments = url.pathname.split('/'); + + // Check if there's a path parameter after /archive/ + if (pathSegments.length > 2 && pathSegments[1] === 'archive') { + const pathQuery = pathSegments[2]; + console.log(pathQuery); + this.setState({ query: pathQuery }, () => { + this.lookup(); + }); + } + }, + handleChange(e) { this.setState({ query: e.target.value }); }, @@ -39,13 +53,28 @@ const ArchivePage = createClass({ .catch((err) => this.setState({ error: err })) .finally(() => this.setState({ searching: false })); }, + updateUrl: function(query) { + const url = new URL(window.location.href); + const urlParams = new URLSearchParams(url.search); + // Clear existing parameters + urlParams.delete('sort'); + urlParams.delete('dir'); + urlParams.delete('filter'); + + // Set the pathname to '/archive/query' + url.pathname = `/archive/${this.state.query}`; + + url.search = urlParams; + window.history.replaceState(null, null, url); +}, renderFoundBrews() { const brews = this.state.brewCollection; if (!brews || brews.length === 0) { return
No brews found.
; } - + console.table(brews); + this.updateUrl(); return ; }, @@ -76,7 +105,7 @@ const ArchivePage = createClass({ ); }, - renderResults: function () {}, + renderNavItems: function () { return ( diff --git a/server/archive.api.js b/server/archive.api.js index e4c6b704b..6302e3041 100644 --- a/server/archive.api.js +++ b/server/archive.api.js @@ -17,7 +17,6 @@ const archive = { // 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); @@ -28,4 +27,4 @@ const archive = { router.get('/archive/:query', asyncHandler(archive.findBrews)); -module.exports = archive; \ No newline at end of file +module.exports = router; \ No newline at end of file From 4ed9fc7d0e4a3a6aaa3453e36f71d1e905323e5a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?V=C3=ADctor=20Losada=20Hern=C3=A1ndez?= Date: Tue, 23 Jan 2024 18:35:09 +0100 Subject: [PATCH 009/252] fix url params --- client/homebrew/homebrew.jsx | 1 - .../pages/archivePage/archivePage.jsx | 38 +++++++++---------- 2 files changed, 17 insertions(+), 22 deletions(-) diff --git a/client/homebrew/homebrew.jsx b/client/homebrew/homebrew.jsx index 039d81e2c..257128766 100644 --- a/client/homebrew/homebrew.jsx +++ b/client/homebrew/homebrew.jsx @@ -76,7 +76,6 @@ const Homebrew = createClass({ } /> } /> }/> - }/> } /> } /> } /> diff --git a/client/homebrew/pages/archivePage/archivePage.jsx b/client/homebrew/pages/archivePage/archivePage.jsx index e79b8bf34..10c1afb03 100644 --- a/client/homebrew/pages/archivePage/archivePage.jsx +++ b/client/homebrew/pages/archivePage/archivePage.jsx @@ -10,7 +10,7 @@ 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 ListPage = require('../basePages/listPage/listPage.jsx'); +const BrewItem = require('../basePages/listPage/brewItem/brewItem.jsx'); const request = require('superagent'); @@ -21,34 +21,26 @@ const ArchivePage = createClass({ }, getInitialState: function () { return { - query : '', + title : this.props.query.title || '', brewCollection : null, searching : false, error : null, }; }, - componentDidMount: function () { - const url = new URL(window.location.href); - const pathSegments = url.pathname.split('/'); - - // Check if there's a path parameter after /archive/ - if (pathSegments.length > 2 && pathSegments[1] === 'archive') { - const pathQuery = pathSegments[2]; - console.log(pathQuery); - this.setState({ query: pathQuery }, () => { - this.lookup(); - }); - } + componentDidMount : function() { + console.log(this.state.title); + this.lookup(); }, + handleChange(e) { - this.setState({ query: e.target.value }); + this.setState({ title: e.target.value }); }, lookup() { this.setState({ searching: true, error: null }); request - .get(`/archive/${this.state.query}`) + .get(`/archive/${this.state.title}`) .then((res) => this.setState({ brewCollection: res.body })) .catch((err) => this.setState({ error: err })) .finally(() => this.setState({ searching: false })); @@ -61,8 +53,8 @@ const ArchivePage = createClass({ urlParams.delete('dir'); urlParams.delete('filter'); - // Set the pathname to '/archive/query' - url.pathname = `/archive/${this.state.query}`; + // Set the pathname to '/archive/?query' + urlParams.set('title', this.state.title); url.search = urlParams; window.history.replaceState(null, null, url); @@ -73,9 +65,13 @@ const ArchivePage = createClass({ if (!brews || brews.length === 0) { return
No brews found.
; } - console.table(brews); this.updateUrl(); - return ; + return
+ {brews.map((brew, index) => ( + + ))} +
+ }, @@ -86,7 +82,7 @@ const ArchivePage = createClass({ From 0dc1b46466c04ac594d73af0c1e68e42411769c1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?V=C3=ADctor=20Losada=20Hern=C3=A1ndez?= Date: Tue, 23 Jan 2024 19:08:57 +0100 Subject: [PATCH 010/252] stying updates, agnostic theme --- .../pages/archivePage/archivePage.less | 51 +++++++++++++------ 1 file changed, 36 insertions(+), 15 deletions(-) diff --git a/client/homebrew/pages/archivePage/archivePage.less b/client/homebrew/pages/archivePage/archivePage.less index 08b10d86d..227ab619f 100644 --- a/client/homebrew/pages/archivePage/archivePage.less +++ b/client/homebrew/pages/archivePage/archivePage.less @@ -72,27 +72,50 @@ .foundBrews { background-color: #2C3E50; display:flex; - flex-direction: row; - flex-wrap:wrap; + flex-direction:column; width:100%; min-height:500px; height:max-content; padding:50px; padding-bottom:unset; - overflow-y:scroll; .brewItem { - background-image: url('/assets/parchmentBackground.jpg'); - width:450px; - height:auto; + height:50px; min-height:unset; - overflow:visible; - margin-right:50px; - - - dt { - font-size:20px; - font-weight:900; + width:100%; + display:flex; + color:white; + background:#707070; + .text { + min-height:unset; + width:20vw; + text-overflow: ellipsis; + overflow:hidden; + white-space: nowrap; + display:grid; + align-content:center; + h2 { + font-size: 20px; + font-weight:900; + + } + } + hr { + display:none; + } + .info { + width:100%; + display:grid; + grid-template-columns: 3fr 1fr 70px 70px 150px 50px; + align-items:center; + + br { + display:none; + } + &:not(:has(.brewTags)) { + grid-template-columns:3fr 70px 70px 150px 50px; + } + } } } @@ -107,7 +130,5 @@ - - From c50042c1e7e72893077196534444fa4f95d9e012 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?V=C3=ADctor=20Losada=20Hern=C3=A1ndez?= Date: Tue, 23 Jan 2024 22:55:36 +0100 Subject: [PATCH 011/252] i love grid template area --- .../pages/archivePage/archivePage.less | 280 ++++++++++++------ 1 file changed, 197 insertions(+), 83 deletions(-) diff --git a/client/homebrew/pages/archivePage/archivePage.less b/client/homebrew/pages/archivePage/archivePage.less index 227ab619f..1bc5bcfbd 100644 --- a/client/homebrew/pages/archivePage/archivePage.less +++ b/client/homebrew/pages/archivePage/archivePage.less @@ -1,121 +1,243 @@ -.archivePage { - height:100%; - background-color: #2C3E50; +body { + height: 100vh; + .content { - display:grid; + height: 100%; + } +} + +.archivePage { + overflow-y: hidden; + height: 100%; + background-color: #2C3E50; + + .content { + display: grid; grid-template-rows: 20vh 1fr; - + .welcome { - display:grid; + 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; - + background-size: 100%; + background-position: center; + height: 20vh; + border-bottom: 5px solid #333; + h1 { - font-size:40px; - font-weight:900; - color:white; + font-size: 40px; + font-weight: 900; + color: white; filter: drop-shadow(0 0 5px black); } } - + .flexGroup { - height:100%; - display:grid; - grid-template-columns:1fr 2fr; - + height: 100%; + display: grid; + grid-template-columns: 1fr 2fr; + .dataGroup { - width:100%; - height:100%; - background:white; - + width: 100%; + height: 100%; + background: white; + &.form .brewLookup { - padding:50px; - + padding: 50px; + h2 { - font-size:30px; + font-size: 30px; font-weight: 900; - border-bottom:2px solid; + border-bottom: 2px solid; margin-block: 20px; } - + label { - margin-right:10px; + margin-right: 10px; } + input+button { - margin-left:20px; + margin-left: 20px; } } - + &.resultsContainer { - display:flex; + display: flex; flex-direction: column; - border-left:2px solid; - height:76.8vh; - + border-left: 2px solid; + height: 100%; + .title { - height:100px; + height: 100px; background-color: #333; - display:grid; + display: grid; place-items: center; - + h2 { - font-size:30px; - color:white; - font-weight:900; + font-size: 30px; + color: white; + font-weight: 900; } } - + .foundBrews { background-color: #2C3E50; - display:flex; - flex-direction:column; - width:100%; - min-height:500px; - height:max-content; - padding:50px; - padding-bottom:unset; - + display: flex; + flex-direction: column; + width: 100%; + min-height: 500px; + height: 100%; + padding: 50px; + padding-bottom: unset; + .brewItem { - height:50px; - min-height:unset; - width:100%; - display:flex; - color:white; - background:#707070; + height: 50px; + min-height: unset; + width: 100%; + display: flex; + color: white; + background: #707070; + overflow: visible; + .text { - min-height:unset; - width:20vw; - text-overflow: ellipsis; - overflow:hidden; - white-space: nowrap; - display:grid; - align-content:center; + min-height: unset; + width: 20vw; + padding-inline:10px; + + display: grid; + align-content: center; + h2 { + text-overflow: ellipsis; + overflow: hidden; + white-space: nowrap; font-size: 20px; - font-weight:900; - + font-weight: 900; + } } + hr { - display:none; + display: none; } + .info { - width:100%; - display:grid; - grid-template-columns: 3fr 1fr 70px 70px 150px 50px; - align-items:center; - + width: 100%; + display: grid; + grid-template-areas: "tags authors views pages update storage"; + justify-content: end; + align-content: space-around; + grid-template-columns: 3fr 150px 70px 70px 200px 50px; br { - display:none; + display: none; } - &:not(:has(.brewTags)) { - grid-template-columns:3fr 70px 70px 150px 50px; + .brewTags{ + display:inline-block; + grid-area: tags; + } + [title*="Authors:"] { + display:inline-block; + grid-area: authors; + } + [title*="Last"] { + display:inline-block; + grid-area: views; + } + [title*="Page"] { + display:inline-block; + grid-area: pages; + } + [title*="Created"] { + display:inline-block; + grid-area: update; } + [title*="Storage"] { + display:inline-block; + grid-area: storage; + filter:drop-shadow(0 0 10px white); + } + + .brewTags { + padding-left: 10px; + } + + .brewTags:has(span:nth-of-type(4)) { + position: relative; + overflow: hidden; + display: flex; + flex-wrap: wrap; + + + span:nth-of-type(n+2) { + display: none; + } + + &:hover { + overflow: visible; + position: absolute; + top: 0; + background:#707070; + height: max-content; + z-index: 100; + width:min-content; + + span:nth-of-type(n+4) { + display: block; + } + + &:after { + position: absolute; + top: 48px; + right: 0; + left:0; + bottom:0; + content: ''; + display: block; + height: calc(100% - 48px); + background: #707070; + border-inline: 1px solid gold; + border-bottom: 1px solid gold; + border-bottom-left-radius: 5px; + border-bottom-right-radius: 5px; + z-index: -1; + } + } + } + + + + } + + .links { + opacity: 1; + background: none; + position: relative; + display: grid; + grid-template-columns: 1fr 1fr; + height: 100%; + width: 100px; + + .editLink, + .deleteLink { + display: none; + } + + >a { + opacity: .8; + + &:hover { + opacity: 1; + } + } + + .shareLink { + color: deepskyblue; + } + + .downloadLink { + color: coral; + } } } } @@ -123,12 +245,4 @@ } } } -} - - - - - - - - +} \ No newline at end of file From 0c167d803c180c5953a0206c063b39ba8ffad0fb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?V=C3=ADctor=20Losada=20Hern=C3=A1ndez?= Date: Wed, 24 Jan 2024 21:15:00 +0100 Subject: [PATCH 012/252] limit the search --- server/archive.api.js | 43 ++++++++++++++++++++++++++----------------- 1 file changed, 26 insertions(+), 17 deletions(-) diff --git a/server/archive.api.js b/server/archive.api.js index 6302e3041..73ec2f170 100644 --- a/server/archive.api.js +++ b/server/archive.api.js @@ -2,29 +2,38 @@ const HomebrewModel = require('./homebrew.model.js').model; const router = require('express').Router(); const asyncHandler = require('express-async-handler'); - const archive = { - archiveApi : router, + archiveApi: router, /* Searches for matching title, also attempts to partial match */ - findBrews : async (req, res, next) => { + findBrews: async (req, res, next) => { try { - const brews = await HomebrewModel.find({ - title: { $regex: req.params.query, $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); + const limit = 3; + const brews = await HomebrewModel.find({ + title: { $regex: req.params.query, $options: 'i' }, + published: true + }) + .limit(limit) + .exec(); + + if (!brews || brews.length === 0) { + // No published documents found with the given title + return res.status(404).json({ error: 'Published documents not found' }); + } + + let message = ''; + if (brews.length === limit) { + // If the limit has been reached, include a message in the response + message = `You've reached the limit of ${limit} documents, you can try being more specific in your search.`; + } + + return res.json({ brews, message }); } catch (error) { - console.error(error); - return res.status(500).json({ error: 'Internal Server Error' }); + console.error(error); + return res.status(500).json({ error: 'Internal Server Error' }); } } } + router.get('/archive/:query', asyncHandler(archive.findBrews)); - -module.exports = router; \ No newline at end of file +module.exports = router; From 89fddd02101e0a1873ee30a66bc5200b22fb4221 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?V=C3=ADctor=20Losada=20Hern=C3=A1ndez?= Date: Wed, 24 Jan 2024 21:15:26 +0100 Subject: [PATCH 013/252] limit search and adapt ui --- .../pages/archivePage/archivePage.jsx | 10 ++++++-- .../pages/archivePage/archivePage.less | 25 ++++++++++++++++--- server/archive.api.js | 2 +- 3 files changed, 31 insertions(+), 6 deletions(-) diff --git a/client/homebrew/pages/archivePage/archivePage.jsx b/client/homebrew/pages/archivePage/archivePage.jsx index 10c1afb03..80bab8619 100644 --- a/client/homebrew/pages/archivePage/archivePage.jsx +++ b/client/homebrew/pages/archivePage/archivePage.jsx @@ -25,6 +25,7 @@ const ArchivePage = createClass({ brewCollection : null, searching : false, error : null, + limit : '', }; }, componentDidMount : function() { @@ -38,10 +39,9 @@ const ArchivePage = createClass({ }, lookup() { this.setState({ searching: true, error: null }); - request .get(`/archive/${this.state.title}`) - .then((res) => this.setState({ brewCollection: res.body })) + .then((res) => this.setState({ brewCollection: res.body.brews }, this.setState({ limit: res.body.message}))) .catch((err) => this.setState({ error: err })) .finally(() => this.setState({ searching: false })); }, @@ -67,6 +67,9 @@ const ArchivePage = createClass({ } this.updateUrl(); return
+
+

{this.state.limit}

+
{brews.map((brew, index) => ( ))} @@ -84,11 +87,14 @@ const ArchivePage = createClass({ type='text' value={this.state.title} onChange={this.handleChange} + onKeyDown={(e) => e.key === 'Enter' && this.lookup()} placeholder='v3 Reference Document' /> {/* In the future, we should be able to filter the results by adding tags. + */} + + )} + Page {page} + {page < totalPages && ( + + )}
- ); - } - - if (!brews || brews.length === 0) { - return( -
-

We haven't found brews meeting your request.

-
- - ); - } - this.updateUrl(); - return
- {brews.length} Brews Found - {this.state.limit} - {brews.map((brew, index) => ( - - ))} -
- - + ); }, + renderForm: function () { return (
@@ -115,7 +125,7 @@ const ArchivePage = createClass({ onKeyDown={(e) => { if (e.key === 'Enter') { this.handleChange(e); - this.lookup(); + this.loadPage(1); } }} placeholder='v3 Reference Document' @@ -125,7 +135,7 @@ const ArchivePage = createClass({ */} - - )} - Page {page} - {page < totalPages && ( - - )} -
-
- ); - }, + try { + //this.updateUrl(); + this.setState({ searching: true, error: null }); + const title = encodeURIComponent(this.state.title); + const response = await fetch(`/archive?title=${title}&page=${page}`); - renderForm: function () { - return ( -
-

Brew Lookup

- - { - 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. + if(response.ok) { + const res = await response.json(); + this.updateStateWithBrews(res.brews, page, res.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 (

Whenever you want, just start typing...

);} + + if(error !== null) { + return ( +
+

I'm sorry, your request didn't work

+

Your search is not specific enough. Too many brews meet this criteria for us to display them.

+
+ ); + } + + if(!brewCollection || brewCollection.length === 0) { + return ( +
+

We haven't found brews meeting your request.

+
+ ); + } + + return ( +
+ {`Brews Found: ${brewCollection.length}`} + + {brewCollection.map((brew, index)=>( + + ))} +
+ {page > 1 && ( + + )} + Page {page} + {page < totalPages && ( + + )} +
+
+ ); + }, + + + renderForm : function () { + return ( +
+

Brew Lookup

+ + { + 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. */} - - -
- ); - }, - + +
+ ); + }, - renderNavItems: function () { - return ( - - + + + renderNavItems : function () { + return ( + + Archive: Search for brews - - - - - - - - ); - }, + + + + + + + + ); + }, - render: function () { - return ( -
- + render : function () { + return ( +
+ - {this.renderNavItems()} + {this.renderNavItems()} -
-
-

Welcome to the Archive

-
-
-
{this.renderForm()}
-
-
-

Your results, my lordship

-
- {this.renderFoundBrews()} -
-
-
-
- ); - }, +
+
+

Welcome to the Archive

+
+
+
{this.renderForm()}
+
+
+

Your results, my lordship

+
+ {this.renderFoundBrews()} +
+
+
+
+ ); + }, }); module.exports = ArchivePage; diff --git a/server/archive.api.js b/server/archive.api.js index 4166bf80a..d959b27b8 100644 --- a/server/archive.api.js +++ b/server/archive.api.js @@ -3,49 +3,49 @@ 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; + 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 titleQuery = { + title : { $regex: decodeURIComponent(title), $options: 'i' }, + published : true + }; - const projection = { - editId: 0, - googleId: 0, - text: 0, - textBin: 0, - }; + const projection = { + editId : 0, + googleId : 0, + text : 0, + textBin : 0, + }; - const brews = await HomebrewModel.find(titleQuery, projection) + 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' }); - } + 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 totalDocuments = await HomebrewModel.countDocuments(title); - const totalPages = Math.ceil(totalDocuments / pageSize); + 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' }); - } - } + return res.json({ brews, page, totalPages }); + } catch (error) { + console.error(error); + return res.status(500).json({ error: 'Internal Server Error' }); + } + } }; router.get('/archive', asyncHandler(archive.findBrews)); From 1d778e3249d79789920daaabf7d63bd1c3352ba2 Mon Sep 17 00:00:00 2001 From: "G.Ambatte" Date: Tue, 13 Feb 2024 09:13:47 +1300 Subject: [PATCH 038/252] Update API route --- server/archive.api.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/server/archive.api.js b/server/archive.api.js index d959b27b8..196b634a5 100644 --- a/server/archive.api.js +++ b/server/archive.api.js @@ -48,6 +48,6 @@ const archive = { } }; -router.get('/archive', asyncHandler(archive.findBrews)); +router.get('/api/archive', asyncHandler(archive.findBrews)); module.exports = router; \ No newline at end of file From eeec24ae78fb54f7549cc93a8315a70f2aa36040 Mon Sep 17 00:00:00 2001 From: "G.Ambatte" Date: Tue, 13 Feb 2024 09:14:31 +1300 Subject: [PATCH 039/252] Change fetch to use request-middleware instead --- .../pages/archivePage/archivePage.jsx | 26 +++++++++---------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/client/homebrew/pages/archivePage/archivePage.jsx b/client/homebrew/pages/archivePage/archivePage.jsx index aae1b6631..49025bf30 100644 --- a/client/homebrew/pages/archivePage/archivePage.jsx +++ b/client/homebrew/pages/archivePage/archivePage.jsx @@ -13,7 +13,7 @@ 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('superagent'); +const request = require('../../utils/request-middleware.js'); const ArchivePage = createClass({ displayName : 'ArchivePage', @@ -37,14 +37,15 @@ const ArchivePage = createClass({ this.setState({ title: e.target.value }); }, - updateStateWithBrews : (brews, page, totalPages)=>{ + updateStateWithBrews : function (brews, page, totalPages) { this.setState({ - brewCollection : brews, - page : page, - totalPages : totalPages, + brewCollection : brews || null, + page : page || 1, + totalPages : totalPages || 1, searching : false }); }, + loadPage : async function(page) { if(this.state.title == '') {} else { @@ -52,19 +53,18 @@ const ArchivePage = createClass({ //this.updateUrl(); this.setState({ searching: true, error: null }); const title = encodeURIComponent(this.state.title); - const response = await fetch(`/archive?title=${title}&page=${page}`); - - - if(response.ok) { - const res = await response.json(); - this.updateStateWithBrews(res.brews, page, res.totalPages); - } - + 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); From 05a7defcb82a639eb3fb661c1b5f83e1eb77cb66 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?V=C3=ADctor=20Losada=20Hern=C3=A1ndez?= Date: Mon, 12 Feb 2024 23:18:24 +0100 Subject: [PATCH 040/252] remove brewCount useless element --- client/homebrew/pages/archivePage/archivePage.jsx | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/client/homebrew/pages/archivePage/archivePage.jsx b/client/homebrew/pages/archivePage/archivePage.jsx index 49025bf30..c05ce3bec 100644 --- a/client/homebrew/pages/archivePage/archivePage.jsx +++ b/client/homebrew/pages/archivePage/archivePage.jsx @@ -101,18 +101,16 @@ const ArchivePage = createClass({ return (
- {`Brews Found: ${brewCollection.length}`} - {brewCollection.map((brew, index)=>( ))}
{page > 1 && ( - + )} Page {page} {page < totalPages && ( - + )}
From d233e2b4a5f2a91da4e5463033623abe510f29d0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?V=C3=ADctor=20Losada=20Hern=C3=A1ndez?= Date: Mon, 12 Feb 2024 23:18:37 +0100 Subject: [PATCH 041/252] css fix, pagination controls basic look --- .../pages/archivePage/archivePage.less | 30 ++++++++++++++++++- 1 file changed, 29 insertions(+), 1 deletion(-) diff --git a/client/homebrew/pages/archivePage/archivePage.less b/client/homebrew/pages/archivePage/archivePage.less index e0ae9460e..ec0460958 100644 --- a/client/homebrew/pages/archivePage/archivePage.less +++ b/client/homebrew/pages/archivePage/archivePage.less @@ -140,7 +140,7 @@ body { margin-right: 40px; color: black; - &:nth-child(even) { + &:nth-child(even of .brewItem) { margin-right: 0; } h2 { @@ -162,6 +162,34 @@ body { } } + .paginationControls { + position: absolute; + left: 50%; + translate: -50%; + width: 500px; + display: grid; + grid-template-areas: "previousPage currentPage nextPage"; + + .currentPage { + grid-area: currentPage; + height: 100%; + width: 100%; + display: block; + text-align: center; + color: white; + font-family: Open Sans; + font-weight: 900; + padding: 5px 8px; + } + + button.previousPage { + grid-area: previousPage; + } + button.nextPage { + grid-area: nextPage; + } + } + hr { visibility: hidden; } From 534131d994fc0540e4886510fdb053cc54296e7d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?V=C3=ADctor=20Losada=20Hern=C3=A1ndez?= Date: Mon, 12 Feb 2024 23:54:00 +0100 Subject: [PATCH 042/252] edit console logs and change totalDocs logic to count correctly --- server/archive.api.js | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/server/archive.api.js b/server/archive.api.js index 196b634a5..fe3d9609c 100644 --- a/server/archive.api.js +++ b/server/archive.api.js @@ -9,7 +9,7 @@ const archive = { try { const title = req.query.title || ''; const page = parseInt(req.query.page) || 1; - console.log('try:', page); + console.log('trying page ', page); const pageSize = 10; // Set a default page size const skip = (page - 1) * pageSize; @@ -17,29 +17,28 @@ const archive = { 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(); + console.log(brews.length); 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 totalDocuments = await HomebrewModel.countDocuments(titleQuery, projection); + const totalPages = Math.ceil(totalDocuments / pageSize); - + console.log('Total brews: ', totalDocuments); + console.log('Total pages: ', totalPages); return res.json({ brews, page, totalPages }); } catch (error) { console.error(error); From 2f323cde8aa784a1a88fd3b5b52d461607bd8c65 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?V=C3=ADctor=20Losada=20Hern=C3=A1ndez?= Date: Mon, 12 Feb 2024 23:54:15 +0100 Subject: [PATCH 043/252] remove unused logic from loadpage --- .../pages/archivePage/archivePage.jsx | 28 +++++++++---------- 1 file changed, 13 insertions(+), 15 deletions(-) diff --git a/client/homebrew/pages/archivePage/archivePage.jsx b/client/homebrew/pages/archivePage/archivePage.jsx index c05ce3bec..84a26f84c 100644 --- a/client/homebrew/pages/archivePage/archivePage.jsx +++ b/client/homebrew/pages/archivePage/archivePage.jsx @@ -47,21 +47,19 @@ const ArchivePage = createClass({ }, 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}`); - } + this.updateUrl(); + 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}`); } }, From 7ffc02c3e54b7caa3e80e3646e2ffd92c9fa81ba Mon Sep 17 00:00:00 2001 From: "G.Ambatte" Date: Tue, 13 Feb 2024 13:25:45 +1300 Subject: [PATCH 044/252] Reset searching state on error --- client/homebrew/pages/archivePage/archivePage.jsx | 1 + 1 file changed, 1 insertion(+) diff --git a/client/homebrew/pages/archivePage/archivePage.jsx b/client/homebrew/pages/archivePage/archivePage.jsx index 84a26f84c..73fc90af2 100644 --- a/client/homebrew/pages/archivePage/archivePage.jsx +++ b/client/homebrew/pages/archivePage/archivePage.jsx @@ -60,6 +60,7 @@ const ArchivePage = createClass({ }); } catch (error) { console.log(`LoadPage error: ${error}`); + this.updateStateWithBrews([], 1, 1); } }, From 9fc8af65536f5f0fe80b429c63ab3ab555d04a5f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?V=C3=ADctor=20Losada=20Hern=C3=A1ndez?= Date: Tue, 13 Feb 2024 10:48:19 +0100 Subject: [PATCH 045/252] pagination controls render separately --- .../pages/archivePage/archivePage.jsx | 36 +++++++++++---- .../pages/archivePage/archivePage.less | 45 ++++++++++++++----- 2 files changed, 60 insertions(+), 21 deletions(-) diff --git a/client/homebrew/pages/archivePage/archivePage.jsx b/client/homebrew/pages/archivePage/archivePage.jsx index 84a26f84c..a29824202 100644 --- a/client/homebrew/pages/archivePage/archivePage.jsx +++ b/client/homebrew/pages/archivePage/archivePage.jsx @@ -75,6 +75,32 @@ const ArchivePage = createClass({ window.history.replaceState(null, null, url); }, + renderPaginationControls() { + const { title, brewCollection, page, totalPages, error } = this.state; + const pages = new Array(totalPages).fill().map((_, index) => ( +
  • this.loadPage(index+1)}>{index + 1}
  • + )); + + return ( +
    + {page > 1 && ( + + )} +
      {pages}
    + {page < totalPages && ( + + )} +
    + ); + }, + renderFoundBrews() { const { title, brewCollection, page, totalPages, error } = this.state; @@ -102,15 +128,7 @@ const ArchivePage = createClass({ {brewCollection.map((brew, index)=>( ))} -
    - {page > 1 && ( - - )} - Page {page} - {page < totalPages && ( - - )} -
    + {this.renderPagination()} ); }, diff --git a/client/homebrew/pages/archivePage/archivePage.less b/client/homebrew/pages/archivePage/archivePage.less index ec0460958..7e10c2ef3 100644 --- a/client/homebrew/pages/archivePage/archivePage.less +++ b/client/homebrew/pages/archivePage/archivePage.less @@ -166,28 +166,49 @@ body { position: absolute; left: 50%; translate: -50%; - width: 500px; + width: auto; display: grid; + place-items: center; grid-template-areas: "previousPage currentPage nextPage"; + grid-template-columns: 50px 1fr 50px; - .currentPage { + .pages { grid-area: currentPage; height: 100%; width: 100%; - display: block; + display: flex; + justify-content:space-evenly; text-align: center; - color: white; - font-family: Open Sans; - font-weight: 900; padding: 5px 8px; + + .pageNumber { + color: white; + font-family: Open Sans; + font-weight: 900; + text-underline-position: under; + margin-inline:10px; + cursor: pointer; + + &.currentPage { + color:gold; + text-decoration:underline; + pointer-events:none; + } + } + } + button { + width:max-content; + border-radius:5px; + + &.previousPage { + grid-area: previousPage; + } + + &.nextPage { + grid-area: nextPage; + } } - button.previousPage { - grid-area: previousPage; - } - button.nextPage { - grid-area: nextPage; - } } hr { From 74ac8f9ffa9a71c47176a0efc69ba105e8795833 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?V=C3=ADctor=20Losada=20Hern=C3=A1ndez?= Date: Tue, 13 Feb 2024 10:52:12 +0100 Subject: [PATCH 046/252] quickfix --- client/homebrew/pages/archivePage/archivePage.jsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/client/homebrew/pages/archivePage/archivePage.jsx b/client/homebrew/pages/archivePage/archivePage.jsx index c7f7b4d93..5bbee10b8 100644 --- a/client/homebrew/pages/archivePage/archivePage.jsx +++ b/client/homebrew/pages/archivePage/archivePage.jsx @@ -129,7 +129,7 @@ const ArchivePage = createClass({ {brewCollection.map((brew, index)=>( ))} - {this.renderPagination()} + {this.renderPaginationControls()} ); }, From 3482d92ab631903b6127faf03ace8e04e7c38fe6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?V=C3=ADctor=20Losada=20Hern=C3=A1ndez?= Date: Thu, 15 Feb 2024 01:10:28 +0100 Subject: [PATCH 047/252] catch 503 error --- client/homebrew/pages/archivePage/archivePage.jsx | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/client/homebrew/pages/archivePage/archivePage.jsx b/client/homebrew/pages/archivePage/archivePage.jsx index 5bbee10b8..ebe24f7bc 100644 --- a/client/homebrew/pages/archivePage/archivePage.jsx +++ b/client/homebrew/pages/archivePage/archivePage.jsx @@ -60,6 +60,7 @@ const ArchivePage = createClass({ }); } catch (error) { console.log(`LoadPage error: ${error}`); + this.setState({ error: {error} }); this.updateStateWithBrews([], 1, 1); } }, @@ -67,8 +68,7 @@ const ArchivePage = createClass({ 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); @@ -107,7 +107,7 @@ const ArchivePage = createClass({ if(title === '') {return (

    Whenever you want, just start typing...

    );} - if(error !== null) { + if(error === 'Error: Service Unavailable') { return (

    I'm sorry, your request didn't work

    @@ -116,7 +116,7 @@ const ArchivePage = createClass({ ); } - if(!brewCollection || brewCollection.length === 0) { + if(!brewCollection || brewCollection.length === 0 || error === 'Error: Not found') { return (

    We haven't found brews meeting your request.

    From 46262c56dbb2ad375d1b46a1d82c57425fe93c65 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?V=C3=ADctor=20Losada=20Hern=C3=A1ndez?= Date: Thu, 15 Feb 2024 01:15:00 +0100 Subject: [PATCH 048/252] 503 catch 2 --- client/homebrew/pages/archivePage/archivePage.jsx | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/client/homebrew/pages/archivePage/archivePage.jsx b/client/homebrew/pages/archivePage/archivePage.jsx index ebe24f7bc..3fc85c162 100644 --- a/client/homebrew/pages/archivePage/archivePage.jsx +++ b/client/homebrew/pages/archivePage/archivePage.jsx @@ -47,9 +47,8 @@ const ArchivePage = createClass({ }, loadPage : async function(page) { - this.updateUrl(); + this.updateUrl(); try { - //this.updateUrl(); this.setState({ searching: true, error: null }); const title = encodeURIComponent(this.state.title); await request.get(`/api/archive?title=${title}&page=${page}`) @@ -60,7 +59,7 @@ const ArchivePage = createClass({ }); } catch (error) { console.log(`LoadPage error: ${error}`); - this.setState({ error: {error} }); + this.setState({ error: `${error}` }); this.updateStateWithBrews([], 1, 1); } }, From 3427fa1e94ffeca923b0328f697a265b90a69bf5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?V=C3=ADctor=20Losada=20Hern=C3=A1ndez?= Date: Thu, 15 Feb 2024 01:26:54 +0100 Subject: [PATCH 049/252] total brews found --- client/homebrew/pages/archivePage/archivePage.jsx | 7 +++++-- server/archive.api.js | 8 ++++---- 2 files changed, 9 insertions(+), 6 deletions(-) diff --git a/client/homebrew/pages/archivePage/archivePage.jsx b/client/homebrew/pages/archivePage/archivePage.jsx index 3fc85c162..f82488af3 100644 --- a/client/homebrew/pages/archivePage/archivePage.jsx +++ b/client/homebrew/pages/archivePage/archivePage.jsx @@ -26,6 +26,7 @@ const ArchivePage = createClass({ brewCollection : null, page : 1, totalPages : 1, + totalBrews : 0, searching : false, error : null, }; @@ -37,11 +38,12 @@ const ArchivePage = createClass({ this.setState({ title: e.target.value }); }, - updateStateWithBrews : function (brews, page, totalPages) { + updateStateWithBrews : function (brews, page, totalPages, totalBrews) { this.setState({ brewCollection : brews || null, page : page || 1, totalPages : totalPages || 1, + totalBrews : totalBrews, searching : false }); }, @@ -54,7 +56,7 @@ const ArchivePage = createClass({ await request.get(`/api/archive?title=${title}&page=${page}`) .then((response)=>{ if(response.ok) { - this.updateStateWithBrews(response.body.brews, page, response.body.totalPages); + this.updateStateWithBrews(response.body.brews, page, response.body.totalPages, response.body.totalBrews); } }); } catch (error) { @@ -125,6 +127,7 @@ const ArchivePage = createClass({ return (
    + Brews found: {this.state.totalBrews} {brewCollection.map((brew, index)=>( ))} diff --git a/server/archive.api.js b/server/archive.api.js index fe3d9609c..2e2ecb711 100644 --- a/server/archive.api.js +++ b/server/archive.api.js @@ -34,12 +34,12 @@ const archive = { // No published documents found with the given title return res.status(404).json({ error: 'Published documents not found' }); } - const totalDocuments = await HomebrewModel.countDocuments(titleQuery, projection); + const totalBrews = await HomebrewModel.countDocuments(titleQuery, projection); - const totalPages = Math.ceil(totalDocuments / pageSize); - console.log('Total brews: ', totalDocuments); + const totalPages = Math.ceil(totalBrews / pageSize); + console.log('Total brews: ', totalBrews); console.log('Total pages: ', totalPages); - return res.json({ brews, page, totalPages }); + return res.json({ brews, page, totalPages, totalBrews}); } catch (error) { console.error(error); return res.status(500).json({ error: 'Internal Server Error' }); From ea1855485c12f2542f7c45fc513b60151faf7610 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?V=C3=ADctor=20Losada=20Hern=C3=A1ndez?= Date: Thu, 15 Feb 2024 01:27:05 +0100 Subject: [PATCH 050/252] css fixes --- .../pages/archivePage/archivePage.less | 28 +++---------------- 1 file changed, 4 insertions(+), 24 deletions(-) diff --git a/client/homebrew/pages/archivePage/archivePage.less b/client/homebrew/pages/archivePage/archivePage.less index 7e10c2ef3..0f51d3a4a 100644 --- a/client/homebrew/pages/archivePage/archivePage.less +++ b/client/homebrew/pages/archivePage/archivePage.less @@ -97,11 +97,12 @@ body { } &.noBrews { - display:grid; - place-items:center; + display: grid; + place-items: center; + color: white; } - .brewCount { + .totalBrews { position: fixed; bottom: 0; right: 17px; @@ -112,27 +113,6 @@ body { 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'); From 153ab6339396b21747efff97c985613ea7a4d192 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?V=C3=ADctor=20Losada=20Hern=C3=A1ndez?= Date: Thu, 15 Feb 2024 08:48:47 +0100 Subject: [PATCH 051/252] pagesize as input --- .../pages/archivePage/archivePage.jsx | 78 ++++++++++++------- .../pages/archivePage/archivePage.less | 25 ++++-- server/archive.api.js | 5 +- 3 files changed, 74 insertions(+), 34 deletions(-) diff --git a/client/homebrew/pages/archivePage/archivePage.jsx b/client/homebrew/pages/archivePage/archivePage.jsx index f82488af3..07496f244 100644 --- a/client/homebrew/pages/archivePage/archivePage.jsx +++ b/client/homebrew/pages/archivePage/archivePage.jsx @@ -25,6 +25,7 @@ const ArchivePage = createClass({ title : this.props.query.title || '', brewCollection : null, page : 1, + pageSize : 10, totalPages : 1, totalBrews : 0, searching : false, @@ -34,8 +35,9 @@ const ArchivePage = createClass({ componentDidMount : function() { }, - handleChange(e) { - this.setState({ title: e.target.value }); + handleChange(inputName, e) { + + this.setState({ [inputName]: e.target.value }); }, updateStateWithBrews : function (brews, page, totalPages, totalBrews) { @@ -53,7 +55,8 @@ const ArchivePage = createClass({ try { this.setState({ searching: true, error: null }); const title = encodeURIComponent(this.state.title); - await request.get(`/api/archive?title=${title}&page=${page}`) + const size = parseInt(this.state.pageSize); + await request.get(`/api/archive?title=${title}&page=${page}&size=${size}`) .then((response)=>{ if(response.ok) { this.updateStateWithBrews(response.body.brews, page, response.body.totalPages, response.body.totalBrews); @@ -140,33 +143,54 @@ const ArchivePage = createClass({ renderForm : function () { return (
    -

    Brew Lookup

    - - { - 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. - - - */} +

    Brew Lookup

    +
    + + + + {/* In the future, we should be able to filter the results by adding tags. + + + */} - + })} + /> + +
    ); }, diff --git a/client/homebrew/pages/archivePage/archivePage.less b/client/homebrew/pages/archivePage/archivePage.less index 0f51d3a4a..cfe085662 100644 --- a/client/homebrew/pages/archivePage/archivePage.less +++ b/client/homebrew/pages/archivePage/archivePage.less @@ -48,20 +48,35 @@ body { background: white; &.form .brewLookup { + position: relative; padding: 50px; - h2 { + .formTitle { + color:black; font-size: 30px; border-bottom: 2px solid; - margin-block: 20px; + margin: 20px 0; + text-align: center; } + .formContents { + display: flex; + flex-direction: column; + } label { - margin-right: 10px; + margin: 10px 0; } + input { + margin: 0 10px; + } + .search { + position:absolute; + right:10px; + bottom:20px; - input+button { - margin-left: 20px; + i { + margin-left: 10px; + } } } diff --git a/server/archive.api.js b/server/archive.api.js index 2e2ecb711..dcc45a977 100644 --- a/server/archive.api.js +++ b/server/archive.api.js @@ -8,9 +8,10 @@ const archive = { findBrews : async (req, res, next)=>{ try { const title = req.query.title || ''; - const page = parseInt(req.query.page) || 1; + const page = Math.max(parseInt(req.query.page) || 1, 1); console.log('trying page ', page); - const pageSize = 10; // Set a default page size + const minPageSize = 6; + const pageSize = Math.max(parseInt(req.query.size) || 10, minPageSize); const skip = (page - 1) * pageSize; const titleQuery = { From 6a11cd0e28f5531bd48febd57a217d7cfdd5f081 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?V=C3=ADctor=20Losada=20Hern=C3=A1ndez?= Date: Thu, 15 Feb 2024 10:34:39 +0100 Subject: [PATCH 052/252] renderer filter query --- .../pages/archivePage/archivePage.jsx | 58 ++++++++++++++++--- server/archive.api.js | 21 +++++-- 2 files changed, 65 insertions(+), 14 deletions(-) diff --git a/client/homebrew/pages/archivePage/archivePage.jsx b/client/homebrew/pages/archivePage/archivePage.jsx index 07496f244..5c5e5a2ab 100644 --- a/client/homebrew/pages/archivePage/archivePage.jsx +++ b/client/homebrew/pages/archivePage/archivePage.jsx @@ -12,6 +12,7 @@ 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 StringArrayEditor = require('../stringArrayEditor/stringArrayEditor.jsx'); const request = require('../../utils/request-middleware.js'); @@ -22,12 +23,20 @@ const ArchivePage = createClass({ }, getInitialState : function () { return { + //request title : this.props.query.title || '', - brewCollection : null, - page : 1, + //tags : {}, + legacy : true, + v3 : true, pageSize : 10, - totalPages : 1, - totalBrews : 0, + page : 1, + + //response + brewCollection : null, + totalPages : null, + totalBrews : null, + + searching : false, error : null, }; @@ -36,7 +45,6 @@ const ArchivePage = createClass({ }, handleChange(inputName, e) { - this.setState({ [inputName]: e.target.value }); }, @@ -54,9 +62,11 @@ const ArchivePage = createClass({ this.updateUrl(); try { this.setState({ searching: true, error: null }); + const title = encodeURIComponent(this.state.title); const size = parseInt(this.state.pageSize); - await request.get(`/api/archive?title=${title}&page=${page}&size=${size}`) + const {legacy, v3} = this.state; + await request.get(`/api/archive?title=${title}&page=${page}&size=${size}&v3=${v3}&legacy=${legacy}`) .then((response)=>{ if(response.ok) { this.updateStateWithBrews(response.body.brews, page, response.body.totalPages, response.body.totalBrews); @@ -75,16 +85,22 @@ const ArchivePage = createClass({ urlParams.set('title', this.state.title); urlParams.set('page', this.state.page); + urlParams.set('pageSize', this.state.pageSize); + urlParams.set('v3', this.state.v3); + urlParams.set('legacy', this.state.legacy); + url.search = urlParams.toString(); // Convert URLSearchParams to string window.history.replaceState(null, null, url); }, renderPaginationControls() { - const { title, brewCollection, page, totalPages, error } = this.state; + const { page, totalPages,} = this.state; const pages = new Array(totalPages).fill().map((_, index) => (
  • this.loadPage(index+1)}>{index + 1}
  • )); + + if(totalPages === null) {return;} return (
    @@ -171,9 +187,33 @@ const ArchivePage = createClass({ onChange={(e) => this.handleChange('pageSize', e)} /> + + + + + + {/* In the future, we should be able to filter the results by adding tags. - - + <this.handleChange('tags', e)}/> + + check metadataEditor.jsx L65 */} )}
      {pages}
    {page < totalPages && ( - )} @@ -123,26 +133,34 @@ const ArchivePage = createClass({ }, renderFoundBrews() { - const { title, brewCollection, page, totalPages, error } = this.state; + const { title, brewCollection, page, totalPages, error, searching } = this.state; + console.log(searching === false && !brewCollection); + if(searching === false && title === '' && error === null) {return (

    Whenever you want, just start typing...

    );} - if(title === '' && error === null) {return (

    Whenever you want, just start typing...

    );} - - if(error === 'Error: Service Unavailable') { + if(searching === false && error === 'Error: Service Unavailable') { return (

    I'm sorry, your request didn't work


    Your search is not specific enough. Too many brews meet this criteria for us to display them.

    ); - } - - if(!brewCollection || brewCollection.length === 0 || error === 'Error: Not found') { + }; + + if(searching === false && (!brewCollection || error === 'Error: Not found')) { return (

    We haven't found brews meeting your request.

    ); - } + }; + + if(searching === true) { + return ( +
    +

    Searching

    ...

    +
    + ); + }; return (
    @@ -157,6 +175,9 @@ const ArchivePage = createClass({ renderForm : function () { + const v3 = (this.state.v3 === 'true'); + const legacy = (this.state.legacy === 'true'); + return (

    Brew Lookup

    @@ -164,14 +185,13 @@ const ArchivePage = createClass({
    +
    + ); }, renderPaginationControls() { - const { page, totalPages} = this.state; + const title = encodeURIComponent(this.state.title); + const size = parseInt(this.state.pageSize); + const {page, totalPages, legacy, v3} = this.state; + console.log('page: ', page); const pages = new Array(totalPages).fill().map((_, index) => ( -
  • this.loadPage(index + 1, false)}>{index + 1}
  • + {index + 1} )); - + if(totalPages === null) {return;} return ( @@ -173,105 +282,6 @@ const ArchivePage = createClass({ ); }, - - renderForm : function () { - const v3 = (this.state.v3 === 'true'); - const legacy = (this.state.legacy === 'true'); - - return ( -
    -

    Brew Lookup

    -
    - - - - - - - - - - {/* In the future, we should be able to filter the results by adding tags. - <this.handleChange('tags', e)}/> - - check metadataEditor.jsx L65 - */} - - -
    -
    - ); - }, - - - - renderNavItems : function () { - return ( - - - Archive: Search for brews - - - - - - - - - ); - }, - render : function () { return (
    From fcb4c722c653ca20270d1658f6f47e24850c5ad9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?V=C3=ADctor=20Losada=20Hern=C3=A1ndez?= Date: Thu, 15 Feb 2024 15:28:36 +0100 Subject: [PATCH 056/252] test 404 error --- client/homebrew/pages/archivePage/archivePage.jsx | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/client/homebrew/pages/archivePage/archivePage.jsx b/client/homebrew/pages/archivePage/archivePage.jsx index 88fbc05aa..d3ea65545 100644 --- a/client/homebrew/pages/archivePage/archivePage.jsx +++ b/client/homebrew/pages/archivePage/archivePage.jsx @@ -243,7 +243,6 @@ const ArchivePage = createClass({ renderFoundBrews() { const { title, brewCollection, page, totalPages, error, searching } = this.state; - console.log(searching === false && !brewCollection); if(searching === false && title === '' && error === null) {return (

    Whenever you want, just start typing...

    );} if(searching === false && error === 'Error: Service Unavailable') { @@ -254,7 +253,7 @@ const ArchivePage = createClass({
    ); }; - + console.log('404: ', searching === false && (!brewCollection || error === 'Error: Not found')) if(searching === false && (!brewCollection || error === 'Error: Not found')) { return (
    From d7c9ab43bcb211f59fb38b6f2972290e79ab6278 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?V=C3=ADctor=20Losada=20Hern=C3=A1ndez?= Date: Thu, 15 Feb 2024 15:34:10 +0100 Subject: [PATCH 057/252] more tests --- client/homebrew/pages/archivePage/archivePage.jsx | 1 + 1 file changed, 1 insertion(+) diff --git a/client/homebrew/pages/archivePage/archivePage.jsx b/client/homebrew/pages/archivePage/archivePage.jsx index d3ea65545..365bb5f2a 100644 --- a/client/homebrew/pages/archivePage/archivePage.jsx +++ b/client/homebrew/pages/archivePage/archivePage.jsx @@ -253,6 +253,7 @@ const ArchivePage = createClass({
    ); }; + console.log(searching, !brewCollection, error); console.log('404: ', searching === false && (!brewCollection || error === 'Error: Not found')) if(searching === false && (!brewCollection || error === 'Error: Not found')) { return ( From 62db3939692cfee996d7f4389a0f821c64d5ce96 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?V=C3=ADctor=20Losada=20Hern=C3=A1ndez?= Date: Thu, 15 Feb 2024 15:50:27 +0100 Subject: [PATCH 058/252] proper error handling(i think) --- .../pages/archivePage/archivePage.jsx | 54 +++++++++++-------- server/archive.api.js | 10 +++- 2 files changed, 42 insertions(+), 22 deletions(-) diff --git a/client/homebrew/pages/archivePage/archivePage.jsx b/client/homebrew/pages/archivePage/archivePage.jsx index 365bb5f2a..07eae0311 100644 --- a/client/homebrew/pages/archivePage/archivePage.jsx +++ b/client/homebrew/pages/archivePage/archivePage.jsx @@ -243,27 +243,8 @@ const ArchivePage = createClass({ renderFoundBrews() { const { title, brewCollection, page, totalPages, error, searching } = this.state; - if(searching === false && title === '' && error === null) {return (

    Whenever you want, just start typing...

    );} - - if(searching === false && error === 'Error: Service Unavailable') { - return ( -
    -

    I'm sorry, your request didn't work

    -

    Your search is not specific enough. Too many brews meet this criteria for us to display them.

    -
    - ); - }; - console.log(searching, !brewCollection, error); - console.log('404: ', searching === false && (!brewCollection || error === 'Error: Not found')) - if(searching === false && (!brewCollection || error === 'Error: Not found')) { - return ( -
    -

    We haven't found brews meeting your request.

    -
    - ); - }; - - if(searching === true) { + + if(searching) { return (

    Searching

    ...

    @@ -271,6 +252,37 @@ const ArchivePage = createClass({ ); }; + if(title === '') {return (

    Whenever you want, just start typing...

    );} + + if (error) { + let errorMessage; + switch (error.errorCode) { + case '404': + errorMessage = "We didn't find any brew"; + break; + case '503': + errorMessage = 'Your search is not specific enough. Too many brews meet this criteria for us to display them.'; + break; + case '500': + default: + errorMessage = 'An unexpected error occurred'; + } + + return ( +
    +

    Error: {errorMessage}

    +
    + ); + }; + + if (!brewCollection || brewCollection.length === 0) { + return ( +
    +

    No brews found

    +
    + ); + }; + return (
    Brews found: {this.state.totalBrews} diff --git a/server/archive.api.js b/server/archive.api.js index 1c00d7f0a..3a8dd41b2 100644 --- a/server/archive.api.js +++ b/server/archive.api.js @@ -46,6 +46,10 @@ const archive = { // No published documents found with the given title return res.status(404).json({ error: 'Published documents not found' }); } + if (!brews || brews.length === 0) { + return res.status(404).json({ errorCode: '404', message: 'Published documents not found' }); + } + const totalBrews = await HomebrewModel.countDocuments(titleQuery, projection); const totalPages = Math.ceil(totalBrews / pageSize); @@ -54,7 +58,11 @@ const archive = { return res.json({ brews, page, totalPages, totalBrews}); } catch (error) { console.error(error); - return res.status(500).json({ error: 'Internal Server Error' }); + if (error.response && error.response.status === 503) { + return res.status(503).json({ errorCode: '503', message: 'Service Unavailable' }); + } else { + return res.status(500).json({ errorCode: '500', message: 'Internal Server Error' }); + } } } }; From 9c53541cbde0cee6563cbce867599269610f0911 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?V=C3=ADctor=20Losada=20Hern=C3=A1ndez?= Date: Thu, 15 Feb 2024 15:53:26 +0100 Subject: [PATCH 059/252] searching animation --- .../homebrew/pages/archivePage/archivePage.jsx | 2 +- .../homebrew/pages/archivePage/archivePage.less | 16 ++++++++++++---- 2 files changed, 13 insertions(+), 5 deletions(-) diff --git a/client/homebrew/pages/archivePage/archivePage.jsx b/client/homebrew/pages/archivePage/archivePage.jsx index 07eae0311..539abc65b 100644 --- a/client/homebrew/pages/archivePage/archivePage.jsx +++ b/client/homebrew/pages/archivePage/archivePage.jsx @@ -247,7 +247,7 @@ const ArchivePage = createClass({ if(searching) { return (
    -

    Searching

    ...

    +

    Searching

    ); }; diff --git a/client/homebrew/pages/archivePage/archivePage.less b/client/homebrew/pages/archivePage/archivePage.less index 665c94a94..251b3ce52 100644 --- a/client/homebrew/pages/archivePage/archivePage.less +++ b/client/homebrew/pages/archivePage/archivePage.less @@ -122,7 +122,15 @@ body { place-items: center; color: white; - h3.searchAnim { + h3 { position: relative;} + h3.searchAnim::after { + content: ""; + width: max-content; + height: 1em; + position: absolute; + right: 0; + top: 50%; + translate: 100% -50%; animation: trailingDots 2s ease infinite; } } @@ -229,13 +237,13 @@ body { @keyframes trailingDots { 0%,32% { - clip-path:inset(0 66% 0 0); + content:'.'; } 33%, 65% { - clip-path:inset(0 33% 0 0); + content:'..'; } 66%,100% { - clip-path:inset(0 0% 0 0); + content:'...'; } } \ No newline at end of file From 1a80a74d4fb5fdf53e11380a3f26ef8532565dde Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?V=C3=ADctor=20Losada=20Hern=C3=A1ndez?= Date: Thu, 15 Feb 2024 16:15:38 +0100 Subject: [PATCH 060/252] more error handling --- client/homebrew/pages/archivePage/archivePage.jsx | 1 - server/archive.api.js | 12 +++--------- 2 files changed, 3 insertions(+), 10 deletions(-) diff --git a/client/homebrew/pages/archivePage/archivePage.jsx b/client/homebrew/pages/archivePage/archivePage.jsx index 539abc65b..52c35586a 100644 --- a/client/homebrew/pages/archivePage/archivePage.jsx +++ b/client/homebrew/pages/archivePage/archivePage.jsx @@ -214,7 +214,6 @@ const ArchivePage = createClass({ const title = encodeURIComponent(this.state.title); const size = parseInt(this.state.pageSize); const {page, totalPages, legacy, v3} = this.state; - console.log('page: ', page); const pages = new Array(totalPages).fill().map((_, index) => ( {index + 1} )); diff --git a/server/archive.api.js b/server/archive.api.js index 3a8dd41b2..33ce01014 100644 --- a/server/archive.api.js +++ b/server/archive.api.js @@ -40,15 +40,6 @@ const archive = { .limit(pageSize) .maxTimeMS(5000) .exec(); - //console.log(brews.length); - - if(!brews || brews.length === 0) { - // No published documents found with the given title - return res.status(404).json({ error: 'Published documents not found' }); - } - if (!brews || brews.length === 0) { - return res.status(404).json({ errorCode: '404', message: 'Published documents not found' }); - } const totalBrews = await HomebrewModel.countDocuments(titleQuery, projection); @@ -58,6 +49,9 @@ const archive = { return res.json({ brews, page, totalPages, totalBrews}); } catch (error) { console.error(error); + if (error.response && error.response.status === 404) { + return res.status(404).json({ errorCode: '404', message: 'Brews not found' }); + } if (error.response && error.response.status === 503) { return res.status(503).json({ errorCode: '503', message: 'Service Unavailable' }); } else { From e08435568cb19e331c4457c8335da25de15a892f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?V=C3=ADctor=20Losada=20Hern=C3=A1ndez?= Date: Thu, 15 Feb 2024 16:20:08 +0100 Subject: [PATCH 061/252] don't search on reload without title --- client/homebrew/pages/archivePage/archivePage.jsx | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/client/homebrew/pages/archivePage/archivePage.jsx b/client/homebrew/pages/archivePage/archivePage.jsx index 52c35586a..cdccb4652 100644 --- a/client/homebrew/pages/archivePage/archivePage.jsx +++ b/client/homebrew/pages/archivePage/archivePage.jsx @@ -41,7 +41,10 @@ const ArchivePage = createClass({ }; }, componentDidMount : function() { - this.loadPage(this.state.page, false); + if (this.state.title !== '') { + this.loadPage(this.state.page, false); + } + }, updateStateWithBrews : function (brews, page, totalPages, totalBrews) { From 3afc9f83d9b5a8793f7e0411f2d0366b1af0f63e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?V=C3=ADctor=20Losada=20Hern=C3=A1ndez?= Date: Thu, 15 Feb 2024 16:23:37 +0100 Subject: [PATCH 062/252] where the hell did i lose the error handling --- client/homebrew/pages/archivePage/archivePage.jsx | 1 + 1 file changed, 1 insertion(+) diff --git a/client/homebrew/pages/archivePage/archivePage.jsx b/client/homebrew/pages/archivePage/archivePage.jsx index cdccb4652..3bdf44289 100644 --- a/client/homebrew/pages/archivePage/archivePage.jsx +++ b/client/homebrew/pages/archivePage/archivePage.jsx @@ -257,6 +257,7 @@ const ArchivePage = createClass({ if(title === '') {return (

    Whenever you want, just start typing...

    );} if (error) { + console.log(error.errorCode); let errorMessage; switch (error.errorCode) { case '404': From 04844a4422ce84d2f1f79e68d498bb5c91172b76 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?V=C3=ADctor=20Losada=20Hern=C3=A1ndez?= Date: Thu, 15 Feb 2024 16:27:50 +0100 Subject: [PATCH 063/252] you know the deal --- server/archive.api.js | 1 + 1 file changed, 1 insertion(+) diff --git a/server/archive.api.js b/server/archive.api.js index 33ce01014..fbc26f20d 100644 --- a/server/archive.api.js +++ b/server/archive.api.js @@ -49,6 +49,7 @@ const archive = { return res.json({ brews, page, totalPages, totalBrews}); } catch (error) { console.error(error); + console.log(error.response.status); if (error.response && error.response.status === 404) { return res.status(404).json({ errorCode: '404', message: 'Brews not found' }); } From f61b664687548af9e90b83ebd419199689a55a5d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?V=C3=ADctor=20Losada=20Hern=C3=A1ndez?= Date: Thu, 15 Feb 2024 16:32:50 +0100 Subject: [PATCH 064/252] 503 log --- server/archive.api.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/server/archive.api.js b/server/archive.api.js index fbc26f20d..7caa7f07c 100644 --- a/server/archive.api.js +++ b/server/archive.api.js @@ -49,7 +49,7 @@ const archive = { return res.json({ brews, page, totalPages, totalBrews}); } catch (error) { console.error(error); - console.log(error.response.status); + console.log(error.response); if (error.response && error.response.status === 404) { return res.status(404).json({ errorCode: '404', message: 'Brews not found' }); } From 2a780bc48240aa51c4267174ef57b9c29842b14d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?V=C3=ADctor=20Losada=20Hern=C3=A1ndez?= Date: Thu, 15 Feb 2024 16:36:10 +0100 Subject: [PATCH 065/252] 503 --- server/archive.api.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/server/archive.api.js b/server/archive.api.js index 7caa7f07c..a7f545e79 100644 --- a/server/archive.api.js +++ b/server/archive.api.js @@ -49,7 +49,7 @@ const archive = { return res.json({ brews, page, totalPages, totalBrews}); } catch (error) { console.error(error); - console.log(error.response); + console.log(error); if (error.response && error.response.status === 404) { return res.status(404).json({ errorCode: '404', message: 'Brews not found' }); } From 0fdb5e83cfa10eefd19881a2222be4bcaeb5c013 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?V=C3=ADctor=20Losada=20Hern=C3=A1ndez?= Date: Thu, 15 Feb 2024 16:44:03 +0100 Subject: [PATCH 066/252] if this renders null i don't understand anything --- client/homebrew/pages/archivePage/archivePage.jsx | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/client/homebrew/pages/archivePage/archivePage.jsx b/client/homebrew/pages/archivePage/archivePage.jsx index 3bdf44289..3e69b034b 100644 --- a/client/homebrew/pages/archivePage/archivePage.jsx +++ b/client/homebrew/pages/archivePage/archivePage.jsx @@ -114,7 +114,9 @@ const ArchivePage = createClass({ } }); } catch (error) { - console.log(`LoadPage error: ${error}`); + if (error.response && error.response.status === 503) { + console.log('loadPage 503'); + } this.setState({ error: `${error}` }); this.updateStateWithBrews([], 1, 1, 0); } @@ -257,7 +259,7 @@ const ArchivePage = createClass({ if(title === '') {return (

    Whenever you want, just start typing...

    );} if (error) { - console.log(error.errorCode); + console.log('render Error: ', error); let errorMessage; switch (error.errorCode) { case '404': From eb404b8e5b9a710cadf7509e1b6aca73dac06173 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?V=C3=ADctor=20Losada=20Hern=C3=A1ndez?= Date: Thu, 15 Feb 2024 16:51:20 +0100 Subject: [PATCH 067/252] where is my 503 error code --- client/homebrew/pages/archivePage/archivePage.jsx | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/client/homebrew/pages/archivePage/archivePage.jsx b/client/homebrew/pages/archivePage/archivePage.jsx index 3e69b034b..7517927e8 100644 --- a/client/homebrew/pages/archivePage/archivePage.jsx +++ b/client/homebrew/pages/archivePage/archivePage.jsx @@ -117,7 +117,7 @@ const ArchivePage = createClass({ if (error.response && error.response.status === 503) { console.log('loadPage 503'); } - this.setState({ error: `${error}` }); + this.setState({ error: `${error}` }) this.updateStateWithBrews([], 1, 1, 0); } }, @@ -259,7 +259,7 @@ const ArchivePage = createClass({ if(title === '') {return (

    Whenever you want, just start typing...

    );} if (error) { - console.log('render Error: ', error); + console.log('render Error: ', error.errorCode); let errorMessage; switch (error.errorCode) { case '404': From 8c07b12bb0f971d1ef1b65e7ba8987dccd7ecb80 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?V=C3=ADctor=20Losada=20Hern=C3=A1ndez?= Date: Thu, 15 Feb 2024 16:56:09 +0100 Subject: [PATCH 068/252] catch error codes --- client/homebrew/pages/archivePage/archivePage.jsx | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/client/homebrew/pages/archivePage/archivePage.jsx b/client/homebrew/pages/archivePage/archivePage.jsx index 7517927e8..fb587bdad 100644 --- a/client/homebrew/pages/archivePage/archivePage.jsx +++ b/client/homebrew/pages/archivePage/archivePage.jsx @@ -114,10 +114,7 @@ const ArchivePage = createClass({ } }); } catch (error) { - if (error.response && error.response.status === 503) { - console.log('loadPage 503'); - } - this.setState({ error: `${error}` }) + this.setState({ error: `${error.response.status}` }) this.updateStateWithBrews([], 1, 1, 0); } }, From fd6109099ade59f0ae51edf2c94536ac7b2ea191 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?V=C3=ADctor=20Losada=20Hern=C3=A1ndez?= Date: Thu, 15 Feb 2024 16:59:17 +0100 Subject: [PATCH 069/252] catch catch catch --- client/homebrew/pages/archivePage/archivePage.jsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/client/homebrew/pages/archivePage/archivePage.jsx b/client/homebrew/pages/archivePage/archivePage.jsx index fb587bdad..31e2684b8 100644 --- a/client/homebrew/pages/archivePage/archivePage.jsx +++ b/client/homebrew/pages/archivePage/archivePage.jsx @@ -256,7 +256,7 @@ const ArchivePage = createClass({ if(title === '') {return (

    Whenever you want, just start typing...

    );} if (error) { - console.log('render Error: ', error.errorCode); + console.log('render Error: ', error); let errorMessage; switch (error.errorCode) { case '404': From 01e3cd0296bba0ff4215ee7cb42c2411b64c50b4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?V=C3=ADctor=20Losada=20Hern=C3=A1ndez?= Date: Thu, 15 Feb 2024 17:22:20 +0100 Subject: [PATCH 070/252] fix notitle search and catch 404? --- .../pages/archivePage/archivePage.jsx | 28 ++++++++++++------- server/archive.api.js | 6 +--- 2 files changed, 19 insertions(+), 15 deletions(-) diff --git a/client/homebrew/pages/archivePage/archivePage.jsx b/client/homebrew/pages/archivePage/archivePage.jsx index 31e2684b8..9228d1a33 100644 --- a/client/homebrew/pages/archivePage/archivePage.jsx +++ b/client/homebrew/pages/archivePage/archivePage.jsx @@ -100,8 +100,8 @@ const ArchivePage = createClass({ if(update === true) { this.updateStateWithForm(); }; - - try { + if (title !== '') { + try { this.setState({ searching: true, error: null }); const title = encodeURIComponent(this.state.title); @@ -117,6 +117,12 @@ const ArchivePage = createClass({ this.setState({ error: `${error.response.status}` }) this.updateStateWithBrews([], 1, 1, 0); } + console.log(!this.state.brewCollection || brewCollection.length === 0); + if(!this.state.brewCollection) { + this.setState({ error: '404'}); + } + } + }, renderNavItems : function () { @@ -253,8 +259,16 @@ const ArchivePage = createClass({ ); }; - if(title === '') {return (

    Whenever you want, just start typing...

    );} + + if(title === '') {return (

    Whenever you want, just start typing...

    );} + if (!brewCollection || brewCollection.length === 0) { + return ( +
    +

    No brews found

    +
    + ); + }; if (error) { console.log('render Error: ', error); let errorMessage; @@ -277,13 +291,7 @@ const ArchivePage = createClass({ ); }; - if (!brewCollection || brewCollection.length === 0) { - return ( -
    -

    No brews found

    -
    - ); - }; + return (
    diff --git a/server/archive.api.js b/server/archive.api.js index a7f545e79..fffe24497 100644 --- a/server/archive.api.js +++ b/server/archive.api.js @@ -41,7 +41,7 @@ const archive = { .maxTimeMS(5000) .exec(); - const totalBrews = await HomebrewModel.countDocuments(titleQuery, projection); + const totalBrews = await HomebrewModel.countDocuments(titleQuery, projection).maxTimeMS(5000); const totalPages = Math.ceil(totalBrews / pageSize); //console.log('Total brews: ', totalBrews); @@ -49,10 +49,6 @@ const archive = { return res.json({ brews, page, totalPages, totalBrews}); } catch (error) { console.error(error); - console.log(error); - if (error.response && error.response.status === 404) { - return res.status(404).json({ errorCode: '404', message: 'Brews not found' }); - } if (error.response && error.response.status === 503) { return res.status(503).json({ errorCode: '503', message: 'Service Unavailable' }); } else { From 094ad3bd59d99a34e49a9e1e2d35f77361d0981b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?V=C3=ADctor=20Losada=20Hern=C3=A1ndez?= Date: Wed, 21 Feb 2024 08:07:46 +0100 Subject: [PATCH 071/252] -proj in countdocs --- server/archive.api.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/server/archive.api.js b/server/archive.api.js index fffe24497..6779526e2 100644 --- a/server/archive.api.js +++ b/server/archive.api.js @@ -41,7 +41,7 @@ const archive = { .maxTimeMS(5000) .exec(); - const totalBrews = await HomebrewModel.countDocuments(titleQuery, projection).maxTimeMS(5000); + const totalBrews = await HomebrewModel.countDocuments(titleQuery).maxTimeMS(5000); const totalPages = Math.ceil(totalBrews / pageSize); //console.log('Total brews: ', totalBrews); From e75c556443c7821335c96e20cf2595caba7f8307 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?V=C3=ADctor=20Losada=20Hern=C3=A1ndez?= Date: Mon, 6 May 2024 22:59:09 +0200 Subject: [PATCH 072/252] use $text instead --- server/archive.api.js | 122 ++++++++++++++++++++++++++++-------------- 1 file changed, 83 insertions(+), 39 deletions(-) diff --git a/server/archive.api.js b/server/archive.api.js index 6779526e2..578004fc0 100644 --- a/server/archive.api.js +++ b/server/archive.api.js @@ -3,61 +3,105 @@ 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 { - console.table(req.query); + archiveApi: router, + /* Searches for matching title, also attempts to partial match */ + findBrews: async (req, res, next) => { + try { + /* + const dbName = HomebrewModel.db.name; + console.log("Database Name:", dbName); + const collectionName = HomebrewModel.collection.name; + console.log("Collection Name:", collectionName); + + */ + console.table(req.query); - const title = req.query.title || ''; - const page = Math.max(parseInt(req.query.page) || 1, 1); - const minPageSize = 6; - const pageSize = Math.max(parseInt(req.query.size) || 10, minPageSize); - const skip = (page - 1) * pageSize; - - const titleQuery = { - title : { $regex: decodeURIComponent(title), $options: 'i' }, - $or: [], - published : true - }; + const title = req.query.title || ''; + const page = Math.max(parseInt(req.query.page) || 1, 1); + const minPageSize = 6; + const pageSize = Math.max( + parseInt(req.query.size) || 10, + minPageSize + ); + const skip = (page - 1) * pageSize; - if (req.query.legacy === 'true') { - titleQuery.$or.push({ renderer: 'legacy' }); + const brewsQuery = { + $or: [], + published: true, }; + if (req.query.legacy === 'true') { + brewsQuery.$or.push({ renderer: 'legacy' }); + } + if (req.query.v3 === 'true') { - titleQuery.$or.push({ renderer: 'V3' }); + brewsQuery.$or.push({ renderer: 'V3' }); + } + + // If user wants to use RegEx it needs to format like /text/ + const titleConditionsArray = + title.startsWith('/') && title.endsWith('/') + ? [ + { + 'title': { + $regex: title.slice(1, -1), + $options: 'i', + }, + }, + ] + : buildTitleConditions(title); + + function buildTitleConditions(inputString) { + return [ + { + $text: { + $search: inputString, + $caseSensitive: false, + }, + }, + ]; + } + + const titleQuery = { + $and: [brewsQuery, ...titleConditionsArray], }; - const projection = { - editId : 0, - googleId : 0, - text : 0, - textBin : 0, - }; - const brews = await HomebrewModel.find(titleQuery, projection) + const projection = { + editId: 0, + googleId: 0, + text: 0, + textBin: 0, + }; + const brews = await HomebrewModel.find(titleQuery, projection) .skip(skip) .limit(pageSize) .maxTimeMS(5000) .exec(); - const totalBrews = await HomebrewModel.countDocuments(titleQuery).maxTimeMS(5000); - - const totalPages = Math.ceil(totalBrews / pageSize); - //console.log('Total brews: ', totalBrews); - //console.log('Total pages: ', totalPages); - return res.json({ brews, page, totalPages, totalBrews}); - } catch (error) { - console.error(error); + const totalBrews = await HomebrewModel.countDocuments( + titleQuery + ).maxTimeMS(5000); + + const totalPages = Math.ceil(totalBrews / pageSize); + console.log('Total brews: ', totalBrews); + console.log('Total pages: ', totalPages); + return res.json({ brews, page, totalPages, totalBrews }); + } catch (error) { + console.error(error); if (error.response && error.response.status === 503) { - return res.status(503).json({ errorCode: '503', message: 'Service Unavailable' }); + return res + .status(503) + .json({ errorCode: '503', message: 'Service Unavailable' }); } else { - return res.status(500).json({ errorCode: '500', message: 'Internal Server Error' }); + return res.status(500).json({ + errorCode: '500', + message: 'Internal Server Error', + }); } - } - } + } + }, }; router.get('/api/archive', asyncHandler(archive.findBrews)); -module.exports = router; \ No newline at end of file +module.exports = router; From 51fcb59f095eae8722052d2c9ed711c85e150b66 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?V=C3=ADctor=20Losada=20Hern=C3=A1ndez?= Date: Mon, 6 May 2024 23:26:02 +0200 Subject: [PATCH 073/252] debugging 500 errir catching --- client/homebrew/pages/archivePage/archivePage.jsx | 1 + server/archive.api.js | 1 + 2 files changed, 2 insertions(+) diff --git a/client/homebrew/pages/archivePage/archivePage.jsx b/client/homebrew/pages/archivePage/archivePage.jsx index 9228d1a33..90d9104a0 100644 --- a/client/homebrew/pages/archivePage/archivePage.jsx +++ b/client/homebrew/pages/archivePage/archivePage.jsx @@ -249,6 +249,7 @@ const ArchivePage = createClass({ }, renderFoundBrews() { + console.table(this.state); const { title, brewCollection, page, totalPages, error, searching } = this.state; if(searching) { diff --git a/server/archive.api.js b/server/archive.api.js index 578004fc0..9fa87eb80 100644 --- a/server/archive.api.js +++ b/server/archive.api.js @@ -88,6 +88,7 @@ const archive = { return res.json({ brews, page, totalPages, totalBrews }); } catch (error) { console.error(error); + console.log('error status number: ', error.response.status); if (error.response && error.response.status === 503) { return res .status(503) From ded78c66399b473843e771dacff096d0b1b8059b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?V=C3=ADctor=20Losada=20Hern=C3=A1ndez?= Date: Mon, 6 May 2024 23:32:18 +0200 Subject: [PATCH 074/252] better error handling in jsx --- .../pages/archivePage/archivePage.jsx | 22 +++++++++++-------- 1 file changed, 13 insertions(+), 9 deletions(-) diff --git a/client/homebrew/pages/archivePage/archivePage.jsx b/client/homebrew/pages/archivePage/archivePage.jsx index 90d9104a0..4dc921fd3 100644 --- a/client/homebrew/pages/archivePage/archivePage.jsx +++ b/client/homebrew/pages/archivePage/archivePage.jsx @@ -263,24 +263,19 @@ const ArchivePage = createClass({ if(title === '') {return (

    Whenever you want, just start typing...

    );} - if (!brewCollection || brewCollection.length === 0) { - return ( -
    -

    No brews found

    -
    - ); - }; + if (error) { console.log('render Error: ', error); let errorMessage; switch (error.errorCode) { case '404': - errorMessage = "We didn't find any brew"; + errorMessage = "404 - We didn't find any brew"; break; case '503': - errorMessage = 'Your search is not specific enough. Too many brews meet this criteria for us to display them.'; + errorMessage = ' 503 - Your search is not specific enough. Too many brews meet this criteria for us to display them.'; break; case '500': + errorMessage = "500 - We don't know what happened." default: errorMessage = 'An unexpected error occurred'; } @@ -291,6 +286,15 @@ const ArchivePage = createClass({
    ); }; + + if (!brewCollection || brewCollection.length === 0) { + return ( +
    +

    No brews found

    +
    + ); + }; + From f1a2037bca76c89f48ea1e5fff81e2b3ff378317 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?V=C3=ADctor=20Losada=20Hern=C3=A1ndez?= Date: Mon, 6 May 2024 23:40:31 +0200 Subject: [PATCH 075/252] page is sometimes a string?? --- client/homebrew/pages/archivePage/archivePage.jsx | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/client/homebrew/pages/archivePage/archivePage.jsx b/client/homebrew/pages/archivePage/archivePage.jsx index 4dc921fd3..37923dd5d 100644 --- a/client/homebrew/pages/archivePage/archivePage.jsx +++ b/client/homebrew/pages/archivePage/archivePage.jsx @@ -29,7 +29,7 @@ const ArchivePage = createClass({ legacy : `${this.props.query.legacy === 'false' ? false : true }`, v3 : `${this.props.query.v3 === 'false' ? false : true }`, pageSize : this.props.query.size || 10, - page : this.props.query.page || 1, + page : parseInt(this.props.query.page) || 1, //response brewCollection : null, @@ -50,7 +50,7 @@ const ArchivePage = createClass({ updateStateWithBrews : function (brews, page, totalPages, totalBrews) { this.setState({ brewCollection : brews || null, - page : page || 1, + page : parseInt(page) || 1, totalPages : totalPages || 1, totalBrews : totalBrews, searching : false @@ -293,10 +293,7 @@ const ArchivePage = createClass({

    No brews found

    ); - }; - - - + }; return (
    From f9f2e604c07e536811f01bb957ecaaa1a5865cd8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?V=C3=ADctor=20Losada=20Hern=C3=A1ndez?= Date: Tue, 7 May 2024 10:14:46 +0200 Subject: [PATCH 076/252] linting and remove async conflict --- .../pages/archivePage/archivePage.jsx | 617 ++++++++++-------- server/archive.api.js | 31 +- 2 files changed, 353 insertions(+), 295 deletions(-) diff --git a/client/homebrew/pages/archivePage/archivePage.jsx b/client/homebrew/pages/archivePage/archivePage.jsx index 37923dd5d..9f5068a28 100644 --- a/client/homebrew/pages/archivePage/archivePage.jsx +++ b/client/homebrew/pages/archivePage/archivePage.jsx @@ -1,197 +1,203 @@ require('./archivePage.less'); -const React = require('react'); +const React = require('react'); const createClass = require('create-react-class'); -const _ = require('lodash'); -const cx = require('classnames'); +const _ = require('lodash'); +const cx = require('classnames'); -const Nav = require('naturalcrit/nav/nav.jsx'); -const Navbar = require('../../navbar/navbar.jsx'); +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 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 StringArrayEditor = require('../stringArrayEditor/stringArrayEditor.jsx'); const request = require('../../utils/request-middleware.js'); const ArchivePage = createClass({ - displayName : 'ArchivePage', - getDefaultProps : function () { - return {}; - }, - getInitialState : function () { - return { - //request - title : this.props.query.title || '', - //tags : {}, - legacy : `${this.props.query.legacy === 'false' ? false : true }`, - v3 : `${this.props.query.v3 === 'false' ? false : true }`, - pageSize : this.props.query.size || 10, - page : parseInt(this.props.query.page) || 1, + displayName: 'ArchivePage', + getDefaultProps: function () { + return {}; + }, + getInitialState: function () { + return { + //request + title: this.props.query.title || '', + //tags : {}, + legacy: `${this.props.query.legacy === 'false' ? false : true}`, + v3: `${this.props.query.v3 === 'false' ? false : true}`, + pageSize: this.props.query.size || 10, + page: parseInt(this.props.query.page) || 1, - //response - brewCollection : null, - totalPages : null, - totalBrews : null, + //response + brewCollection: null, + totalPages: null, + totalBrews: null, - searching : false, - error : null, - }; - }, - componentDidMount : function() { - if (this.state.title !== '') { - this.loadPage(this.state.page, false); - } - - }, + searching: false, + error: null, + }; + }, + componentDidMount: function () { + if (this.state.title !== '') { + this.loadPage(this.state.page, false); + } + }, - updateStateWithBrews : function (brews, page, totalPages, totalBrews) { - this.setState({ - brewCollection : brews || null, - page : parseInt(page) || 1, - totalPages : totalPages || 1, - totalBrews : totalBrews, - searching : false - }); - }, + updateStateWithBrews: function (brews, page, totalPages, totalBrews) { + this.setState({ + brewCollection: brews || null, + page: parseInt(page) || 1, + totalPages: totalPages || 1, + totalBrews: totalBrews, + searching: false, + }); + }, - updateStateWithForm : function() { - const title = document.getElementById( 'title' ).value || ""; - const size = document.getElementById( 'size' ).value || 10; - const page = 1; - const v3 = document.getElementById('v3').checked; - const legacy = document.getElementById('legacy').checked; + updateUrl: function (title, page, size, v3, legacy) { + const url = new URL(window.location.href); + const urlParams = new URLSearchParams(url.search); - this.setState({ - title: title, - pageSize: size, - v3: v3, - legacy: legacy - }); - this.updateUrl(title, page, size, v3, legacy); - }, + //clean all params + urlParams.delete('title'); + urlParams.delete('page'); + urlParams.delete('size'); + urlParams.delete('v3'); + urlParams.delete('legacy'); + urlParams.set('title', title); + urlParams.set('page', page); + urlParams.set('size', size); + urlParams.set('v3', v3); + urlParams.set('legacy', legacy); - updateUrl : function(title, page, size, v3, legacy) { - const url = new URL(window.location.href); - const urlParams = new URLSearchParams(url.search); + url.search = urlParams.toString(); // Convert URLSearchParams to string + window.history.replaceState(null, null, url); + }, - //clean all params - urlParams.delete('title'); - urlParams.delete('page'); - urlParams.delete('size'); - urlParams.delete('v3'); - urlParams.delete('legacy'); - - urlParams.set('title', title); - urlParams.set('page', page); - urlParams.set('size', size); - urlParams.set('v3', v3); - urlParams.set('legacy', legacy); - + loadPage: async function (page, update) { + //load form data directly + const title = document.getElementById('title').value || ''; + const size = document.getElementById('size').value || 10; + const v3 = document.getElementById('v3').checked; + const legacy = document.getElementById('legacy').checked; - url.search = urlParams.toString(); // Convert URLSearchParams to string - window.history.replaceState(null, null, url); - }, + // Update state with form data for later, only when first page + if (update === true) { + this.setState({ + title: title, + pageSize: size, + v3: v3, + legacy: legacy, + }); + this.updateUrl(title, page, size, v3, legacy); + } - loadPage : async function(page, update) { - if(update === true) { - this.updateStateWithForm(); - }; - if (title !== '') { - try { - this.setState({ searching: true, error: null }); - - const title = encodeURIComponent(this.state.title); - const size = parseInt(this.state.pageSize); - const {legacy, v3} = this.state; - await request.get(`/api/archive?title=${title}&page=${page}&size=${size}&v3=${v3}&legacy=${legacy}`) - .then((response)=>{ - if(response.ok) { - this.updateStateWithBrews(response.body.brews, page, response.body.totalPages, response.body.totalBrews); - } - }); - } catch (error) { - this.setState({ error: `${error.response.status}` }) - this.updateStateWithBrews([], 1, 1, 0); - } - console.log(!this.state.brewCollection || brewCollection.length === 0); - if(!this.state.brewCollection) { - this.setState({ error: '404'}); - } - } - - }, + if (title !== '') { + try { + this.setState({ searching: true, error: null }); - renderNavItems : function () { - return ( - - - Archive: Search for brews - - - - - - - - - ); - }, + await request + .get( + `/api/archive?title=${title}&page=${page}&size=${size}&v3=${v3}&legacy=${legacy}` + ) + .then((response) => { + if (response.ok) { + this.updateStateWithBrews( + response.body.brews, + page, + response.body.totalPages, + response.body.totalBrews + ); + } + }); + } catch (error) { + this.setState({ error: `${error.response.status}` }); + this.updateStateWithBrews([], 1, 1, 0); + } + console.log('a', + !this.state.brewCollection || brewCollection.length === 0 + ); + if (!this.state.brewCollection) { + this.setState({ error: '404' }); + } + } - renderForm : function () { - return ( -
    -

    Brew Lookup

    -
    - - - + + }, - + renderNavItems: function () { + return ( + + + + Archive: Search for brews + + + + + + + + + + ); + }, - - + renderForm: function () { + return ( +
    +

    Brew Lookup

    +
    + - {/* In the future, we should be able to filter the results by adding tags. + + + + + + + {/* In the future, we should be able to filter the results by adding tags. <{ - this.loadPage(1, true); - }}> - Search - - -
    -
    - ); - }, + +
    +
    + ); + }, - renderPaginationControls() { - const title = encodeURIComponent(this.state.title); - const size = parseInt(this.state.pageSize); - const {page, totalPages, legacy, v3} = this.state; - const pages = new Array(totalPages).fill().map((_, index) => ( - {index + 1} - )); - - if(totalPages === null) {return;} - - return ( -
    - {page > 1 && ( - - )} -
      {pages}
    - {page < totalPages && ( - - )} -
    - ); - }, + renderPaginationControls() { + const title = encodeURIComponent(this.state.title); + const size = parseInt(this.state.pageSize); + const { page, totalPages, legacy, v3 } = this.state; + const pages = new Array(totalPages).fill().map((_, index) => ( + + {index + 1} + + )); - renderFoundBrews() { - console.table(this.state); - const { title, brewCollection, page, totalPages, error, searching } = this.state; - - if(searching) { - return ( -
    -

    Searching

    -
    - ); - }; + if (totalPages === null) { + return; + } + return ( +
    + {page > 1 && ( + + )} +
      {pages}
    + {page < totalPages && ( + + )} +
    + ); + }, + renderFoundBrews() { + console.log('State when rendering:'); + console.table(this.state); + const { title, brewCollection, page, totalPages, error, searching } = + this.state; - if(title === '') {return (

    Whenever you want, just start typing...

    );} + if (searching) { + return ( +
    +

    Searching

    +
    + ); + } - if (error) { - console.log('render Error: ', error); - let errorMessage; - switch (error.errorCode) { - case '404': - errorMessage = "404 - We didn't find any brew"; - break; - case '503': - errorMessage = ' 503 - Your search is not specific enough. Too many brews meet this criteria for us to display them.'; - break; - case '500': - errorMessage = "500 - We don't know what happened." - default: - errorMessage = 'An unexpected error occurred'; - } - - return ( -
    -

    Error: {errorMessage}

    -
    - ); - }; + if (title === '') { + return ( +
    +

    Whenever you want, just start typing...

    +
    + ); + } - if (!brewCollection || brewCollection.length === 0) { - return ( -
    -

    No brews found

    -
    - ); - }; - - return ( -
    - Brews found: {this.state.totalBrews} - {brewCollection.map((brew, index)=>( - - ))} - {this.renderPaginationControls()} -
    - ); - }, + if (error) { + console.log('render Error: ', error); + let errorMessage; + switch (error.errorCode) { + case '404': + errorMessage = "404 - We didn't find any brew"; + break; + case '503': + errorMessage = + ' 503 - Your search is not specific enough. Too many brews meet this criteria for us to display them.'; + break; + case '500': + errorMessage = "500 - We don't know what happened."; + default: + errorMessage = 'An unexpected error occurred'; + } - render : function () { - return ( -
    - - - {this.renderNavItems()} + return ( +
    +

    Error: {errorMessage}

    +
    + ); + } -
    -
    -

    Welcome to the Archive

    -
    -
    -
    {this.renderForm()}
    -
    -
    -

    Your results, my lordship

    -
    - {this.renderFoundBrews()} -
    -
    -
    -
    - ); - }, + if (!brewCollection || brewCollection.length === 0) { + return ( +
    +

    No brews found

    +
    + ); + } + + return ( +
    + + Brews found: {this.state.totalBrews} + + {brewCollection.map((brew, index) => ( + + ))} + {this.renderPaginationControls()} +
    + ); + }, + + render: function () { + return ( +
    + + + {this.renderNavItems()} + +
    +
    +

    Welcome to the Archive

    +
    +
    +
    + {this.renderForm()} +
    +
    +
    +

    Your results, my lordship

    +
    + {this.renderFoundBrews()} +
    +
    +
    +
    + ); + }, }); module.exports = ArchivePage; diff --git a/server/archive.api.js b/server/archive.api.js index 9fa87eb80..ee1be4b7a 100644 --- a/server/archive.api.js +++ b/server/archive.api.js @@ -8,12 +8,18 @@ const archive = { findBrews: async (req, res, next) => { try { /* + //log db name and collection name, for local purposes const dbName = HomebrewModel.db.name; console.log("Database Name:", dbName); const collectionName = HomebrewModel.collection.name; console.log("Collection Name:", collectionName); */ + + const bright = '\x1b[1m'; // Bright (bold) style + const yellow = '\x1b[93m'; // yellow color + const reset = '\x1b[0m'; // Reset to default style + console.log(`Query as received in ${bright + yellow}archive api${reset}:`); console.table(req.query); const title = req.query.title || ''; @@ -88,11 +94,26 @@ const archive = { return res.json({ brews, page, totalPages, totalBrews }); } catch (error) { console.error(error); - console.log('error status number: ', error.response.status); - if (error.response && error.response.status === 503) { - return res - .status(503) - .json({ errorCode: '503', message: 'Service Unavailable' }); + + if (error.response && error.response.status) { + const status = error.response.status; + + if (status === 500) { + return res.status(500).json({ + errorCode: '500', + message: 'Internal Server Error', + }); + } else if (status === 503) { + return res.status(503).json({ + errorCode: '503', + message: 'Service Unavailable', + }); + } else { + return res.status(status).json({ + errorCode: status.toString(), + message: 'Internal Server Error', + }); + } } else { return res.status(500).json({ errorCode: '500', From 02450982c180fd0f0250523ed741c3f957885c05 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?V=C3=ADctor=20Losada=20Hern=C3=A1ndez?= Date: Wed, 8 May 2024 13:32:03 +0200 Subject: [PATCH 077/252] fix brewCollection issue --- client/homebrew/pages/archivePage/archivePage.jsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/client/homebrew/pages/archivePage/archivePage.jsx b/client/homebrew/pages/archivePage/archivePage.jsx index 9f5068a28..7edb5c807 100644 --- a/client/homebrew/pages/archivePage/archivePage.jsx +++ b/client/homebrew/pages/archivePage/archivePage.jsx @@ -118,7 +118,7 @@ const ArchivePage = createClass({ this.updateStateWithBrews([], 1, 1, 0); } console.log('a', - !this.state.brewCollection || brewCollection.length === 0 + !this.state.brewCollection || this.state.brewCollection.length === 0 ); if (!this.state.brewCollection) { this.setState({ error: '404' }); From 9966e6322d525aee7c813b9b5cdfbe2ea7ae7b1b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?V=C3=ADctor=20Losada=20Hern=C3=A1ndez?= Date: Wed, 8 May 2024 15:33:27 +0200 Subject: [PATCH 078/252] pagination controls update search terms --- client/homebrew/pages/archivePage/archivePage.jsx | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/client/homebrew/pages/archivePage/archivePage.jsx b/client/homebrew/pages/archivePage/archivePage.jsx index 7edb5c807..4ac2e4a35 100644 --- a/client/homebrew/pages/archivePage/archivePage.jsx +++ b/client/homebrew/pages/archivePage/archivePage.jsx @@ -117,7 +117,7 @@ const ArchivePage = createClass({ this.setState({ error: `${error.response.status}` }); this.updateStateWithBrews([], 1, 1, 0); } - console.log('a', + console.log("We've come up empty", !this.state.brewCollection || this.state.brewCollection.length === 0 ); if (!this.state.brewCollection) { @@ -252,7 +252,7 @@ const ArchivePage = createClass({ {page > 1 && ( @@ -261,7 +261,7 @@ const ArchivePage = createClass({ {page < totalPages && ( From e30a0c3dce518f4cf8c18068795fe4283b8058e3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?V=C3=ADctor=20Losada=20Hern=C3=A1ndez?= Date: Wed, 8 May 2024 15:41:44 +0200 Subject: [PATCH 079/252] page size log to track issue --- client/homebrew/pages/archivePage/archivePage.jsx | 1 + 1 file changed, 1 insertion(+) diff --git a/client/homebrew/pages/archivePage/archivePage.jsx b/client/homebrew/pages/archivePage/archivePage.jsx index 4ac2e4a35..4f2ea2ca9 100644 --- a/client/homebrew/pages/archivePage/archivePage.jsx +++ b/client/homebrew/pages/archivePage/archivePage.jsx @@ -96,6 +96,7 @@ const ArchivePage = createClass({ } if (title !== '') { + console.log('pagesize when querying: ', this.state.pageSize); try { this.setState({ searching: true, error: null }); From 22f4dade4fa3ed58021fc2da30545cce8fb67f71 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?V=C3=ADctor=20Losada=20Hern=C3=A1ndez?= Date: Wed, 8 May 2024 15:51:14 +0200 Subject: [PATCH 080/252] default value to page size --- client/homebrew/pages/archivePage/archivePage.jsx | 1 + 1 file changed, 1 insertion(+) diff --git a/client/homebrew/pages/archivePage/archivePage.jsx b/client/homebrew/pages/archivePage/archivePage.jsx index 4f2ea2ca9..76f89bc5c 100644 --- a/client/homebrew/pages/archivePage/archivePage.jsx +++ b/client/homebrew/pages/archivePage/archivePage.jsx @@ -176,6 +176,7 @@ const ArchivePage = createClass({ min="6" step="2" max="30" + defaultValue={this.state.pageSize} name="pageSize" /> From cca0f3b4dc2297c236367b895ecaddc72e4b89df Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?V=C3=ADctor=20Losada=20Hern=C3=A1ndez?= Date: Wed, 8 May 2024 15:51:31 +0200 Subject: [PATCH 081/252] Revert "pagination controls update search terms" This reverts commit 9966e6322d525aee7c813b9b5cdfbe2ea7ae7b1b. --- client/homebrew/pages/archivePage/archivePage.jsx | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/client/homebrew/pages/archivePage/archivePage.jsx b/client/homebrew/pages/archivePage/archivePage.jsx index 76f89bc5c..eb8e78cc7 100644 --- a/client/homebrew/pages/archivePage/archivePage.jsx +++ b/client/homebrew/pages/archivePage/archivePage.jsx @@ -118,7 +118,7 @@ const ArchivePage = createClass({ this.setState({ error: `${error.response.status}` }); this.updateStateWithBrews([], 1, 1, 0); } - console.log("We've come up empty", + console.log('a', !this.state.brewCollection || this.state.brewCollection.length === 0 ); if (!this.state.brewCollection) { @@ -254,7 +254,7 @@ const ArchivePage = createClass({ {page > 1 && ( @@ -263,7 +263,7 @@ const ArchivePage = createClass({ {page < totalPages && ( From 5eeac603db2e51fd4c59047c249e0c4c9ad9ef8a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?V=C3=ADctor=20Losada=20Hern=C3=A1ndez?= Date: Thu, 9 May 2024 08:24:27 +0200 Subject: [PATCH 082/252] why didn't i think about this sooner --- server/archive.api.js | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/server/archive.api.js b/server/archive.api.js index ee1be4b7a..a38eb269e 100644 --- a/server/archive.api.js +++ b/server/archive.api.js @@ -84,9 +84,7 @@ const archive = { .maxTimeMS(5000) .exec(); - const totalBrews = await HomebrewModel.countDocuments( - titleQuery - ).maxTimeMS(5000); + const totalBrews = brews.length; const totalPages = Math.ceil(totalBrews / pageSize); console.log('Total brews: ', totalBrews); From a89b575b267beccaaaa07cbd53d8962d7f7f2715 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?V=C3=ADctor=20Losada=20Hern=C3=A1ndez?= Date: Mon, 13 May 2024 13:37:53 +0200 Subject: [PATCH 083/252] archive 2.0 --- .../pages/archivePage/archivePage.jsx | 168 ++++++++++-------- server/admin.api.js | 2 - server/archive.api.js | 94 ++++++++-- themes/themes.json | 4 +- 4 files changed, 183 insertions(+), 85 deletions(-) diff --git a/client/homebrew/pages/archivePage/archivePage.jsx b/client/homebrew/pages/archivePage/archivePage.jsx index eb8e78cc7..71e47f965 100644 --- a/client/homebrew/pages/archivePage/archivePage.jsx +++ b/client/homebrew/pages/archivePage/archivePage.jsx @@ -21,37 +21,37 @@ const ArchivePage = createClass({ getDefaultProps: function () { return {}; }, + getInitialState: function () { return { - //request + //# request title: this.props.query.title || '', - //tags : {}, + //tags: {}, legacy: `${this.props.query.legacy === 'false' ? false : true}`, v3: `${this.props.query.v3 === 'false' ? false : true}`, pageSize: this.props.query.size || 10, page: parseInt(this.props.query.page) || 1, - //response + //# response brewCollection: null, - totalPages: null, totalBrews: null, searching: false, error: null, }; }, + componentDidMount: function () { if (this.state.title !== '') { this.loadPage(this.state.page, false); } + this.state.totalBrews || this.loadTotal(); // Load total if not already loaded }, - updateStateWithBrews: function (brews, page, totalPages, totalBrews) { + updateStateWithBrews: function (brews, page) { this.setState({ brewCollection: brews || null, page: parseInt(page) || 1, - totalPages: totalPages || 1, - totalBrews: totalBrews, searching: false, }); }, @@ -78,6 +78,7 @@ const ArchivePage = createClass({ }, loadPage: async function (page, update) { + console.log('running loadPage'); //load form data directly const title = document.getElementById('title').value || ''; const size = document.getElementById('size').value || 10; @@ -96,46 +97,58 @@ const ArchivePage = createClass({ } if (title !== '') { - console.log('pagesize when querying: ', this.state.pageSize); try { this.setState({ searching: true, error: null }); - await request - .get( - `/api/archive?title=${title}&page=${page}&size=${size}&v3=${v3}&legacy=${legacy}` - ) - .then((response) => { - if (response.ok) { - this.updateStateWithBrews( - response.body.brews, - page, - response.body.totalPages, - response.body.totalBrews - ); - } - }); + await request.get( + `/api/archive?title=${title}&page=${page}&size=${size}&v3=${v3}&legacy=${legacy}` + ).then((response) => { + if (response.ok) { + this.updateStateWithBrews( + response.body.brews, + page + ); + } + }); } catch (error) { + console.log('error at loadPage: ', error); this.setState({ error: `${error.response.status}` }); - this.updateStateWithBrews([], 1, 1, 0); + this.updateStateWithBrews([], 1); } - console.log('a', - !this.state.brewCollection || this.state.brewCollection.length === 0 - ); if (!this.state.brewCollection) { this.setState({ error: '404' }); } } + }, - + loadTotal: async function () { + console.log('running loadTotal'); + const {title, v3, legacy} = this.state; + + if (title !== '') { + + try { + await request + .get( + `/api/archive/total?title=${title}&v3=${v3}&legacy=${legacy}` + ).then((response) => { + if (response.ok) { + this.setState({totalBrews : response.body.totalBrews}); + } + }); + } catch (error) { + console.log('error at loadTotal: ', error); + this.setState({ error: `${error.response.status}` }); + this.updateStateWithBrews([], 1); + } + } }, renderNavItems: function () { return ( - - Archive: Search for brews - + Archive: Search for brews @@ -161,6 +174,7 @@ const ArchivePage = createClass({ defaultValue={this.state.title} onKeyDown={(e) => { if (e.key === 'Enter') { + this.loadTotal(); this.loadPage(1, true); } }} @@ -211,6 +225,7 @@ const ArchivePage = createClass({ + )} +
      {pages}
    + {page < totalPages && ( + + )} +
    + ); + } else { return;} - return ( -
    - {page > 1 && ( - - )} -
      {pages}
    - {page < totalPages && ( - - )} -
    - ); + }, renderFoundBrews() { console.log('State when rendering:'); - console.table(this.state); + const stateWithoutBrewCollection = { ...this.state }; + delete stateWithoutBrewCollection.brewCollection; + console.table(stateWithoutBrewCollection); + console.table(this.state.brewCollection); + const { title, brewCollection, page, totalPages, error, searching } = this.state; diff --git a/server/admin.api.js b/server/admin.api.js index 626e63d68..5ddba0902 100644 --- a/server/admin.api.js +++ b/server/admin.api.js @@ -100,7 +100,6 @@ router.get('/admin/finduncompressed', mw.adminOnly, (req, res)=>{ }); }); - /* Compresses the "text" field of a brew to binary */ router.put('/admin/compress/:id', (req, res)=>{ HomebrewModel.findOne({ _id: req.params.id }) @@ -122,7 +121,6 @@ router.put('/admin/compress/:id', (req, res)=>{ }); }); - router.get('/admin/stats', mw.adminOnly, async (req, res)=>{ try { const totalBrewsCount = await HomebrewModel.countDocuments({}); diff --git a/server/archive.api.js b/server/archive.api.js index a38eb269e..4643e7181 100644 --- a/server/archive.api.js +++ b/server/archive.api.js @@ -3,7 +3,6 @@ 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 { @@ -17,9 +16,11 @@ const archive = { */ const bright = '\x1b[1m'; // Bright (bold) style - const yellow = '\x1b[93m'; // yellow color + const yellow = '\x1b[93m'; // yellow color const reset = '\x1b[0m'; // Reset to default style - console.log(`Query as received in ${bright + yellow}archive api${reset}:`); + console.log( + `Query as received in ${bright + yellow}archive api${reset}:` + ); console.table(req.query); const title = req.query.title || ''; @@ -84,18 +85,90 @@ const archive = { .maxTimeMS(5000) .exec(); - const totalBrews = brews.length; + return res.json({ brews, page}); - const totalPages = Math.ceil(totalBrews / pageSize); - console.log('Total brews: ', totalBrews); - console.log('Total pages: ', totalPages); - return res.json({ brews, page, totalPages, totalBrews }); } catch (error) { console.error(error); - + if (error.response && error.response.status) { const status = error.response.status; - + + if (status === 500) { + return res.status(500).json({ + errorCode: '500', + message: 'Internal Server Error', + }); + } else if (status === 503) { + return res.status(503).json({ + errorCode: '503', + message: 'Service Unavailable', + }); + } else { + return res.status(status).json({ + errorCode: status.toString(), + message: 'Internal Server Error', + }); + } + } else { + return res.status(500).json({ + errorCode: '500', + message: 'Internal Server Error', + }); + } + } + }, + findTotal: async (req, res) => { + try { + const title = req.query.title || ''; + + const brewsQuery = { + $or: [], + published: true, + }; + if (req.query.legacy === 'true') { + brewsQuery.$or.push({ renderer: 'legacy' }); + } + if (req.query.v3 === 'true') { + brewsQuery.$or.push({ renderer: 'V3' }); + } + // If user wants to use RegEx it needs to format like /text/ + const titleConditionsArray = + title.startsWith('/') && title.endsWith('/') + ? [ + { + 'title': { + $regex: title.slice(1, -1), + $options: 'i', + }, + }, + ] + : buildTitleConditions(title); + + function buildTitleConditions(inputString) { + return [ + { + $text: { + $search: inputString, + $caseSensitive: false, + }, + }, + ]; + } + const titleQuery = { + $and: [brewsQuery, ...titleConditionsArray], + }; + console.table(req.query); + + const totalBrews = await HomebrewModel.countDocuments(titleQuery); + + return res.json({totalBrews}); + + } catch (error) { + console.error(error); + + if (error.response && error.response.status) { + const status = error.response.status; + if (status === 500) { return res.status(500).json({ errorCode: '500', @@ -122,6 +195,7 @@ const archive = { }, }; +router.get('/api/archive/total', asyncHandler(archive.findTotal)); router.get('/api/archive', asyncHandler(archive.findBrews)); module.exports = router; diff --git a/themes/themes.json b/themes/themes.json index 0d28c7394..bc719185d 100644 --- a/themes/themes.json +++ b/themes/themes.json @@ -29,12 +29,12 @@ "baseSnippets": false, "path": "Blank" }, - "Journal": { + "journal": { "name": "Journal", "renderer": "V3", "baseTheme": false, "baseSnippets": "5ePHB", - "path": "Journal" + "path": "journal" } } } \ No newline at end of file From e23166e1d5da8bf95047a4844a9430051479edee Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?V=C3=ADctor=20Losada=20Hern=C3=A1ndez?= Date: Tue, 14 May 2024 09:31:22 +0200 Subject: [PATCH 084/252] when did i change this? --- themes/themes.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/themes/themes.json b/themes/themes.json index bc719185d..cb0c5593e 100644 --- a/themes/themes.json +++ b/themes/themes.json @@ -34,7 +34,7 @@ "renderer": "V3", "baseTheme": false, "baseSnippets": "5ePHB", - "path": "journal" + "path": "Journal" } } } \ No newline at end of file From 153812c6e57d599f8c174050231fc104f11dc6bd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?V=C3=ADctor=20Losada=20Hern=C3=A1ndez?= Date: Tue, 14 May 2024 09:36:59 +0200 Subject: [PATCH 085/252] simplify console log and remove unused code --- server/archive.api.js | 16 +--------------- 1 file changed, 1 insertion(+), 15 deletions(-) diff --git a/server/archive.api.js b/server/archive.api.js index 4643e7181..36aa93429 100644 --- a/server/archive.api.js +++ b/server/archive.api.js @@ -6,21 +6,7 @@ const archive = { /* Searches for matching title, also attempts to partial match */ findBrews: async (req, res, next) => { try { - /* - //log db name and collection name, for local purposes - const dbName = HomebrewModel.db.name; - console.log("Database Name:", dbName); - const collectionName = HomebrewModel.collection.name; - console.log("Collection Name:", collectionName); - - */ - - const bright = '\x1b[1m'; // Bright (bold) style - const yellow = '\x1b[93m'; // yellow color - const reset = '\x1b[0m'; // Reset to default style - console.log( - `Query as received in ${bright + yellow}archive api${reset}:` - ); + console.log(`Query as received in archive api:`); console.table(req.query); const title = req.query.title || ''; From 4b10686336e4b2f2963c8cb1b306f201b689c047 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?V=C3=ADctor=20Losada=20Hern=C3=A1ndez?= Date: Tue, 14 May 2024 09:49:14 +0200 Subject: [PATCH 086/252] simplify logic --- server/archive.api.js | 202 ++++++++++++++++-------------------------- 1 file changed, 74 insertions(+), 128 deletions(-) diff --git a/server/archive.api.js b/server/archive.api.js index 36aa93429..e9e118152 100644 --- a/server/archive.api.js +++ b/server/archive.api.js @@ -2,8 +2,72 @@ const HomebrewModel = require('./homebrew.model.js').model; const router = require('express').Router(); const asyncHandler = require('express-async-handler'); +const buildTitleConditionsArray = (title) => { + if (title.startsWith('/') && title.endsWith('/')) { + return [ + { + title: { + $regex: title.slice(1, -1), + $options: 'i', + }, + }, + ]; + } else { + return buildTitleConditions(title); + } +}; + +const buildTitleConditions = (inputString) => { + return [ + { + $text: { + $search: inputString, + $caseSensitive: false, + }, + }, + ]; +}; + +const handleErrorResponse = (res, error, functionName) => { + let status; + let message; + + if (error.response && error.response.status) { + status = error.response.status; + } else { + status = 500; + } + + if (status === 503) { + message = 'Service Unavailable'; + } else { + message = 'Internal Server Error'; + } + + return res.status(status).json({ + errorCode: status.toString(), + message: `Error in function ${functionName}: ${message}`, + }); +}; + +const buildBrewsQuery = (legacy, v3) => { + const brewsQuery = { + $or: [], + published: true, + }; + + if (legacy === 'true') { + brewsQuery.$or.push({ renderer: 'legacy' }); + } + + if (v3 === 'true') { + brewsQuery.$or.push({ renderer: 'V3' }); + } + + return brewsQuery; +}; + const archive = { - /* Searches for matching title, also attempts to partial match */ findBrews: async (req, res, next) => { try { console.log(`Query as received in archive api:`); @@ -12,48 +76,11 @@ const archive = { const title = req.query.title || ''; const page = Math.max(parseInt(req.query.page) || 1, 1); const minPageSize = 6; - const pageSize = Math.max( - parseInt(req.query.size) || 10, - minPageSize - ); + const pageSize = Math.max(parseInt(req.query.size) || 10, minPageSize); const skip = (page - 1) * pageSize; - const brewsQuery = { - $or: [], - published: true, - }; - - if (req.query.legacy === 'true') { - brewsQuery.$or.push({ renderer: 'legacy' }); - } - - if (req.query.v3 === 'true') { - brewsQuery.$or.push({ renderer: 'V3' }); - } - - // If user wants to use RegEx it needs to format like /text/ - const titleConditionsArray = - title.startsWith('/') && title.endsWith('/') - ? [ - { - 'title': { - $regex: title.slice(1, -1), - $options: 'i', - }, - }, - ] - : buildTitleConditions(title); - - function buildTitleConditions(inputString) { - return [ - { - $text: { - $search: inputString, - $caseSensitive: false, - }, - }, - ]; - } + const brewsQuery = buildBrewsQuery(req.query.legacy, req.query.v3); + const titleConditionsArray = buildTitleConditionsArray(title); const titleQuery = { $and: [brewsQuery, ...titleConditionsArray], @@ -71,112 +98,31 @@ const archive = { .maxTimeMS(5000) .exec(); - return res.json({ brews, page}); + return res.json({ brews, page }); } catch (error) { console.error(error); - - if (error.response && error.response.status) { - const status = error.response.status; - - if (status === 500) { - return res.status(500).json({ - errorCode: '500', - message: 'Internal Server Error', - }); - } else if (status === 503) { - return res.status(503).json({ - errorCode: '503', - message: 'Service Unavailable', - }); - } else { - return res.status(status).json({ - errorCode: status.toString(), - message: 'Internal Server Error', - }); - } - } else { - return res.status(500).json({ - errorCode: '500', - message: 'Internal Server Error', - }); - } + return handleErrorResponse(res, error, 'findBrews'); } }, findTotal: async (req, res) => { try { const title = req.query.title || ''; - const brewsQuery = { - $or: [], - published: true, - }; - if (req.query.legacy === 'true') { - brewsQuery.$or.push({ renderer: 'legacy' }); - } - if (req.query.v3 === 'true') { - brewsQuery.$or.push({ renderer: 'V3' }); - } - // If user wants to use RegEx it needs to format like /text/ - const titleConditionsArray = - title.startsWith('/') && title.endsWith('/') - ? [ - { - 'title': { - $regex: title.slice(1, -1), - $options: 'i', - }, - }, - ] - : buildTitleConditions(title); + const brewsQuery = buildBrewsQuery(req.query.legacy, req.query.v3); + const titleConditionsArray = buildTitleConditionsArray(title); - function buildTitleConditions(inputString) { - return [ - { - $text: { - $search: inputString, - $caseSensitive: false, - }, - }, - ]; - } const titleQuery = { $and: [brewsQuery, ...titleConditionsArray], }; - console.table(req.query); const totalBrews = await HomebrewModel.countDocuments(titleQuery); - return res.json({totalBrews}); + return res.json({ totalBrews }); } catch (error) { console.error(error); - - if (error.response && error.response.status) { - const status = error.response.status; - - if (status === 500) { - return res.status(500).json({ - errorCode: '500', - message: 'Internal Server Error', - }); - } else if (status === 503) { - return res.status(503).json({ - errorCode: '503', - message: 'Service Unavailable', - }); - } else { - return res.status(status).json({ - errorCode: status.toString(), - message: 'Internal Server Error', - }); - } - } else { - return res.status(500).json({ - errorCode: '500', - message: 'Internal Server Error', - }); - } + return handleErrorResponse(res, error, 'findTotal'); } }, }; From 021ac6840064fe9f0a2db31d5c416c3264808f19 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?V=C3=ADctor=20Losada=20Hern=C3=A1ndez?= Date: Tue, 14 May 2024 10:44:16 +0200 Subject: [PATCH 087/252] Update archive page to use pagination with page numbers and ellipses * Change the way pagination is handled on the archive page * Display page links for 10 pages max --- .../pages/archivePage/archivePage.jsx | 112 ++++++++++-------- .../pages/archivePage/archivePage.less | 7 ++ 2 files changed, 70 insertions(+), 49 deletions(-) diff --git a/client/homebrew/pages/archivePage/archivePage.jsx b/client/homebrew/pages/archivePage/archivePage.jsx index 71e47f965..5b444ff58 100644 --- a/client/homebrew/pages/archivePage/archivePage.jsx +++ b/client/homebrew/pages/archivePage/archivePage.jsx @@ -100,16 +100,18 @@ const ArchivePage = createClass({ try { this.setState({ searching: true, error: null }); - await request.get( - `/api/archive?title=${title}&page=${page}&size=${size}&v3=${v3}&legacy=${legacy}` - ).then((response) => { - if (response.ok) { - this.updateStateWithBrews( - response.body.brews, - page - ); - } - }); + await request + .get( + `/api/archive?title=${title}&page=${page}&size=${size}&v3=${v3}&legacy=${legacy}` + ) + .then((response) => { + if (response.ok) { + this.updateStateWithBrews( + response.body.brews, + page + ); + } + }); } catch (error) { console.log('error at loadPage: ', error); this.setState({ error: `${error.response.status}` }); @@ -123,19 +125,21 @@ const ArchivePage = createClass({ loadTotal: async function () { console.log('running loadTotal'); - const {title, v3, legacy} = this.state; + const { title, v3, legacy } = this.state; if (title !== '') { - try { await request - .get( - `/api/archive/total?title=${title}&v3=${v3}&legacy=${legacy}` - ).then((response) => { - if (response.ok) { - this.setState({totalBrews : response.body.totalBrews}); - } - }); + .get( + `/api/archive/total?title=${title}&v3=${v3}&legacy=${legacy}` + ) + .then((response) => { + if (response.ok) { + this.setState({ + totalBrews: response.body.totalBrews, + }); + } + }); } catch (error) { console.log('error at loadTotal: ', error); this.setState({ error: `${error.response.status}` }); @@ -148,7 +152,9 @@ const ArchivePage = createClass({ return ( - Archive: Search for brews + + Archive: Search for brews + @@ -246,28 +252,36 @@ const ArchivePage = createClass({ if (this.state.totalBrews) { const title = encodeURIComponent(this.state.title); const size = parseInt(this.state.pageSize); - const { page, totalBrews} = this.state; + const { page, totalBrews } = this.state; const totalPages = Math.ceil(totalBrews / size); - - const pages = new Array(totalPages).fill().map((_, index) => ( - - {index + 1} - - )); - - if (totalPages === null) { - return; + + let startPage, endPage; + if (page <= 6) { + startPage = 1; + endPage = Math.min(totalPages, 10); + } else if (page + 4 >= totalPages) { + startPage = Math.max(1, totalPages - 9); + endPage = totalPages; + } else { + startPage = page - 5; + endPage = page + 4; } - + + const pagesAroundCurrent = new Array(endPage - startPage + 1) + .fill() + .map((_, index) => ( + this.loadPage(startPage + index, false)} + > + {startPage + index} + + )); + return (
    {page > 1 && ( @@ -278,7 +292,13 @@ const ArchivePage = createClass({ << )} -
      {pages}
    +
      + {startPage > 1 && 1 ...} + {pagesAroundCurrent} + {endPage < totalPages && ( + ... {totalPages} + )} +
    {page < totalPages && ( )}
      - {startPage > 1 && 1 ...} + {startPage > 1 && this.loadPage(1, false)}>1 ...} {pagesAroundCurrent} {endPage < totalPages && ( - ... {totalPages} + this.loadPage(totalPages, false)}>... {totalPages} )}
    {page < totalPages && ( From 97ef56f9056d2d2e8626957da2b21bfc6f7e8944 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?V=C3=ADctor=20Losada=20Hern=C3=A1ndez?= Date: Tue, 14 May 2024 11:10:48 +0200 Subject: [PATCH 089/252] small changes, tips and style --- client/homebrew/pages/archivePage/archivePage.jsx | 3 ++- .../homebrew/pages/archivePage/archivePage.less | 15 +++++++++++++++ 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/client/homebrew/pages/archivePage/archivePage.jsx b/client/homebrew/pages/archivePage/archivePage.jsx index 5708b774b..dac0e9a33 100644 --- a/client/homebrew/pages/archivePage/archivePage.jsx +++ b/client/homebrew/pages/archivePage/archivePage.jsx @@ -187,7 +187,7 @@ const ArchivePage = createClass({ placeholder="v3 Reference Document" /> - + Tip! you can use RegEx if you format your query as /title/
    + Remember, you can only search brews with this tool if they are published
    ); }, diff --git a/client/homebrew/pages/archivePage/archivePage.less b/client/homebrew/pages/archivePage/archivePage.less index 8fcd74610..6f4fc8684 100644 --- a/client/homebrew/pages/archivePage/archivePage.less +++ b/client/homebrew/pages/archivePage/archivePage.less @@ -4,6 +4,20 @@ body { .content { height: 100%; } + + small { + font-size:10pt; + color:#555; + a { + color:#333; + } + } + + code { + background:lightgrey; + border-radius:5px; + padding-inline:5px + } } .archivePage { @@ -250,6 +264,7 @@ body { 33%, 65% { content:'..'; } + 66%,100% { content:'...'; } From a711f8eb89e11e628719c7fcd67c9ee33125b429 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?V=C3=ADctor=20Losada=20Hern=C3=A1ndez?= Date: Sat, 18 May 2024 23:07:43 +0200 Subject: [PATCH 090/252] remove regex search --- .../pages/archivePage/archivePage.jsx | 2 +- server/archive.api.js | 19 ++----------------- 2 files changed, 3 insertions(+), 18 deletions(-) diff --git a/client/homebrew/pages/archivePage/archivePage.jsx b/client/homebrew/pages/archivePage/archivePage.jsx index dac0e9a33..f4e79da35 100644 --- a/client/homebrew/pages/archivePage/archivePage.jsx +++ b/client/homebrew/pages/archivePage/archivePage.jsx @@ -187,7 +187,7 @@ const ArchivePage = createClass({ placeholder="v3 Reference Document" /> - Tip! you can use RegEx if you format your query as /title/ + Tip! you can use - to negate words, and "word" to specify an exact string.
    -

    Your results, my lordship

    +

    Your searched returned these results

    {this.renderFoundBrews()}
    diff --git a/client/homebrew/pages/archivePage/archivePage.less b/client/homebrew/pages/archivePage/archivePage.less index 6f4fc8684..31dba3cd6 100644 --- a/client/homebrew/pages/archivePage/archivePage.less +++ b/client/homebrew/pages/archivePage/archivePage.less @@ -117,7 +117,7 @@ body { background-color: #2C3E50; width: 100%; max-height: 100%; - height: 66.7vh; + height: 66.8vh; padding: 50px; overflow-y:scroll; From 21244fba58660c03d3e544012ef663703015aef7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?V=C3=ADctor=20Losada=20Hern=C3=A1ndez?= Date: Sun, 19 May 2024 23:45:12 +0200 Subject: [PATCH 093/252] "Removed lodash import, simplified boolean assignments, refactored API request and error handling, and removed unused variables in ArchivePage component." --- .../pages/archivePage/archivePage.jsx | 29 ++++++------------- 1 file changed, 9 insertions(+), 20 deletions(-) diff --git a/client/homebrew/pages/archivePage/archivePage.jsx b/client/homebrew/pages/archivePage/archivePage.jsx index 57802b4ef..6cf84ef3d 100644 --- a/client/homebrew/pages/archivePage/archivePage.jsx +++ b/client/homebrew/pages/archivePage/archivePage.jsx @@ -2,7 +2,6 @@ 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'); @@ -27,8 +26,8 @@ const ArchivePage = createClass({ //# request title: this.props.query.title || '', //tags: {}, - legacy: `${this.props.query.legacy === 'false' ? false : true}`, - v3: `${this.props.query.v3 === 'false' ? false : true}`, + legacy: this.props.query.legacy !== 'false', + v3: this.props.query.v3 !== 'false', pageSize: this.props.query.size || 10, page: parseInt(this.props.query.page) || 1, @@ -100,19 +99,10 @@ const ArchivePage = createClass({ if (title !== '') { try { this.setState({ searching: true, error: null }); - - await request - .get( - `/api/archive?title=${title}&page=${page}&size=${size}&v3=${v3}&legacy=${legacy}` - ) - .then((response) => { - if (response.ok) { - this.updateStateWithBrews( - response.body.brews, - page - ); - } - }); + const response = await request.get(`/api/archive?title=${title}&page=${page}&size=${size}&v3=${v3}&legacy=${legacy}`); + if (response.ok) { + this.updateStateWithBrews(response.body.brews, page); + } } catch (error) { console.log('error at loadPage: ', error); this.setState({ error: `${error.response.status}` }); @@ -252,7 +242,6 @@ const ArchivePage = createClass({ renderPaginationControls() { if (this.state.totalBrews) { - const title = encodeURIComponent(this.state.title); const size = parseInt(this.state.pageSize); const { page, totalBrews } = this.state; @@ -317,7 +306,7 @@ const ArchivePage = createClass({ }, renderFoundBrews() { - const { title, brewCollection, page, totalPages, error, searching } = + const { title, brewCollection, error, searching } = this.state; if (searching) { @@ -344,11 +333,11 @@ const ArchivePage = createClass({ errorMessage = "404 - We didn't find any brew"; break; case '503': - errorMessage = - ' 503 - Service Unavailable, try again later, sorry.'; + errorMessage = "503 - Service Unavailable, try again later, sorry."; break; case '500': errorMessage = "500 - We don't know what happened, go ahead and contact the mods or report as a mistake."; + break; default: errorMessage = 'An unexpected error occurred'; } From f9d19c75b29aa5494fa652b01ddce55799161eb1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?V=C3=ADctor=20Losada=20Hern=C3=A1ndez?= Date: Tue, 21 May 2024 11:57:48 +0200 Subject: [PATCH 094/252] change renderPagination order of operations and fix pagination not loading properly --- .../pages/archivePage/archivePage.jsx | 159 ++++++++++-------- 1 file changed, 91 insertions(+), 68 deletions(-) diff --git a/client/homebrew/pages/archivePage/archivePage.jsx b/client/homebrew/pages/archivePage/archivePage.jsx index 6cf84ef3d..e23af7b26 100644 --- a/client/homebrew/pages/archivePage/archivePage.jsx +++ b/client/homebrew/pages/archivePage/archivePage.jsx @@ -99,7 +99,9 @@ const ArchivePage = createClass({ if (title !== '') { try { this.setState({ searching: true, error: null }); - const response = await request.get(`/api/archive?title=${title}&page=${page}&size=${size}&v3=${v3}&legacy=${legacy}`); + const response = await request.get( + `/api/archive?title=${title}&page=${page}&size=${size}&v3=${v3}&legacy=${legacy}` + ); if (response.ok) { this.updateStateWithBrews(response.body.brews, page); } @@ -119,6 +121,9 @@ const ArchivePage = createClass({ const { title, v3, legacy } = this.state; if (title !== '') { + this.setState({ + totalBrews: null, + }); try { await request .get( @@ -178,7 +183,10 @@ const ArchivePage = createClass({ placeholder="v3 Reference Document" /> - Tip! you can use - to negate words, and "word" to specify an exact string. + + Tip! you can use - to negate words, and{' '} + "word" to specify an exact string. +
    - Remember, you can only search brews with this tool if they are published + + Remember, you can only search brews with this tool if they + are published +
    ); }, - renderPaginationControls() { - if (this.state.totalBrews) { - const size = parseInt(this.state.pageSize); - const { page, totalBrews } = this.state; - - const totalPages = Math.ceil(totalBrews / size); - - let startPage, endPage; - if (page <= 6) { - startPage = 1; - endPage = Math.min(totalPages, 10); - } else if (page + 4 >= totalPages) { - startPage = Math.max(1, totalPages - 9); - endPage = totalPages; - } else { - startPage = page - 5; - endPage = page + 4; - } - - const pagesAroundCurrent = new Array(endPage - startPage + 1) - .fill() - .map((_, index) => ( - this.loadPage(startPage + index, false)} - > - {startPage + index} - - )); - - return ( -
    - {page > 1 && ( - - )} -
      - {startPage > 1 && this.loadPage(1, false)}>1 ...} - {pagesAroundCurrent} - {endPage < totalPages && ( - this.loadPage(totalPages, false)}>... {totalPages} - )} -
    - {page < totalPages && ( - - )} -
    - ); - } else { + renderPaginationControls: function () { + if (!this.state.totalBrews) { return null; } + + const size = parseInt(this.state.pageSize); + const { page, totalBrews } = this.state; + const totalPages = Math.ceil(totalBrews / size); + + let startPage, endPage; + if (page <= 6) { + startPage = 1; + endPage = Math.min(totalPages, 10); + } else if (page + 4 >= totalPages) { + startPage = Math.max(1, totalPages - 9); + endPage = totalPages; + } else { + startPage = page - 5; + endPage = page + 4; + } + + const pagesAroundCurrent = new Array(endPage - startPage + 1) + .fill() + .map((_, index) => ( + this.loadPage(startPage + index, false)} + > + {startPage + index} + + )); + + return ( +
    + {page > 1 && ( + + )} +
      + {startPage > 1 && ( + this.loadPage(1, false)} + > + 1 ... + + )} + {pagesAroundCurrent} + {endPage < totalPages && ( + this.loadPage(totalPages, false)} + > + ... {totalPages} + + )} +
    + {page < totalPages && ( + + )} +
    + ); }, renderFoundBrews() { - const { title, brewCollection, error, searching } = - this.state; + const { title, brewCollection, error, searching } = this.state; if (searching) { return ( @@ -333,10 +354,12 @@ const ArchivePage = createClass({ errorMessage = "404 - We didn't find any brew"; break; case '503': - errorMessage = "503 - Service Unavailable, try again later, sorry."; + errorMessage = + '503 - Service Unavailable, try again later, sorry.'; break; case '500': - errorMessage = "500 - We don't know what happened, go ahead and contact the mods or report as a mistake."; + errorMessage = + "500 - We don't know what happened, go ahead and contact the mods or report as a mistake."; break; default: errorMessage = 'An unexpected error occurred'; From e9b85e1a9aeaeb94fb3dd2e681aa0027ea315943 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?V=C3=ADctor=20Losada=20Hern=C3=A1ndez?= Date: Tue, 21 May 2024 12:06:08 +0200 Subject: [PATCH 095/252] damn totalBrews won't go away --- client/homebrew/pages/archivePage/archivePage.jsx | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/client/homebrew/pages/archivePage/archivePage.jsx b/client/homebrew/pages/archivePage/archivePage.jsx index e23af7b26..17dba86fb 100644 --- a/client/homebrew/pages/archivePage/archivePage.jsx +++ b/client/homebrew/pages/archivePage/archivePage.jsx @@ -91,7 +91,6 @@ const ArchivePage = createClass({ pageSize: size, v3: v3, legacy: legacy, - totalBrews: null, }); this.updateUrl(title, page, size, v3, legacy); } @@ -119,11 +118,11 @@ const ArchivePage = createClass({ loadTotal: async function () { console.log('running loadTotal'); const { title, v3, legacy } = this.state; + this.setState({ + totalBrews: null, + }); if (title !== '') { - this.setState({ - totalBrews: null, - }); try { await request .get( From efda06ebe5cac0dcefd173d0016ac31c4d06ca9c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?V=C3=ADctor=20Losada=20Hern=C3=A1ndez?= Date: Tue, 21 May 2024 12:09:41 +0200 Subject: [PATCH 096/252] console log to find the issue --- client/homebrew/pages/archivePage/archivePage.jsx | 2 ++ 1 file changed, 2 insertions(+) diff --git a/client/homebrew/pages/archivePage/archivePage.jsx b/client/homebrew/pages/archivePage/archivePage.jsx index 17dba86fb..9e428f355 100644 --- a/client/homebrew/pages/archivePage/archivePage.jsx +++ b/client/homebrew/pages/archivePage/archivePage.jsx @@ -118,6 +118,7 @@ const ArchivePage = createClass({ loadTotal: async function () { console.log('running loadTotal'); const { title, v3, legacy } = this.state; + this.setState({ totalBrews: null, }); @@ -141,6 +142,7 @@ const ArchivePage = createClass({ this.updateStateWithBrews([], 1); } } + console.log('total brews in state in loadtotal: ', this.state.totalBrews); }, renderNavItems: function () { From 68c3e1ba84ba4fbc47bec9ba2983014026ca49f5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?V=C3=ADctor=20Losada=20Hern=C3=A1ndez?= Date: Tue, 21 May 2024 12:16:07 +0200 Subject: [PATCH 097/252] log at will --- client/homebrew/pages/archivePage/archivePage.jsx | 1 + 1 file changed, 1 insertion(+) diff --git a/client/homebrew/pages/archivePage/archivePage.jsx b/client/homebrew/pages/archivePage/archivePage.jsx index 9e428f355..ee4ea3925 100644 --- a/client/homebrew/pages/archivePage/archivePage.jsx +++ b/client/homebrew/pages/archivePage/archivePage.jsx @@ -248,6 +248,7 @@ const ArchivePage = createClass({ Remember, you can only search brews with this tool if they are published + ); }, From ecfdada810c43cc08ef5bba45ef42034afbddf1f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?V=C3=ADctor=20Losada=20Hern=C3=A1ndez?= Date: Tue, 21 May 2024 12:24:47 +0200 Subject: [PATCH 098/252] fix damn error finally --- client/homebrew/pages/archivePage/archivePage.jsx | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/client/homebrew/pages/archivePage/archivePage.jsx b/client/homebrew/pages/archivePage/archivePage.jsx index ee4ea3925..f271c2f95 100644 --- a/client/homebrew/pages/archivePage/archivePage.jsx +++ b/client/homebrew/pages/archivePage/archivePage.jsx @@ -117,7 +117,9 @@ const ArchivePage = createClass({ loadTotal: async function () { console.log('running loadTotal'); - const { title, v3, legacy } = this.state; + const title = document.getElementById('title').value || ''; + const v3 = document.getElementById('v3').checked; + const legacy = document.getElementById('legacy').checked; this.setState({ totalBrews: null, @@ -142,7 +144,6 @@ const ArchivePage = createClass({ this.updateStateWithBrews([], 1); } } - console.log('total brews in state in loadtotal: ', this.state.totalBrews); }, renderNavItems: function () { @@ -248,7 +249,6 @@ const ArchivePage = createClass({ Remember, you can only search brews with this tool if they are published - ); }, From 8fd165a79b5f1d6cd4b6042e7b7bfc9f6e7c3f6d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?V=C3=ADctor=20Losada=20Hern=C3=A1ndez?= Date: Tue, 21 May 2024 23:43:56 +0200 Subject: [PATCH 099/252] form changes --- .../pages/archivePage/archivePage.jsx | 35 +++++++++++++------ .../pages/archivePage/archivePage.less | 2 +- 2 files changed, 25 insertions(+), 12 deletions(-) diff --git a/client/homebrew/pages/archivePage/archivePage.jsx b/client/homebrew/pages/archivePage/archivePage.jsx index f271c2f95..4f6aab683 100644 --- a/client/homebrew/pages/archivePage/archivePage.jsx +++ b/client/homebrew/pages/archivePage/archivePage.jsx @@ -120,7 +120,7 @@ const ArchivePage = createClass({ const title = document.getElementById('title').value || ''; const v3 = document.getElementById('v3').checked; const legacy = document.getElementById('legacy').checked; - + this.setState({ totalBrews: null, }); @@ -164,6 +164,16 @@ const ArchivePage = createClass({ ); }, + validateInput: function (e) { + const textInput = e.target + const submitButton = document.getElementById('searchButton'); + if (textInput.value.length > 3) { + submitButton.disabled = false; + } else { + submitButton.disabled = true; + } + }, + renderForm: function () { return (
    @@ -176,6 +186,9 @@ const ArchivePage = createClass({ type="text" name="title" defaultValue={this.state.title} + onKeyUp={(e) => { + this.validateInput(e); + }} onKeyDown={(e) => { if (e.key === 'Enter') { this.loadTotal(); @@ -191,15 +204,14 @@ const ArchivePage = createClass({
    + placeholder="v3 Reference Document" + /> + - Remember, you can only search brews with this tool if they - are published + Tip! you can use - to negate words, and{' '} + "word" to specify an exact string. + + + + + + + - ); - }, + + Remember, you can only search brews with this tool if they are + published + + + ); - renderPaginationControls: function () { - if (!this.state.totalBrews) { - return null; - } + const renderPaginationControls = () => { + if (!totalBrews) return null; - const count = parseInt(this.state.count); - const { page, totalBrews } = this.state; - const totalPages = Math.ceil(totalBrews / count); + const countInt = parseInt(count); + const totalPages = Math.ceil(totalBrews / countInt); let startPage, endPage; if (page <= 6) { @@ -296,7 +260,7 @@ const ArchivePage = createClass({ className={`pageNumber ${ page === startPage + index ? 'currentPage' : '' }`} - onClick={() => this.loadPage(startPage + index, false)} + onClick={() => loadPage(startPage + index, false)} > {startPage + index} @@ -307,7 +271,7 @@ const ArchivePage = createClass({ {page > 1 && ( @@ -315,8 +279,8 @@ const ArchivePage = createClass({
      {startPage > 1 && ( this.loadPage(1, false)} + className="firstPage" + onClick={() => loadPage(1, false)} > 1 ... @@ -324,8 +288,8 @@ const ArchivePage = createClass({ {pagesAroundCurrent} {endPage < totalPages && ( this.loadPage(totalPages, false)} + className="lastPage" + onClick={() => loadPage(totalPages, false)} > ... {totalPages} @@ -334,18 +298,16 @@ const ArchivePage = createClass({ {page < totalPages && ( )} ); - }, - - renderFoundBrews() { - const { title, brewCollection, error, searching } = this.state; + }; + const renderFoundBrews = () => { if (searching) { return (
      @@ -395,43 +357,45 @@ const ArchivePage = createClass({
      ); } - console.log('state when rendering '); - console.table(this.state); + return (
      {`Brews found: `} - {title === '' ? '0' : this.state.totalBrews ? this.state.totalBrews : } + {title === '' ? ( + '0' + ) : totalBrews ? ( + totalBrews + ) : ( + + )} {brewCollection.map((brew, index) => ( ))} - {this.renderPaginationControls()} + {renderPaginationControls()}
      ); - - }, + }; - render: function () { - return ( -
      - - - {this.renderNavItems()} + return ( +
      + + + {renderNavItems()} +
      +
      {renderForm()}
      -
      -
      {this.renderForm()}
      -
      - {this.renderFoundBrews()} -
      +
      + {renderFoundBrews()}
      - ); - }, -}); +
      + ); +}; module.exports = ArchivePage; From 90431efbc92d7adaa57a706ff310a43c302b59c3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?V=C3=ADctor=20Losada=20Hern=C3=A1ndez?= Date: Tue, 11 Jun 2024 00:33:36 +0200 Subject: [PATCH 119/252] "Removed ArchivePage and related files, replaced with VaultPage, updated routes and API endpoints, and made minor changes to theme configuration and error handling." --- client/homebrew/homebrew.jsx | 5 +-- .../basePages/listPage/brewItem/brewItem.jsx | 2 - .../vaultPage.jsx} | 45 +++++++++++-------- .../vaultPage.less} | 2 +- server/admin.api.js | 3 ++ server/app.js | 8 ++-- server/{archive.api.js => vault.api.js} | 13 +++--- themes/themes.json | 2 +- 8 files changed, 43 insertions(+), 37 deletions(-) rename client/homebrew/pages/{archivePage/archivePage.jsx => vaultPage/vaultPage.jsx} (91%) rename client/homebrew/pages/{archivePage/archivePage.less => vaultPage/vaultPage.less} (99%) rename server/{archive.api.js => vault.api.js} (90%) diff --git a/client/homebrew/homebrew.jsx b/client/homebrew/homebrew.jsx index 49f51aec0..b23f47baa 100644 --- a/client/homebrew/homebrew.jsx +++ b/client/homebrew/homebrew.jsx @@ -10,7 +10,7 @@ const UserPage = require('./pages/userPage/userPage.jsx'); 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 VaultPage = require('./pages/vaultPage/vaultPage.jsx'); const AccountPage = require('./pages/accountPage/accountPage.jsx'); const WithRoute = (props)=>{ @@ -72,9 +72,8 @@ const Homebrew = createClass({ } /> } /> } /> - } /> - } /> } /> + }/> } /> } /> } /> diff --git a/client/homebrew/pages/basePages/listPage/brewItem/brewItem.jsx b/client/homebrew/pages/basePages/listPage/brewItem/brewItem.jsx index affc227c0..bf0624f1c 100644 --- a/client/homebrew/pages/basePages/listPage/brewItem/brewItem.jsx +++ b/client/homebrew/pages/basePages/listPage/brewItem/brewItem.jsx @@ -117,8 +117,6 @@ const BrewItem = createClass({ }); } const dateFormatString = 'YYYY-MM-DD HH:mm:ss'; - const authors = brew.authors.length > 0 ? brew.authors : 'No authors'; - return
      {brew.thumbnail && diff --git a/client/homebrew/pages/archivePage/archivePage.jsx b/client/homebrew/pages/vaultPage/vaultPage.jsx similarity index 91% rename from client/homebrew/pages/archivePage/archivePage.jsx rename to client/homebrew/pages/vaultPage/vaultPage.jsx index 657837392..867812bc5 100644 --- a/client/homebrew/pages/archivePage/archivePage.jsx +++ b/client/homebrew/pages/vaultPage/vaultPage.jsx @@ -1,4 +1,4 @@ -require('./archivePage.less'); +require('./vaultPage.less'); const React = require('react'); const { useState, useEffect, useRef } = React; @@ -14,7 +14,7 @@ const BrewItem = require('../basePages/listPage/brewItem/brewItem.jsx'); const request = require('../../utils/request-middleware.js'); -const ArchivePage = (props) => { +const VaultPage = (props) => { const [title, setTitle] = useState(props.query.title || ''); const [legacy, setLegacy] = useState(props.query.legacy !== 'false'); const [v3, setV3] = useState(props.query.v3 !== 'false'); @@ -29,6 +29,7 @@ const ArchivePage = (props) => { const countRef = useRef(null); const v3Ref = useRef(null); const legacyRef = useRef(null); + const totalBrewsSpanRef = useRef(null); useEffect(() => { validateInput(); @@ -38,6 +39,23 @@ const ArchivePage = (props) => { !totalBrews && loadTotal(); }, []); + useEffect(() => { + console.log(totalBrewsSpanRef); + console.log(totalBrews); + if (totalBrewsSpanRef.current) { + if (title === '') { + totalBrewsSpanRef.current.innerHTML = '0'; + } else { + if (!totalBrews) { + totalBrewsSpanRef.current.innerHTML = + ''; + } else { + totalBrewsSpanRef.current.innerHTML = `${totalBrews}`; + } + } + } + }, [totalBrews, title, () => totalBrewsSpanRef.current]); + const updateStateWithBrews = (brews, page) => { setBrewCollection(brews || null); setPage(parseInt(page) || 1); @@ -65,7 +83,7 @@ const ArchivePage = (props) => { if (title !== '') { try { const response = await request.get( - `/api/archive?title=${title}&page=${page}&count=${count}&v3=${v3}&legacy=${legacy}` + `/api/vault?title=${title}&page=${page}&count=${count}&v3=${v3}&legacy=${legacy}` ); if (response.ok) { updateStateWithBrews(response.body.brews, page); @@ -112,7 +130,7 @@ const ArchivePage = (props) => { if (title) { try { const response = await request.get( - `/api/archive/total?title=${title}&v3=${v3}&legacy=${legacy}` + `/api/vault/total?title=${title}&v3=${v3}&legacy=${legacy}` ); if (response.ok) { @@ -134,7 +152,7 @@ const ArchivePage = (props) => { - Archive: Search for brews + Vault: Search for brews @@ -171,10 +189,7 @@ const ArchivePage = (props) => { pattern=".{3,}" onKeyDown={(e) => { if (e.key === 'Enter') { - if ( - e.target.validity.valid && - e.target.value - ) { + if (e.target.validity.valid && e.target.value) { loadTotal(); loadPage(1, true); } @@ -362,13 +377,7 @@ const ArchivePage = (props) => {
      {`Brews found: `} - {title === '' ? ( - '0' - ) : totalBrews ? ( - totalBrews - ) : ( - - )} + {brewCollection.map((brew, index) => ( { }; return ( -
      +
      {renderNavItems()} @@ -398,4 +407,4 @@ const ArchivePage = (props) => { ); }; -module.exports = ArchivePage; +module.exports = VaultPage; diff --git a/client/homebrew/pages/archivePage/archivePage.less b/client/homebrew/pages/vaultPage/vaultPage.less similarity index 99% rename from client/homebrew/pages/archivePage/archivePage.less rename to client/homebrew/pages/vaultPage/vaultPage.less index 75e9c462e..9f6b8e3df 100644 --- a/client/homebrew/pages/archivePage/archivePage.less +++ b/client/homebrew/pages/vaultPage/vaultPage.less @@ -25,7 +25,7 @@ body { } } -.archivePage { +.vaultPage { overflow-y: hidden; height: 100%; background-color: #2C3E50; diff --git a/server/admin.api.js b/server/admin.api.js index 0b5ecb1fc..66bd58852 100644 --- a/server/admin.api.js +++ b/server/admin.api.js @@ -85,6 +85,7 @@ router.get('/admin/lookup/:id', mw.adminOnly, async (req, res, next)=>{ }); }); + /* Find 50 brews that aren't compressed yet */ router.get('/admin/finduncompressed', mw.adminOnly, (req, res)=>{ const query = uncompressedBrewQuery.clone(); @@ -100,6 +101,7 @@ router.get('/admin/finduncompressed', mw.adminOnly, (req, res)=>{ }); }); + /* Compresses the "text" field of a brew to binary */ router.put('/admin/compress/:id', (req, res)=>{ HomebrewModel.findOne({ _id: req.params.id }) @@ -121,6 +123,7 @@ router.put('/admin/compress/:id', (req, res)=>{ }); }); + router.get('/admin/stats', mw.adminOnly, async (req, res)=>{ try { const totalBrewsCount = await HomebrewModel.countDocuments({}); diff --git a/server/app.js b/server/app.js index cc8c7dfef..b0cb0aca5 100644 --- a/server/app.js +++ b/server/app.js @@ -54,7 +54,7 @@ app.use((req, res, next)=>{ app.use(homebrewApi); app.use(require('./admin.api.js')); -app.use(require('./archive.api.js')); +app.use(require('./vault.api.js')); const HomebrewModel = require('./homebrew.model.js').model; const welcomeText = require('fs').readFileSync('client/homebrew/pages/homePage/welcome_msg.md', 'utf8'); @@ -462,8 +462,8 @@ 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'); + if(err.originalUrl?.startsWith('/vault/')) { + // console.log('vault error'); res.status(err.status || err.response?.status || 500).send(err); return; } @@ -490,8 +490,6 @@ 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); diff --git a/server/archive.api.js b/server/vault.api.js similarity index 90% rename from server/archive.api.js rename to server/vault.api.js index 512b071f1..97d91fc54 100644 --- a/server/archive.api.js +++ b/server/vault.api.js @@ -52,10 +52,10 @@ const buildBrewsQuery = (legacy, v3) => { return brewsQuery; }; -const archive = { +const vault = { findBrews: async (req, res, next) => { try { - console.log(`Query as received in archive api for findBrews:`); + console.log(`Query as received in vault api for findBrews:`); console.table(req.query); const title = req.query.title || ''; @@ -91,7 +91,7 @@ const archive = { } }, findTotal: async (req, res) => { - console.log(`Query as received in archive api for totalBrews:`); + console.log(`Query as received in vault api for totalBrews:`); console.table(req.query); try { const title = req.query.title || ''; @@ -102,9 +102,8 @@ const archive = { const titleQuery = { $and: [brewsQuery, ...titleConditionsArray], }; - const totalBrews = await HomebrewModel.countDocuments(titleQuery); - console.log('when returning, totalbrews is ', totalBrews); + console.log('when returning, totalbrews is ', totalBrews, 'for the query ',JSON.stringify(titleQuery)); return res.json({ totalBrews }); } catch (error) { @@ -114,7 +113,7 @@ const archive = { }, }; -router.get('/api/archive/total', asyncHandler(archive.findTotal)); -router.get('/api/archive', asyncHandler(archive.findBrews)); +router.get('/api/vault/total', asyncHandler(vault.findTotal)); +router.get('/api/vault', asyncHandler(vault.findBrews)); module.exports = router; diff --git a/themes/themes.json b/themes/themes.json index cb0c5593e..bc719185d 100644 --- a/themes/themes.json +++ b/themes/themes.json @@ -34,7 +34,7 @@ "renderer": "V3", "baseTheme": false, "baseSnippets": "5ePHB", - "path": "Journal" + "path": "journal" } } } \ No newline at end of file From 1e080b30fdbe27f5f2372ab6b4cff66d8ac78f19 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?V=C3=ADctor=20Losada=20Hern=C3=A1ndez?= Date: Thu, 13 Jun 2024 00:41:40 +0200 Subject: [PATCH 120/252] finally fixed the damn issue --- client/homebrew/pages/vaultPage/vaultPage.jsx | 90 ++++++++----------- 1 file changed, 36 insertions(+), 54 deletions(-) diff --git a/client/homebrew/pages/vaultPage/vaultPage.jsx b/client/homebrew/pages/vaultPage/vaultPage.jsx index 867812bc5..8ea7ff0b2 100644 --- a/client/homebrew/pages/vaultPage/vaultPage.jsx +++ b/client/homebrew/pages/vaultPage/vaultPage.jsx @@ -29,33 +29,14 @@ const VaultPage = (props) => { const countRef = useRef(null); const v3Ref = useRef(null); const legacyRef = useRef(null); - const totalBrewsSpanRef = useRef(null); useEffect(() => { validateInput(); if (title) { - loadPage(page, false); + loadPage(page, false, true); } - !totalBrews && loadTotal(); }, []); - useEffect(() => { - console.log(totalBrewsSpanRef); - console.log(totalBrews); - if (totalBrewsSpanRef.current) { - if (title === '') { - totalBrewsSpanRef.current.innerHTML = '0'; - } else { - if (!totalBrews) { - totalBrewsSpanRef.current.innerHTML = - ''; - } else { - totalBrewsSpanRef.current.innerHTML = `${totalBrews}`; - } - } - } - }, [totalBrews, title, () => totalBrewsSpanRef.current]); - const updateStateWithBrews = (brews, page) => { setBrewCollection(brews || null); setPage(parseInt(page) || 1); @@ -74,7 +55,7 @@ const VaultPage = (props) => { window.history.replaceState(null, null, url); }; - const loadPage = async (page, update) => { + const loadPage = async (page, update, total) => { setSearching(true); setError(null); @@ -106,12 +87,36 @@ const VaultPage = (props) => { } }; - if (update) { - const title = titleRef.current.value || ''; - const count = countRef.current.value || 10; - const v3 = v3Ref.current.checked; - const legacy = legacyRef.current.checked; + const loadTotal = async ({title, v3, legacy}) => { + setTotalBrews(null); + setError(null); + if (title) { + try { + const response = await request.get( + `/api/vault/total?title=${title}&v3=${v3}&legacy=${legacy}` + ); + if (response.ok) { + setTotalBrews(response.body.totalBrews); + } else { + throw new Error( + `Failed to load total brews: ${response.statusText}` + ); + } + } catch (error) { + console.log('error at loadTotal: ', error); + setError(`${error.response.status}`); + updateStateWithBrews([], 1); + } + } + }; + + const title = titleRef.current.value || ''; + const count = countRef.current.value || 10; + const v3 = v3Ref.current.checked; + const legacy = legacyRef.current.checked; + + if (update) { setTitle(title); setCount(count); setV3(v3); @@ -121,30 +126,9 @@ const VaultPage = (props) => { } else { performSearch({ title, count, v3, legacy }); } - }; - const loadTotal = async () => { - setTotalBrews(null); - setError(null); - - if (title) { - try { - const response = await request.get( - `/api/vault/total?title=${title}&v3=${v3}&legacy=${legacy}` - ); - - if (response.ok) { - setTotalBrews(response.body.totalBrews); - } else { - throw new Error( - `Failed to load total brews: ${response.statusText}` - ); - } - } catch (error) { - console.log('error at loadTotal: ', error); - setError(`${error.response.status}`); - updateStateWithBrews([], 1); - } + if (total) { + loadTotal({ title, v3, legacy }); } }; @@ -190,8 +174,7 @@ const VaultPage = (props) => { onKeyDown={(e) => { if (e.key === 'Enter') { if (e.target.validity.valid && e.target.value) { - loadTotal(); - loadPage(1, true); + loadPage(1, true, true); } } }} @@ -229,8 +212,7 @@ const VaultPage = (props) => { - )} +
        {startPage > 1 && ( loadPage(1, false)} > 1 ... @@ -285,21 +284,20 @@ const VaultPage = (props) => { {pagesAroundCurrent} {endPage < totalPages && ( loadPage(totalPages, false)} > ... {totalPages} )}
      - {page < totalPages && ( - - )} +
      ); }; diff --git a/client/homebrew/pages/vaultPage/vaultPage.less b/client/homebrew/pages/vaultPage/vaultPage.less index 9f6b8e3df..0af26e092 100644 --- a/client/homebrew/pages/vaultPage/vaultPage.less +++ b/client/homebrew/pages/vaultPage/vaultPage.less @@ -1,280 +1,245 @@ body { - height: 100vh; + height : 100vh; - .content { - height: 100%; - } + .content { height : 100%; } - small { - font-size: 10pt; - color: #555; + small { + font-size : 10pt; + color : #555555; - a { - color: #333; - } - } + a { color : #333333; } + } - code { - background: lightgrey; - border-radius: 5px; - padding-inline: 5px - } + code { + padding-inline : 5px; + background : lightgrey; + border-radius : 5px; + } - *:not(input) { - user-select: none; - } + *:not(input) { user-select : none; } } .vaultPage { - overflow-y: hidden; - height: 100%; - background-color: #2C3E50; + height : 100%; + overflow-y : hidden; + background-color : #2C3E50; - h1, - h2, - h3 { - font-family: 'Open Sans'; - color: white; - font-weight: 900; - } + h1, + h2, + h3 { + font-family : 'Open Sans'; + font-weight : 900; + color : white; + } - .content { - display: grid; - grid-template-columns: 500px 2fr; - background: #2C3E50; + .content { + display : grid; + grid-template-columns : 500px 2fr; + background : #2C3E50; - .dataGroup { - width: 100%; - height: 100%; - background: white; + .dataGroup { + width : 100%; + height : 100%; + background : white; - &.form .brewLookup { - position: relative; - padding: 50px; + &.form .brewLookup { + position : relative; + padding : 50px; - .formTitle { - color: black; - font-size: 30px; - border-bottom: 2px solid; - margin: 20px 0; - text-align: center; - } + .formTitle { + margin : 20px 0; + font-size : 30px; + color : black; + text-align : center; + border-bottom : 2px solid; + } - .formContents { - display: flex; - flex-direction: column; - } + .formContents { + display : flex; + flex-direction : column; + } - label { - margin: 10px 0; - } + label { margin : 10px 0; } - input { - margin: 0 10px; - } + input { margin : 0 10px; } - #searchButton { - position: absolute; - right: 10px; - bottom: 20px; + #searchButton { + position : absolute; + right : 10px; + bottom : 20px; - i { - margin-left: 10px; - } - } - } + i { margin-left : 10px; } + } + } - &.resultsContainer { - display: flex; - flex-direction: column; - border-left: 2px solid; - height: 100%; - font-family: "BookInsanityRemake"; - font-size: .34cm; - overflow-y: auto; + &.resultsContainer { + display : flex; + flex-direction : column; + height : 100%; + overflow-y : auto; + font-family : 'BookInsanityRemake'; + font-size : 0.34cm; + border-left : 2px solid; - .foundBrews { - position: relative; - background-color: #2C3E50; - width: 100%; - max-height: 100%; - height: 100%; - padding: 50px 50px 70px 50px; - overflow-y: scroll; + .foundBrews { + position : relative; + width : 100%; + height : 100%; + max-height : 100%; + padding : 50px 50px 70px 50px; + overflow-y : scroll; + background-color : #2C3E50; - h3 { - font-size: 25px; - } + h3 { font-size : 25px; } - &.noBrews { - display: grid; - place-items: center; - color: white; - } + &.noBrews { + display : grid; + place-items : center; + color : white; + } - &.searching { - display: grid; - place-items: center; - color: white; + &.searching { + display : grid; + place-items : center; + color : white; - h3 { - position: relative; - } + h3 { position : relative; } - h3.searchAnim::after { - content: ""; - width: max-content; - height: 1em; - position: absolute; - right: 0; - top: 50%; - translate: 100% -50%; - animation: trailingDots 2s ease infinite; - } - } + h3.searchAnim::after { + position : absolute; + top : 50%; + right : 0; + width : max-content; + height : 1em; + content : ''; + translate : 100% -50%; + animation : trailingDots 2s ease infinite; + } + } - .totalBrews { - 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'; + .totalBrews { + position : fixed; + right : 17px; + bottom : 0; + z-index : 1000; + padding : 8px 10px; + font-family : 'Open Sans'; + font-size : 11px; + font-weight : 800; + color : white; + background-color : #333333; - .searchAnim { - position: relative; - display: inline-block; - width: 3ch; - height: 1em; - } + .searchAnim { + position : relative; + display : inline-block; + width : 3ch; + height : 1em; + } - .searchAnim::after { - content: ""; - width: max-content; - height: 1em; - position: absolute; - right: 0; - top: 50%; - translate: -50% -50%; - animation: trailingDots 2s ease infinite; - } - } + .searchAnim::after { + position : absolute; + top : 50%; + right : 0; + width : max-content; + height : 1em; + content : ''; + translate : -50% -50%; + animation : trailingDots 2s ease infinite; + } + } - .brewItem { - background-image: url('/assets/parchmentBackground.jpg'); - width: 48%; - margin-right: 40px; - color: black; + .brewItem { + width : 48%; + margin-right : 40px; + color : black; + background-image : url('/assets/parchmentBackground.jpg'); - &:nth-child(even of .brewItem) { - margin-right: 0; - } + &:nth-child(even of .brewItem) { margin-right : 0; } - h2 { - font-size: 0.75cm; - line-height: 0.988em; - font-family: "MrEavesRemake"; - font-weight: 800; - color: var(--HB_Color_HeaderText); - } + h2 { + font-family : 'MrEavesRemake'; + font-size : 0.75cm; + font-weight : 800; + line-height : 0.988em; + color : var(--HB_Color_HeaderText); + } - .info { - font-family: ScalySansRemake; - font-size: 1.2em; + .info { + font-family : "ScalySansRemake"; + font-size : 1.2em; - >span { - margin-right: 12px; - line-height: 1.5em; - } - } - } + >span { + margin-right : 12px; + line-height : 1.5em; + } + } + } - .paginationControls { - position: absolute; - left: 50%; - translate: -50%; - width: auto; - display: grid; - place-items: center; - grid-template-areas: "previousPage currentPage nextPage"; - grid-template-columns: 50px 1fr 50px; + .paginationControls { + position : absolute; + left : 50%; + display : grid; + grid-template-areas : 'previousPage currentPage nextPage'; + grid-template-columns : 50px 1fr 50px; + place-items : center; + width : auto; + translate : -50%; - .pages { - grid-area: currentPage; - height: 100%; - width: 100%; - display: flex; - justify-content: space-evenly; - text-align: center; - padding: 5px 8px; + .pages { + display : flex; + grid-area : currentPage; + justify-content : space-evenly; + width : 100%; + height : 100%; + padding : 5px 8px; + text-align : center; - .pageNumber { - color: white; - font-family: Open Sans; - font-weight: 900; - text-underline-position: under; - margin-inline: 10px; - cursor: pointer; + .pageNumber { + margin-inline : 10px; + font-family : "Open Sans"; + font-weight : 900; + color : white; + text-underline-position : under; + cursor : pointer; - &.currentPage { - color: gold; - text-decoration: underline; - pointer-events: none; - } + &.currentPage { + color : gold; + text-decoration : underline; + pointer-events : none; + } - &.firstPage { - margin-right: -5px; - } + &.firstPage { margin-right : -5px; } - &.lastPage { - margin-left: -5px; - } - } - } + &.lastPage { margin-left : -5px; } + } + } - button { - width: max-content; - border-radius: 5px; + button { + width : max-content; - &.previousPage { - grid-area: previousPage; - } + &.previousPage { grid-area : previousPage; } - &.nextPage { - grid-area: nextPage; - } - } + &.nextPage { grid-area : nextPage; } + } - } + } - hr { - visibility: hidden; - } - } - } - } - } + hr { visibility : hidden; } + } + } + } + } } @keyframes trailingDots { - 0%, - 32% { - content: '.'; - } + 0%, + 32% { content : '.'; } - 33%, - 65% { - content: '..'; - } + 33%, + 65% { content : '..'; } - 66%, - 100% { - content: '...'; - } + 66%, + 100% { content : '...'; } } \ No newline at end of file From bdfd194672a9e19516d36d083ac10bf6d85d0c9b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?V=C3=ADctor=20Losada=20Hern=C3=A1ndez?= Date: Thu, 13 Jun 2024 01:13:38 +0200 Subject: [PATCH 122/252] changed order of params per request --- client/homebrew/pages/vaultPage/vaultPage.jsx | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/client/homebrew/pages/vaultPage/vaultPage.jsx b/client/homebrew/pages/vaultPage/vaultPage.jsx index 19d65e8f3..2ed360f4b 100644 --- a/client/homebrew/pages/vaultPage/vaultPage.jsx +++ b/client/homebrew/pages/vaultPage/vaultPage.jsx @@ -47,7 +47,7 @@ const VaultPage = (props) => { const url = new URL(window.location.href); const urlParams = new URLSearchParams(); - Object.entries({ title, page, count, v3, legacy }).forEach( + Object.entries({ title, v3, legacy, count, page }).forEach( ([key, value]) => urlParams.set(key, value) ); @@ -64,7 +64,7 @@ const VaultPage = (props) => { if (title !== '') { try { const response = await request.get( - `/api/vault?title=${title}&page=${page}&count=${count}&v3=${v3}&legacy=${legacy}` + `/api/vault?title=${title}&v3=${v3}&legacy=${legacy}&count=${count}&page=${page}` ); if (response.ok) { updateStateWithBrews(response.body.brews, page); From 5232c16eb289591a0c88da60164b5031f4c03efa Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?V=C3=ADctor=20Losada=20Hern=C3=A1ndez?= Date: Thu, 13 Jun 2024 01:32:34 +0200 Subject: [PATCH 123/252] change div to form --- client/homebrew/pages/vaultPage/vaultPage.jsx | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/client/homebrew/pages/vaultPage/vaultPage.jsx b/client/homebrew/pages/vaultPage/vaultPage.jsx index 2ed360f4b..0f1560b9b 100644 --- a/client/homebrew/pages/vaultPage/vaultPage.jsx +++ b/client/homebrew/pages/vaultPage/vaultPage.jsx @@ -161,7 +161,7 @@ const VaultPage = (props) => { const renderForm = () => (

      Brew Lookup

      -
      +
      + Remember, you can only search brews with this tool if they are published From 01ee184044a39d2d1c929c9e81dd74cc970ee780 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?V=C3=ADctor=20Losada=20Hern=C3=A1ndez?= Date: Tue, 23 Jul 2024 23:57:05 +0200 Subject: [PATCH 124/252] "Update default count value from 10 to 20 in VaultPage component and vault API" --- client/homebrew/pages/vaultPage/vaultPage.jsx | 2 +- server/vault.api.js | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/client/homebrew/pages/vaultPage/vaultPage.jsx b/client/homebrew/pages/vaultPage/vaultPage.jsx index 0f1560b9b..e2c175fe5 100644 --- a/client/homebrew/pages/vaultPage/vaultPage.jsx +++ b/client/homebrew/pages/vaultPage/vaultPage.jsx @@ -18,7 +18,7 @@ const VaultPage = (props) => { const [title, setTitle] = useState(props.query.title || ''); const [legacy, setLegacy] = useState(props.query.legacy !== 'false'); const [v3, setV3] = useState(props.query.v3 !== 'false'); - const [count, setCount] = useState(props.query.count || 10); + const [count, setCount] = useState(props.query.count || 20); const [page, setPage] = useState(parseInt(props.query.page) || 1); const [brewCollection, setBrewCollection] = useState(null); const [totalBrews, setTotalBrews] = useState(null); diff --git a/server/vault.api.js b/server/vault.api.js index 97d91fc54..f2500129e 100644 --- a/server/vault.api.js +++ b/server/vault.api.js @@ -61,7 +61,7 @@ const vault = { const title = req.query.title || ''; const page = Math.max(parseInt(req.query.page) || 1, 1); const mincount = 10; - const count = Math.max(parseInt(req.query.count) || 10, mincount); + const count = Math.max(parseInt(req.query.count) || 20, mincount); const skip = (page - 1) * count; const brewsQuery = buildBrewsQuery(req.query.legacy, req.query.v3); From 016a9fa1e8c15972eecb4d372fd9975ffca6134d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?V=C3=ADctor=20Losada=20Hern=C3=A1ndez?= Date: Wed, 24 Jul 2024 00:26:23 +0200 Subject: [PATCH 125/252] few css changes to make the page more responsive on smaller screens --- client/homebrew/pages/vaultPage/vaultPage.less | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/client/homebrew/pages/vaultPage/vaultPage.less b/client/homebrew/pages/vaultPage/vaultPage.less index 0af26e092..57463ca8c 100644 --- a/client/homebrew/pages/vaultPage/vaultPage.less +++ b/client/homebrew/pages/vaultPage/vaultPage.less @@ -34,7 +34,7 @@ body { .content { display : grid; - grid-template-columns : 500px 2fr; + grid-template-columns : clamp(310px,25vw, 600px) 2fr; background : #2C3E50; .dataGroup { @@ -44,7 +44,7 @@ body { &.form .brewLookup { position : relative; - padding : 50px; + padding : 50px clamp(20px, 4vw, 50px); .formTitle { margin : 20px 0; @@ -66,7 +66,7 @@ body { #searchButton { position : absolute; right : 10px; - bottom : 20px; + bottom : 0; i { margin-left : 10px; } } @@ -120,7 +120,7 @@ body { .totalBrews { position : fixed; - right : 17px; + right : 0; bottom : 0; z-index : 1000; padding : 8px 10px; @@ -150,7 +150,7 @@ body { } .brewItem { - width : 48%; + width : 47%; margin-right : 40px; color : black; background-image : url('/assets/parchmentBackground.jpg'); @@ -196,12 +196,13 @@ body { text-align : center; .pageNumber { - margin-inline : 10px; + margin-inline : 1vw; font-family : "Open Sans"; font-weight : 900; color : white; text-underline-position : under; cursor : pointer; + text-wrap : nowrap; &.currentPage { color : gold; From e206b501a686edfadb6198249f9e1e90e32fcd15 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?V=C3=ADctor=20Losada=20Hern=C3=A1ndez?= Date: Wed, 24 Jul 2024 00:34:13 +0200 Subject: [PATCH 126/252] media query to show only one column in case of small window --- client/homebrew/pages/vaultPage/vaultPage.less | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/client/homebrew/pages/vaultPage/vaultPage.less b/client/homebrew/pages/vaultPage/vaultPage.less index 57463ca8c..f110a333a 100644 --- a/client/homebrew/pages/vaultPage/vaultPage.less +++ b/client/homebrew/pages/vaultPage/vaultPage.less @@ -243,4 +243,14 @@ body { 66%, 100% { content : '...'; } +} + +// media query for when the page is smaller than 1079 px in width +@media screen and (max-width: 1079px) { + .vaultPage .content .dataGroup.resultsContainer .foundBrews .brewItem { + width: 100%; + color: black; + background-image: url('/assets/parchmentBackground.jpg'); + } + } \ No newline at end of file From e562ebef48ea3a3bf02b3244779fffa334d41ed3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?V=C3=ADctor=20Losada=20Hern=C3=A1ndez?= Date: Wed, 24 Jul 2024 00:50:21 +0200 Subject: [PATCH 127/252] media query for mobile use expanded to vertical stack --- client/homebrew/pages/vaultPage/vaultPage.less | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/client/homebrew/pages/vaultPage/vaultPage.less b/client/homebrew/pages/vaultPage/vaultPage.less index f110a333a..66c627f65 100644 --- a/client/homebrew/pages/vaultPage/vaultPage.less +++ b/client/homebrew/pages/vaultPage/vaultPage.less @@ -247,10 +247,18 @@ body { // media query for when the page is smaller than 1079 px in width @media screen and (max-width: 1079px) { - .vaultPage .content .dataGroup.resultsContainer .foundBrews .brewItem { - width: 100%; - color: black; - background-image: url('/assets/parchmentBackground.jpg'); - } + .vaultPage .content { + grid-template-columns: none; + grid-template-rows: 325px 1fr; + .brewLookup { + padding-block:10px 20px; + } + + .dataGroup.resultsContainer .foundBrews .brewItem { + width: 100%; + color: black; + background-image: url('/assets/parchmentBackground.jpg'); + } + } } \ No newline at end of file From cc08579583acce41ee4909cbacb04477188d5362 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?V=C3=ADctor=20Losada=20Hern=C3=A1ndez?= Date: Thu, 25 Jul 2024 16:57:33 +0200 Subject: [PATCH 128/252] change to splitPane component --- client/homebrew/pages/vaultPage/vaultPage.jsx | 4 ++++ client/homebrew/pages/vaultPage/vaultPage.less | 16 +++++----------- 2 files changed, 9 insertions(+), 11 deletions(-) diff --git a/client/homebrew/pages/vaultPage/vaultPage.jsx b/client/homebrew/pages/vaultPage/vaultPage.jsx index e2c175fe5..f8bca4052 100644 --- a/client/homebrew/pages/vaultPage/vaultPage.jsx +++ b/client/homebrew/pages/vaultPage/vaultPage.jsx @@ -12,6 +12,8 @@ const NewBrew = require('../../navbar/newbrew.navitem.jsx'); const HelpNavItem = require('../../navbar/help.navitem.jsx'); const BrewItem = require('../basePages/listPage/brewItem/brewItem.jsx'); +const SplitPane = require('../../../../shared/naturalcrit/splitPane/splitPane.jsx'); + const request = require('../../utils/request-middleware.js'); const VaultPage = (props) => { @@ -377,11 +379,13 @@ const VaultPage = (props) => { {renderNavItems()}
      +
      {renderForm()}
      {renderFoundBrews()}
      +
      ); diff --git a/client/homebrew/pages/vaultPage/vaultPage.less b/client/homebrew/pages/vaultPage/vaultPage.less index 66c627f65..9fa392b82 100644 --- a/client/homebrew/pages/vaultPage/vaultPage.less +++ b/client/homebrew/pages/vaultPage/vaultPage.less @@ -33,9 +33,7 @@ body { } .content { - display : grid; - grid-template-columns : clamp(310px,25vw, 600px) 2fr; - background : #2C3E50; + background: #2C3E50; .dataGroup { width : 100%; @@ -79,7 +77,6 @@ body { overflow-y : auto; font-family : 'BookInsanityRemake'; font-size : 0.34cm; - border-left : 2px solid; .foundBrews { @@ -248,17 +245,14 @@ body { // media query for when the page is smaller than 1079 px in width @media screen and (max-width: 1079px) { .vaultPage .content { - grid-template-columns: none; - grid-template-rows: 325px 1fr; .brewLookup { - padding-block:10px 20px; + padding:0 20px 20px 10px; } .dataGroup.resultsContainer .foundBrews .brewItem { - width: 100%; - color: black; - background-image: url('/assets/parchmentBackground.jpg'); + width : 100%; + margin-inline : auto; } } -} \ No newline at end of file +} From 3e2c2de269a03721703f41239eacc97e6c00c540 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?V=C3=ADctor=20Losada=20Hern=C3=A1ndez?= Date: Thu, 25 Jul 2024 23:11:51 +0200 Subject: [PATCH 129/252] Added hideMoveArrows prop to split pane for use in vault --- client/homebrew/pages/vaultPage/vaultPage.jsx | 2 +- shared/naturalcrit/splitPane/splitPane.jsx | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/client/homebrew/pages/vaultPage/vaultPage.jsx b/client/homebrew/pages/vaultPage/vaultPage.jsx index f8bca4052..1a055c9b1 100644 --- a/client/homebrew/pages/vaultPage/vaultPage.jsx +++ b/client/homebrew/pages/vaultPage/vaultPage.jsx @@ -379,7 +379,7 @@ const VaultPage = (props) => { {renderNavItems()}
      - +
      {renderForm()}
      diff --git a/shared/naturalcrit/splitPane/splitPane.jsx b/shared/naturalcrit/splitPane/splitPane.jsx index 55af5e386..ffab6bec9 100644 --- a/shared/naturalcrit/splitPane/splitPane.jsx +++ b/shared/naturalcrit/splitPane/splitPane.jsx @@ -8,7 +8,7 @@ const SplitPane = createClass({ getDefaultProps : function() { return { storageKey : 'naturalcrit-pane-split', - onDragFinish : function(){} //fires when dragging + onDragFinish : function(){}, //fires when dragging }; }, @@ -19,7 +19,7 @@ const SplitPane = createClass({ isDragging : false, moveSource : false, moveBrew : false, - showMoveArrows : true + showMoveArrows : !this.props.hideMoveArrows, }; }, From c1dc7125424be5f3673c1b752224de5b423981af Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?V=C3=ADctor=20Losada=20Hern=C3=A1ndez?= Date: Thu, 25 Jul 2024 23:48:37 +0200 Subject: [PATCH 130/252] better checkboxes and linting --- client/homebrew/pages/vaultPage/vaultPage.jsx | 10 ++- .../homebrew/pages/vaultPage/vaultPage.less | 82 +++++++++++++++---- 2 files changed, 72 insertions(+), 20 deletions(-) diff --git a/client/homebrew/pages/vaultPage/vaultPage.jsx b/client/homebrew/pages/vaultPage/vaultPage.jsx index 1a055c9b1..fbde0c140 100644 --- a/client/homebrew/pages/vaultPage/vaultPage.jsx +++ b/client/homebrew/pages/vaultPage/vaultPage.jsx @@ -188,7 +188,7 @@ const VaultPage = (props) => { "word" to specify an exact string.
    - - Remember, you can only search brews with this tool if they are - published - + +

    Tips and tricks

    +
      +
    • + You can only search brews with this tool if they are + published +
    • +
    • + Usernames are case sensitive, make sure you are writing + it correctly +
    • +
    • + You can use - to negate words, assuming + there is any word not negated, and "word"{' '} + to specify an exact string. +
    • + +
    • + Some words like a, after, through, itself, or here, are + ignored in searches, make sure your search has relevant + words. The full list can be found{' '} + + here + +
    • +
    +
    + ); @@ -405,7 +425,7 @@ const VaultPage = (props) => { ); } - + if (brewCollection.length === 0) { return (
    From 8658a6a97aebc467567813c5e1b5de408c831cd9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?V=C3=ADctor=20Losada=20Hern=C3=A1ndez?= Date: Sat, 31 Aug 2024 19:13:08 +0200 Subject: [PATCH 166/252] styling --- client/homebrew/pages/vaultPage/vaultPage.jsx | 6 +- .../homebrew/pages/vaultPage/vaultPage.less | 73 ++++++++++++------- 2 files changed, 48 insertions(+), 31 deletions(-) diff --git a/client/homebrew/pages/vaultPage/vaultPage.jsx b/client/homebrew/pages/vaultPage/vaultPage.jsx index daba3c67b..59e831aa4 100644 --- a/client/homebrew/pages/vaultPage/vaultPage.jsx +++ b/client/homebrew/pages/vaultPage/vaultPage.jsx @@ -294,16 +294,16 @@ const VaultPage = (props) => {
  • You can use - to negate words, assuming - there is any word not negated, and "word"{' '} + there is any word not negated, and "word" to specify an exact string.
  • Some words like a, after, through, itself, or here, are ignored in searches, make sure your search has relevant - words. The full list can be found{' '} + words. The full list can be found   - here + here
  • diff --git a/client/homebrew/pages/vaultPage/vaultPage.less b/client/homebrew/pages/vaultPage/vaultPage.less index 300d5ee11..d3a688172 100644 --- a/client/homebrew/pages/vaultPage/vaultPage.less +++ b/client/homebrew/pages/vaultPage/vaultPage.less @@ -24,14 +24,29 @@ body { overflow-y : hidden; background-color : #2C3E50; - h1, - h2, - h3 { - font-family : 'Open Sans'; - font-weight : 900; - color : white; + h1, h2, h3, h4 { + font-family : 'CodeBold'; + letter-spacing : 2px; } + legend { + h3 { + margin-block : 30px 20px; + font-size : 20px; + text-align : center; + border-bottom : 2px solid; + } + ul { + padding-inline : 30px 10px; + li { + margin-block : 5px; + line-height:calc(1em + 5px); + list-style : disc; + } + } + } + + .content { background : #2C3E50; @@ -66,12 +81,10 @@ body { input { margin : 0 10px; - &:invalid { - background : rgb(255, 188, 181); - } + &:invalid { background : rgb(255, 188, 181); } &[type='checkbox'] { - position : relative; + position : relative; display : inline-block; width : 50px; height : 30px; @@ -112,24 +125,22 @@ body { } } - &:after { - content: "Error:\A At least one renderer should be enabled to make a search"; - display: block; - opacity:0; - transition: opacity 0.5s; - position: absolute; - white-space: pre-wrap; - top:0; - left:0; - right:0; - background:rgb(255, 60, 60); - color:white; - font-weight:900; - padding:10px; - } - &:not(:has(input[type="checkbox"]:checked)):after { - opacity:1; + &::after { + position : absolute; + top : 0; + right : 0; + left : 0; + display : block; + padding : 10px; + font-weight : 900; + color : white; + white-space : pre-wrap; + content : 'Error:\A At least one renderer should be enabled to make a search'; + background : rgb(255, 60, 60); + opacity : 0; + transition : opacity 0.5s; } + &:not(:has(input[type='checkbox']:checked))::after { opacity : 1; } #searchButton { position : absolute; @@ -137,7 +148,7 @@ body { bottom : 0; i { - margin-left : 10px; + margin-left : 10px; animation-duration : 1000s; } } @@ -152,6 +163,12 @@ body { font-family : 'BookInsanityRemake'; font-size : 0.34cm; + + h3 { + font-family : 'Open Sans'; + font-weight : 900; + color : white; + } .foundBrews { position : relative; From e6e220fbec9a750561ef246eb653fb61a1e1809a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?V=C3=ADctor=20Losada=20Hern=C3=A1ndez?= Date: Sat, 31 Aug 2024 19:19:47 +0200 Subject: [PATCH 167/252] reposition button --- client/homebrew/pages/vaultPage/vaultPage.less | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/client/homebrew/pages/vaultPage/vaultPage.less b/client/homebrew/pages/vaultPage/vaultPage.less index d3a688172..988a53a81 100644 --- a/client/homebrew/pages/vaultPage/vaultPage.less +++ b/client/homebrew/pages/vaultPage/vaultPage.less @@ -40,7 +40,7 @@ body { padding-inline : 30px 10px; li { margin-block : 5px; - line-height:calc(1em + 5px); + line-height : calc(1em + 5px); list-style : disc; } } @@ -68,6 +68,7 @@ body { } .formContents { + position : relative; display : flex; flex-direction : column; @@ -144,7 +145,7 @@ body { #searchButton { position : absolute; - right : 10px; + right : 20px; bottom : 0; i { From f7c3e81b7b75125979a0b3cf54f3cca5aa6306bc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?V=C3=ADctor=20Losada=20Hern=C3=A1ndez?= Date: Sat, 31 Aug 2024 19:35:44 +0200 Subject: [PATCH 168/252] "Added new route for '/vault' and updated catch-all for invalid routes" --- server/app.js | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/server/app.js b/server/app.js index 3a0031609..f8bd753e1 100644 --- a/server/app.js +++ b/server/app.js @@ -434,6 +434,11 @@ if(isLocalEnvironment){ }); } +//Vault Page +app.get('/vault', asyncHandler(async(req, res, next)=>{ + return next(); +})); + //Send rendered page app.use(asyncHandler(async (req, res, next)=>{ if (!req.route) return res.redirect('/'); // Catch-all for invalid routes From a0010c9c84fd2e0d2d4f94effef60102c5238937 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?V=C3=ADctor=20Losada=20Hern=C3=A1ndez?= Date: Sat, 31 Aug 2024 19:39:01 +0200 Subject: [PATCH 169/252] "Moved error message styles from .searchButton to body, and removed duplicate styles." --- .../homebrew/pages/vaultPage/vaultPage.less | 34 ++++++++++--------- 1 file changed, 18 insertions(+), 16 deletions(-) diff --git a/client/homebrew/pages/vaultPage/vaultPage.less b/client/homebrew/pages/vaultPage/vaultPage.less index 988a53a81..f6e3ba7ff 100644 --- a/client/homebrew/pages/vaultPage/vaultPage.less +++ b/client/homebrew/pages/vaultPage/vaultPage.less @@ -59,6 +59,23 @@ body { position : relative; padding : 50px clamp(20px, 4vw, 50px); + &::after { + position : absolute; + top : 0; + right : 0; + left : 0; + display : block; + padding : 10px; + font-weight : 900; + color : white; + white-space : pre-wrap; + content : 'Error:\A At least one renderer should be enabled to make a search'; + background : rgb(255, 60, 60); + opacity : 0; + transition : opacity 0.5s; + } + &:not(:has(input[type='checkbox']:checked))::after { opacity : 1; } + .formTitle { margin : 20px 0; font-size : 30px; @@ -126,22 +143,7 @@ body { } } - &::after { - position : absolute; - top : 0; - right : 0; - left : 0; - display : block; - padding : 10px; - font-weight : 900; - color : white; - white-space : pre-wrap; - content : 'Error:\A At least one renderer should be enabled to make a search'; - background : rgb(255, 60, 60); - opacity : 0; - transition : opacity 0.5s; - } - &:not(:has(input[type='checkbox']:checked))::after { opacity : 1; } + #searchButton { position : absolute; From 6f837980eb7be2758bbb8f7fe8a1c482e8e9bae5 Mon Sep 17 00:00:00 2001 From: David Bolack Date: Sat, 31 Aug 2024 13:54:52 -0500 Subject: [PATCH 170/252] All Snippet entries that have subsnippets but not generators. --- client/homebrew/editor/snippetbar/snippetbar.jsx | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/client/homebrew/editor/snippetbar/snippetbar.jsx b/client/homebrew/editor/snippetbar/snippetbar.jsx index af493c961..0cf5b0cce 100644 --- a/client/homebrew/editor/snippetbar/snippetbar.jsx +++ b/client/homebrew/editor/snippetbar/snippetbar.jsx @@ -70,7 +70,9 @@ const Snippetbar = createClass({ mergeCustomizer : function(oldValue, newValue, key) { if(key == 'snippets') { const result = _.reverse(_.unionBy(_.reverse(newValue), _.reverse(oldValue), 'name')); // Join snippets together, with preference for the child theme over the parent theme - return _.filter(result, 'gen'); //Only keep snippets with a 'gen' property. + return _.filter(result, function(snip) { + return(snip.hasOwnProperty('gen') || snip.hasOwnProperty('subsnippets')); + }); } }, From 8d2a9ed9cbcecaee090c090953a63de0fbfe4173 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?V=C3=ADctor=20Losada=20Hern=C3=A1ndez?= Date: Sat, 31 Aug 2024 22:08:21 +0200 Subject: [PATCH 171/252] adress app.js changes requested --- server/app.js | 5 ----- 1 file changed, 5 deletions(-) diff --git a/server/app.js b/server/app.js index f8bd753e1..02075d31d 100644 --- a/server/app.js +++ b/server/app.js @@ -503,11 +503,6 @@ app.use(async (err, req, res, next)=>{ res.status(err.status || err.response?.status || 500).send(err); return; } - if(err.originalUrl?.startsWith('/vault/')) { - // console.log('vault error'); - res.status(err.status || err.response?.status || 500).send(err); - return; - } // console.log('non-API error'); const status = err.status || err.code || 500; From 19102db23ac6e070eba3c16610eb08ce5347ad1a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?V=C3=ADctor=20Losada=20Hern=C3=A1ndez?= Date: Sat, 31 Aug 2024 22:11:43 +0200 Subject: [PATCH 172/252] indent with tabs --- client/homebrew/navbar/vault.navitem.jsx | 13 +- client/homebrew/pages/vaultPage/vaultPage.jsx | 820 +++++++++--------- server/vault.api.js | 174 ++-- 3 files changed, 506 insertions(+), 501 deletions(-) diff --git a/client/homebrew/navbar/vault.navitem.jsx b/client/homebrew/navbar/vault.navitem.jsx index 8752b8e0f..51c5c341d 100644 --- a/client/homebrew/navbar/vault.navitem.jsx +++ b/client/homebrew/navbar/vault.navitem.jsx @@ -2,11 +2,16 @@ const React = require('react'); const Nav = require('naturalcrit/nav/nav.jsx'); -module.exports = function(props){ - return + rel="noopener noreferrer" + > Vault + ); }; diff --git a/client/homebrew/pages/vaultPage/vaultPage.jsx b/client/homebrew/pages/vaultPage/vaultPage.jsx index 59e831aa4..377260d0f 100644 --- a/client/homebrew/pages/vaultPage/vaultPage.jsx +++ b/client/homebrew/pages/vaultPage/vaultPage.jsx @@ -16,458 +16,458 @@ const SplitPane = require('../../../../shared/naturalcrit/splitPane/splitPane.js const request = require('../../utils/request-middleware.js'); const VaultPage = (props) => { - const [title, setTitle] = useState(props.query.title || ''); - //state author - const [author, setAuthor] = useState(props.query.author || ''); - const [legacy, setLegacy] = useState(props.query.legacy !== 'false'); - const [v3, setV3] = useState(props.query.v3 !== 'false'); - const [count, setCount] = useState(props.query.count || 20); - const [page, setPage] = useState(parseInt(props.query.page) || 1); - const [brewCollection, setBrewCollection] = useState(null); - const [totalBrews, setTotalBrews] = useState(null); - const [searching, setSearching] = useState(false); - const [error, setError] = useState(null); + const [title, setTitle] = useState(props.query.title || ''); + //state author + const [author, setAuthor] = useState(props.query.author || ''); + const [legacy, setLegacy] = useState(props.query.legacy !== 'false'); + const [v3, setV3] = useState(props.query.v3 !== 'false'); + const [count, setCount] = useState(props.query.count || 20); + const [page, setPage] = useState(parseInt(props.query.page) || 1); + const [brewCollection, setBrewCollection] = useState(null); + const [totalBrews, setTotalBrews] = useState(null); + const [searching, setSearching] = useState(false); + const [error, setError] = useState(null); - const titleRef = useRef(null); - const authorRef = useRef(null); - const countRef = useRef(null); - const v3Ref = useRef(null); - const legacyRef = useRef(null); - const searchButtonRef = useRef(null); + const titleRef = useRef(null); + const authorRef = useRef(null); + const countRef = useRef(null); + const v3Ref = useRef(null); + const legacyRef = useRef(null); + const searchButtonRef = useRef(null); - useEffect(() => { - disableSubmitIfFormInvalid(); - loadPage(page, false, true); - }, []); + useEffect(() => { + disableSubmitIfFormInvalid(); + loadPage(page, false, true); + }, []); - const updateStateWithBrews = (brews, page) => { - setBrewCollection(brews || null); - setPage(parseInt(page) || 1); - setSearching(false); - }; + const updateStateWithBrews = (brews, page) => { + setBrewCollection(brews || null); + setPage(parseInt(page) || 1); + setSearching(false); + }; - const updateUrl = (title, author, count, v3, legacy, page) => { - const url = new URL(window.location.href); - const urlParams = new URLSearchParams(); + const updateUrl = (title, author, count, v3, legacy, page) => { + const url = new URL(window.location.href); + const urlParams = new URLSearchParams(); - Object.entries({ - title, - author, - count, - v3, - legacy, - page, - }).forEach(([key, value]) => urlParams.set(key, value)); + Object.entries({ + title, + author, + count, + v3, + legacy, + page, + }).forEach(([key, value]) => urlParams.set(key, value)); - url.search = urlParams.toString(); - window.history.replaceState(null, null, url); - }; + url.search = urlParams.toString(); + window.history.replaceState(null, null, url); + }; - const loadPage = async (page, update, total) => { - //Different searches use the update or total props to make only the necessary queries and functions + const loadPage = async (page, update, total) => { + //Different searches use the update or total props to make only the necessary queries and functions - if (!validateForm()) { - return; - } + if (!validateForm()) { + return; + } - setSearching(true); - setError(null); + setSearching(true); + setError(null); - const performSearch = async ({ title, author, count, v3, legacy }) => { - updateUrl(title, author, count, v3, legacy, page); - console.log(title, author, count, v3, legacy); - if ((title || author) && (v3 || legacy)) { - try { - const response = await request.get( - `/api/vault?title=${title}&author=${author}&v3=${v3}&legacy=${legacy}&count=${count}&page=${page}` - ); - if (response.ok) { - updateStateWithBrews(response.body.brews, page); - } else { - throw new Error(`Error: ${response.status}`); - } - } catch (error) { - console.log('error at loadPage: ', error); - setError( - `${ - error.response - ? error.response.status - : error.message - }` - ); - updateStateWithBrews([], 1); - } - } else { - setError('404'); - } - }; + const performSearch = async ({ title, author, count, v3, legacy }) => { + updateUrl(title, author, count, v3, legacy, page); + console.log(title, author, count, v3, legacy); + if ((title || author) && (v3 || legacy)) { + try { + const response = await request.get( + `/api/vault?title=${title}&author=${author}&v3=${v3}&legacy=${legacy}&count=${count}&page=${page}` + ); + if (response.ok) { + updateStateWithBrews(response.body.brews, page); + } else { + throw new Error(`Error: ${response.status}`); + } + } catch (error) { + console.log('error at loadPage: ', error); + setError( + `${ + error.response + ? error.response.status + : error.message + }` + ); + updateStateWithBrews([], 1); + } + } else { + setError('404'); + } + }; - const loadTotal = async ({ title, v3, legacy }) => { - setTotalBrews(null); - setError(null); - if ((title || author) && (v3 || legacy)) { - try { - const response = await request.get( - `/api/vault/total?title=${title}&author=${author}&v3=${v3}&legacy=${legacy}` - ); + const loadTotal = async ({ title, v3, legacy }) => { + setTotalBrews(null); + setError(null); + if ((title || author) && (v3 || legacy)) { + try { + const response = await request.get( + `/api/vault/total?title=${title}&author=${author}&v3=${v3}&legacy=${legacy}` + ); - if (response.ok) { - setTotalBrews(response.body.totalBrews); - } else { - throw new Error( - `Failed to load total brews: ${response.statusText}` - ); - } - } catch (error) { - console.log('error at loadTotal: ', error); - setError(`${error.response.status}`); - updateStateWithBrews([], 1); - } - } - }; + if (response.ok) { + setTotalBrews(response.body.totalBrews); + } else { + throw new Error( + `Failed to load total brews: ${response.statusText}` + ); + } + } catch (error) { + console.log('error at loadTotal: ', error); + setError(`${error.response.status}`); + updateStateWithBrews([], 1); + } + } + }; - const title = titleRef.current.value || ''; - const author = authorRef.current.value || ''; - const count = countRef.current.value || 10; - const v3 = v3Ref.current.checked != false; - const legacy = legacyRef.current.checked != false; + const title = titleRef.current.value || ''; + const author = authorRef.current.value || ''; + const count = countRef.current.value || 10; + const v3 = v3Ref.current.checked != false; + const legacy = legacyRef.current.checked != false; - console.log(title); - if (update) { - setTitle(title); - setAuthor(author); - setCount(count); - setV3(v3); - setLegacy(legacy); - } + console.log(title); + if (update) { + setTitle(title); + setAuthor(author); + setCount(count); + setV3(v3); + setLegacy(legacy); + } - // Perform search with the latest input values, because state is not fast enough - performSearch({ title, author, count, v3, legacy }); + // Perform search with the latest input values, because state is not fast enough + performSearch({ title, author, count, v3, legacy }); - if (total) { - loadTotal({ title, author, v3, legacy }); - } - }; + if (total) { + loadTotal({ title, author, v3, legacy }); + } + }; - const renderNavItems = () => ( - - - - Vault: Search for brews - - - - - - - - - - ); + const renderNavItems = () => ( + + + + Vault: Search for brews + + + + + + + + + + ); - const validateForm = () => { - //form validity: title or author must be written, and at least one renderer set - const { current: titleInput } = titleRef; - const { current: legacyCheckbox } = legacyRef; - const { current: v3Checkbox } = v3Ref; - const { current: authorInput } = authorRef; + const validateForm = () => { + //form validity: title or author must be written, and at least one renderer set + const { current: titleInput } = titleRef; + const { current: legacyCheckbox } = legacyRef; + const { current: v3Checkbox } = v3Ref; + const { current: authorInput } = authorRef; - const isTitleValid = titleInput.validity.valid && titleInput.value; - //because a pattern attr is set in the input, title must be over 2 chars long - const isAuthorValid = authorInput.validity.valid && authorInput.value; - const isCheckboxChecked = legacyCheckbox.checked || v3Checkbox.checked; + const isTitleValid = titleInput.validity.valid && titleInput.value; + //because a pattern attr is set in the input, title must be over 2 chars long + const isAuthorValid = authorInput.validity.valid && authorInput.value; + const isCheckboxChecked = legacyCheckbox.checked || v3Checkbox.checked; - const isFormValid = - (isTitleValid || isAuthorValid) && isCheckboxChecked; + const isFormValid = + (isTitleValid || isAuthorValid) && isCheckboxChecked; - return isFormValid; - }; + return isFormValid; + }; - const disableSubmitIfFormInvalid = () => { - const { current: submitButton } = searchButtonRef; - submitButton.disabled = !validateForm(); - }; + const disableSubmitIfFormInvalid = () => { + const { current: submitButton } = searchButtonRef; + submitButton.disabled = !validateForm(); + }; - const renderForm = () => ( -
    -

    Brew Lookup

    -
    - + const renderForm = () => ( +
    +

    Brew Lookup

    +
    + - + - + - + - + - -
    - -

    Tips and tricks

    -
      -
    • - You can only search brews with this tool if they are - published -
    • -
    • - Usernames are case sensitive, make sure you are writing - it correctly -
    • -
    • - You can use - to negate words, assuming - there is any word not negated, and "word" - to specify an exact string. -
    • + +
    + +

    Tips and tricks

    +
      +
    • + You can only search brews with this tool if they are + published +
    • +
    • + Usernames are case sensitive, make sure you are writing + it correctly +
    • +
    • + You can use - to negate words, assuming + there is any word not negated, and "word" + to specify an exact string. +
    • -
    • - Some words like a, after, through, itself, or here, are - ignored in searches, make sure your search has relevant - words. The full list can be found   - - here - -
    • -
    -
    - -
    - ); +
  • + Some words like a, after, through, itself, or here, are + ignored in searches, make sure your search has relevant + words. The full list can be found   + + here + +
  • + + + +
    + ); - const renderPaginationControls = () => { - if (!totalBrews) return null; + const renderPaginationControls = () => { + if (!totalBrews) return null; - const countInt = parseInt(count); - const totalPages = Math.ceil(totalBrews / countInt); + const countInt = parseInt(count); + const totalPages = Math.ceil(totalBrews / countInt); - let startPage, endPage; - if (page <= 6) { - startPage = 1; - endPage = Math.min(totalPages, 10); - } else if (page + 4 >= totalPages) { - startPage = Math.max(1, totalPages - 9); - endPage = totalPages; - } else { - startPage = page - 5; - endPage = page + 4; - } + let startPage, endPage; + if (page <= 6) { + startPage = 1; + endPage = Math.min(totalPages, 10); + } else if (page + 4 >= totalPages) { + startPage = Math.max(1, totalPages - 9); + endPage = totalPages; + } else { + startPage = page - 5; + endPage = page + 4; + } - const pagesAroundCurrent = new Array(endPage - startPage + 1) - .fill() - .map((_, index) => ( - loadPage(startPage + index, false, false)} - > - {startPage + index} - - )); + const pagesAroundCurrent = new Array(endPage - startPage + 1) + .fill() + .map((_, index) => ( + loadPage(startPage + index, false, false)} + > + {startPage + index} + + )); - return ( -
    - -
      - {startPage > 1 && ( - loadPage(1, false, false)} - > - 1 ... - - )} - {pagesAroundCurrent} - {endPage < totalPages && ( - loadPage(totalPages, false, false)} - > - ... {totalPages} - - )} -
    - -
    - ); - }; + return ( +
    + +
      + {startPage > 1 && ( + loadPage(1, false, false)} + > + 1 ... + + )} + {pagesAroundCurrent} + {endPage < totalPages && ( + loadPage(totalPages, false, false)} + > + ... {totalPages} + + )} +
    + +
    + ); + }; - const renderFoundBrews = () => { - if (searching) { - return ( -
    -

    Searching

    -
    - ); - } + const renderFoundBrews = () => { + if (searching) { + return ( +
    +

    Searching

    +
    + ); + } - if (error) { - console.log('render Error: ', error); - let errorMessage; - switch (error.errorCode) { - case '404': - errorMessage = "404 - We didn't find any brew"; - break; - case '503': - errorMessage = - '503 - Service Unavailable, try again later, sorry.'; - break; - case '500': - errorMessage = - "500 - We don't know what happened, go ahead and contact the mods or report as a mistake."; - break; - default: - errorMessage = 'An unexpected error occurred'; - } + if (error) { + console.log('render Error: ', error); + let errorMessage; + switch (error.errorCode) { + case '404': + errorMessage = "404 - We didn't find any brew"; + break; + case '503': + errorMessage = + '503 - Service Unavailable, try again later, sorry.'; + break; + case '500': + errorMessage = + "500 - We don't know what happened, go ahead and contact the mods or report as a mistake."; + break; + default: + errorMessage = 'An unexpected error occurred'; + } - return ( -
    -

    Error: {errorMessage}

    -
    - ); - } + return ( +
    +

    Error: {errorMessage}

    +
    + ); + } - if (!brewCollection) { - return ( -
    -

    No search yet

    -
    - ); - } + if (!brewCollection) { + return ( +
    +

    No search yet

    +
    + ); + } - if (brewCollection.length === 0) { - return ( -
    -

    No brews found

    -
    - ); - } + if (brewCollection.length === 0) { + return ( +
    +

    No brews found

    +
    + ); + } - return ( -
    - - {`Brews found: `} - {totalBrews} - - {brewCollection.map((brew, index) => ( - - ))} - {renderPaginationControls()} -
    - ); - }; + return ( +
    + + {`Brews found: `} + {totalBrews} + + {brewCollection.map((brew, index) => ( + + ))} + {renderPaginationControls()} +
    + ); + }; - return ( -
    - - - {renderNavItems()} -
    - -
    {renderForm()}
    + return ( +
    + + + {renderNavItems()} +
    + +
    {renderForm()}
    -
    - {renderFoundBrews()} -
    -
    -
    -
    - ); +
    + {renderFoundBrews()} +
    +
    +
    +
    + ); }; module.exports = VaultPage; diff --git a/server/vault.api.js b/server/vault.api.js index 996ccf536..6a5b58140 100644 --- a/server/vault.api.js +++ b/server/vault.api.js @@ -5,121 +5,121 @@ const HomebrewModel = require('./homebrew.model.js').model; const router = express.Router(); const buildTitleConditions = (title) => { - if (!title) return {}; - return { - $text: { - $search: title, - $caseSensitive: false, - }, - }; + if (!title) return {}; + return { + $text: { + $search: title, + $caseSensitive: false, + }, + }; }; const buildAuthorConditions = (author) => { - if (!author) return {}; - return { authors: author }; + if (!author) return {}; + return { authors: author }; }; //"$and": [ {"published": true}, {"$text": { "$search": "titleString", "$caseSensitive": false } }, { "authors" : "authorString"}] //is a good example of a query constructed with this function const handleErrorResponse = (res, error, functionName) => { - const status = error.response?.status || 500; - const message = - status === 503 ? 'Service Unavailable' : 'Internal Server Error'; + const status = error.response?.status || 500; + const message = + status === 503 ? 'Service Unavailable' : 'Internal Server Error'; - console.error(`Error in ${functionName}:`, error); + console.error(`Error in ${functionName}:`, error); - return res.status(status).json({ - errorCode: status.toString(), - message: `Error in function ${functionName}: ${message}`, - }); + return res.status(status).json({ + errorCode: status.toString(), + message: `Error in function ${functionName}: ${message}`, + }); }; const buildBrewsQuery = (legacy, v3) => { - const brewsQuery = { published: true }; - if (legacy === 'true' && v3 === 'true') return { published: true }; + const brewsQuery = { published: true }; + if (legacy === 'true' && v3 === 'true') return { published: true }; - if (legacy === 'true' && v3 !== 'true') { - brewsQuery.renderer = 'legacy'; - } else if (v3 === 'true' && legacy !== 'true') { - brewsQuery.renderer = 'V3'; - } + if (legacy === 'true' && v3 !== 'true') { + brewsQuery.renderer = 'legacy'; + } else if (v3 === 'true' && legacy !== 'true') { + brewsQuery.renderer = 'V3'; + } - return brewsQuery; + return brewsQuery; }; const vault = { - findBrews: async (req, res) => { - try { - const title = req.query.title || ''; - const author = req.query.author || ''; - const page = Math.max(parseInt(req.query.page) || 1, 1); - const mincount = 10; - const count = Math.max(parseInt(req.query.count) || 20, mincount); - const skip = (page - 1) * count; + findBrews: async (req, res) => { + try { + const title = req.query.title || ''; + const author = req.query.author || ''; + const page = Math.max(parseInt(req.query.page) || 1, 1); + const mincount = 10; + const count = Math.max(parseInt(req.query.count) || 20, mincount); + const skip = (page - 1) * count; - const brewsQuery = buildBrewsQuery(req.query.legacy, req.query.v3); - const titleConditions = buildTitleConditions(title); - const authorConditions = buildAuthorConditions(author); + const brewsQuery = buildBrewsQuery(req.query.legacy, req.query.v3); + const titleConditions = buildTitleConditions(title); + const authorConditions = buildAuthorConditions(author); - const combinedQuery = { - $and: [brewsQuery, titleConditions, authorConditions], - }; + const combinedQuery = { + $and: [brewsQuery, titleConditions, authorConditions], + }; - const projection = { - editId: 0, - googleId: 0, - text: 0, - textBin: 0, - version: 0, - thumbnail: 0, - }; + const projection = { + editId: 0, + googleId: 0, + text: 0, + textBin: 0, + version: 0, + thumbnail: 0, + }; - const brews = await HomebrewModel.find(combinedQuery, projection) - .skip(skip) - .limit(count) - .maxTimeMS(5000) - .exec(); + const brews = await HomebrewModel.find(combinedQuery, projection) + .skip(skip) + .limit(count) + .maxTimeMS(5000) + .exec(); - console.log( - 'Query in findBrews: ', - JSON.stringify(combinedQuery, null, 2) - ); - return res.json({ brews, page }); - } catch (error) { - console.error(error); - return handleErrorResponse(res, error, 'findBrews'); - } - }, + console.log( + 'Query in findBrews: ', + JSON.stringify(combinedQuery, null, 2) + ); + return res.json({ brews, page }); + } catch (error) { + console.error(error); + return handleErrorResponse(res, error, 'findBrews'); + } + }, - findTotal: async (req, res) => { - try { - const title = req.query.title || ''; - const author = req.query.author || ''; + findTotal: async (req, res) => { + try { + const title = req.query.title || ''; + const author = req.query.author || ''; - const brewsQuery = buildBrewsQuery(req.query.legacy, req.query.v3); - const titleConditions = buildTitleConditions(title); - const authorConditions = buildAuthorConditions(author); + const brewsQuery = buildBrewsQuery(req.query.legacy, req.query.v3); + const titleConditions = buildTitleConditions(title); + const authorConditions = buildAuthorConditions(author); - const combinedQuery = { - $and: [brewsQuery, titleConditions, authorConditions], - }; + const combinedQuery = { + $and: [brewsQuery, titleConditions, authorConditions], + }; - const totalBrews = await HomebrewModel.countDocuments( - combinedQuery - ); - console.log( - 'when returning, the total of brews is ', - totalBrews, - 'for the query', - JSON.stringify(combinedQuery) - ); - return res.json({ totalBrews }); - } catch (error) { - console.error(error); - return handleErrorResponse(res, error, 'findTotal'); - } - }, + const totalBrews = await HomebrewModel.countDocuments( + combinedQuery + ); + console.log( + 'when returning, the total of brews is ', + totalBrews, + 'for the query', + JSON.stringify(combinedQuery) + ); + return res.json({ totalBrews }); + } catch (error) { + console.error(error); + return handleErrorResponse(res, error, 'findTotal'); + } + }, }; router.get('/api/vault/total', asyncHandler(vault.findTotal)); From fb8c4c5c444dc62fc6187712ad4a283cbb4362a0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?V=C3=ADctor=20Losada=20Hern=C3=A1ndez?= Date: Sat, 31 Aug 2024 22:28:29 +0200 Subject: [PATCH 173/252] all sugggested changes --- server/vault.api.js | 144 ++++++++++++++++++++++---------------------- 1 file changed, 71 insertions(+), 73 deletions(-) diff --git a/server/vault.api.js b/server/vault.api.js index 6a5b58140..1406895a6 100644 --- a/server/vault.api.js +++ b/server/vault.api.js @@ -19,25 +19,8 @@ const buildAuthorConditions = (author) => { return { authors: author }; }; -//"$and": [ {"published": true}, {"$text": { "$search": "titleString", "$caseSensitive": false } }, { "authors" : "authorString"}] -//is a good example of a query constructed with this function - -const handleErrorResponse = (res, error, functionName) => { - const status = error.response?.status || 500; - const message = - status === 503 ? 'Service Unavailable' : 'Internal Server Error'; - - console.error(`Error in ${functionName}:`, error); - - return res.status(status).json({ - errorCode: status.toString(), - message: `Error in function ${functionName}: ${message}`, - }); -}; - -const buildBrewsQuery = (legacy, v3) => { - const brewsQuery = { published: true }; - if (legacy === 'true' && v3 === 'true') return { published: true }; +const buildRendererConditions = (legacy, v3) => { + const brewsQuery = {}; if (legacy === 'true' && v3 !== 'true') { brewsQuery.renderer = 'legacy'; @@ -48,81 +31,96 @@ const buildBrewsQuery = (legacy, v3) => { return brewsQuery; }; -const vault = { - findBrews: async (req, res) => { - try { - const title = req.query.title || ''; - const author = req.query.author || ''; - const page = Math.max(parseInt(req.query.page) || 1, 1); - const mincount = 10; - const count = Math.max(parseInt(req.query.count) || 20, mincount); - const skip = (page - 1) * count; +// Function to find brews +const findBrews = async (req, res) => { + const title = req.query.title || ''; + const author = req.query.author || ''; + const page = Math.max(parseInt(req.query.page) || 1, 1); + const mincount = 10; + const count = Math.max(parseInt(req.query.count) || 20, mincount); + const skip = (page - 1) * count; - const brewsQuery = buildBrewsQuery(req.query.legacy, req.query.v3); - const titleConditions = buildTitleConditions(title); - const authorConditions = buildAuthorConditions(author); + const brewsQuery = buildRendererConditions(req.query.legacy, req.query.v3); + const titleConditions = buildTitleConditions(title); + const authorConditions = buildAuthorConditions(author); - const combinedQuery = { - $and: [brewsQuery, titleConditions, authorConditions], - }; + const combinedQuery = { + $and: [ + { published: true }, + brewsQuery, + titleConditions, + authorConditions, + ], + }; - const projection = { - editId: 0, - googleId: 0, - text: 0, - textBin: 0, - version: 0, - thumbnail: 0, - }; - - const brews = await HomebrewModel.find(combinedQuery, projection) - .skip(skip) - .limit(count) - .maxTimeMS(5000) - .exec(); + const projection = { + editId: 0, + googleId: 0, + text: 0, + textBin: 0, + version: 0, + thumbnail: 0, + }; + await HomebrewModel.find(combinedQuery, projection) + .skip(skip) + .limit(count) + .maxTimeMS(5000) + .exec() + .then((brews) => { console.log( 'Query in findBrews: ', JSON.stringify(combinedQuery, null, 2) ); - return res.json({ brews, page }); - } catch (error) { + res.json({ brews, page }); + }) + .catch((error) => { console.error(error); - return handleErrorResponse(res, error, 'findBrews'); - } - }, + res.status(500).json({ + error: 'Error finding brews in Vault search', + HBErrorCode: '99', + }); + }); +}; - findTotal: async (req, res) => { - try { - const title = req.query.title || ''; - const author = req.query.author || ''; +// Function to find total brews +const findTotal = async (req, res) => { + const title = req.query.title || ''; + const author = req.query.author || ''; - const brewsQuery = buildBrewsQuery(req.query.legacy, req.query.v3); - const titleConditions = buildTitleConditions(title); - const authorConditions = buildAuthorConditions(author); + const brewsQuery = buildRendererConditions(req.query.legacy, req.query.v3); + const titleConditions = buildTitleConditions(title); + const authorConditions = buildAuthorConditions(author); - const combinedQuery = { - $and: [brewsQuery, titleConditions, authorConditions], - }; + const combinedQuery = { + $and: [ + { published: true }, + brewsQuery, + titleConditions, + authorConditions, + ], + }; - const totalBrews = await HomebrewModel.countDocuments( - combinedQuery - ); + await HomebrewModel.countDocuments(combinedQuery) + .then((totalBrews) => { console.log( 'when returning, the total of brews is ', totalBrews, 'for the query', JSON.stringify(combinedQuery) ); - return res.json({ totalBrews }); - } catch (error) { + res.json({ totalBrews }); + }) + .catch((error) => { console.error(error); - return handleErrorResponse(res, error, 'findTotal'); - } - }, + res.status(500).json({ + error: 'Error finding brews in Vault search find total search', + HBErrorCode: '99', + }); + }); }; -router.get('/api/vault/total', asyncHandler(vault.findTotal)); -router.get('/api/vault', asyncHandler(vault.findBrews)); +router.get('/api/vault/total', asyncHandler(findTotal)); +router.get('/api/vault', asyncHandler(findBrews)); module.exports = router; From df21f978df5f201c7afff94151fb9544051e96fc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?V=C3=ADctor=20Losada=20Hern=C3=A1ndez?= Date: Sat, 31 Aug 2024 22:34:04 +0200 Subject: [PATCH 174/252] bring back throws --- server/vault.api.js | 13 +++---------- 1 file changed, 3 insertions(+), 10 deletions(-) diff --git a/server/vault.api.js b/server/vault.api.js index 1406895a6..7c489efd7 100644 --- a/server/vault.api.js +++ b/server/vault.api.js @@ -28,10 +28,10 @@ const buildRendererConditions = (legacy, v3) => { brewsQuery.renderer = 'V3'; } + //if all renderers are selected, doesn't make sense to add them to the query, it would only take longer return brewsQuery; }; -// Function to find brews const findBrews = async (req, res) => { const title = req.query.title || ''; const author = req.query.author || ''; @@ -76,14 +76,10 @@ const findBrews = async (req, res) => { }) .catch((error) => { console.error(error); - res.status(500).json({ - error: 'Error finding brews in Vault search', - HBErrorCode: '99', - }); + throw {...err, message: "Error finding brews in Vault search", HBErrorCode: '99'}; }); }; -// Function to find total brews const findTotal = async (req, res) => { const title = req.query.title || ''; const author = req.query.author || ''; @@ -113,10 +109,7 @@ const findTotal = async (req, res) => { }) .catch((error) => { console.error(error); - res.status(500).json({ - error: 'Error finding brews in Vault search find total search', - HBErrorCode: '99', - }); + throw {...err, message: "Error finding brews in Vault search", HBErrorCode: '99'}; }); }; From 9a2f18fc0d3ebfe6296fcb49f4059849d28dcab3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?V=C3=ADctor=20Losada=20Hern=C3=A1ndez?= Date: Sat, 31 Aug 2024 22:38:03 +0200 Subject: [PATCH 175/252] provide error code text --- client/homebrew/pages/errorPage/errors/errorIndex.js | 3 +++ 1 file changed, 3 insertions(+) diff --git a/client/homebrew/pages/errorPage/errors/errorIndex.js b/client/homebrew/pages/errorPage/errors/errorIndex.js index 957991ad6..3f4ecb969 100644 --- a/client/homebrew/pages/errorPage/errors/errorIndex.js +++ b/client/homebrew/pages/errorPage/errors/errorIndex.js @@ -171,6 +171,9 @@ const errorIndex = (props)=>{ **Brew ID:** ${props.brew.brewId} **Brew Title:** ${props.brew.brewTitle}`, + + '99' : dedent` An unexpected error ocurred while looking for these brews, try again in a few minutes, if this error persists, + contact the developers at the subreddit or discord provided in the home page.`, }; }; From bb08aed1a8f93a25edba603af7a2d26caa62f718 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?V=C3=ADctor=20Losada=20Hern=C3=A1ndez?= Date: Sat, 31 Aug 2024 22:43:54 +0200 Subject: [PATCH 176/252] move some css to prevent affecting brew cards --- .../homebrew/pages/vaultPage/vaultPage.less | 45 ++++++++++--------- 1 file changed, 23 insertions(+), 22 deletions(-) diff --git a/client/homebrew/pages/vaultPage/vaultPage.less b/client/homebrew/pages/vaultPage/vaultPage.less index f6e3ba7ff..7b19856f7 100644 --- a/client/homebrew/pages/vaultPage/vaultPage.less +++ b/client/homebrew/pages/vaultPage/vaultPage.less @@ -23,28 +23,6 @@ body { height : 100%; overflow-y : hidden; background-color : #2C3E50; - - h1, h2, h3, h4 { - font-family : 'CodeBold'; - letter-spacing : 2px; - } - - legend { - h3 { - margin-block : 30px 20px; - font-size : 20px; - text-align : center; - border-bottom : 2px solid; - } - ul { - padding-inline : 30px 10px; - li { - margin-block : 5px; - line-height : calc(1em + 5px); - list-style : disc; - } - } - } .content { @@ -59,6 +37,29 @@ body { position : relative; padding : 50px clamp(20px, 4vw, 50px); + h1, h2, h3, h4 { + font-family : 'CodeBold'; + letter-spacing : 2px; + } + + + legend { + h3 { + margin-block : 30px 20px; + font-size : 20px; + text-align : center; + border-bottom : 2px solid; + } + ul { + padding-inline : 30px 10px; + li { + margin-block : 5px; + line-height : calc(1em + 5px); + list-style : disc; + } + } + } + &::after { position : absolute; top : 0; From 47d8bb20d2b2323588c03243865a49de05d21a30 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?V=C3=ADctor=20Losada=20Hern=C3=A1ndez?= Date: Sat, 31 Aug 2024 23:12:24 +0200 Subject: [PATCH 177/252] hide usernames with emails --- .../basePages/listPage/brewItem/brewItem.jsx | 16 +++++--- client/homebrew/pages/vaultPage/vaultPage.jsx | 37 +++++++++++-------- 2 files changed, 32 insertions(+), 21 deletions(-) diff --git a/client/homebrew/pages/basePages/listPage/brewItem/brewItem.jsx b/client/homebrew/pages/basePages/listPage/brewItem/brewItem.jsx index bf0624f1c..01907bed4 100644 --- a/client/homebrew/pages/basePages/listPage/brewItem/brewItem.jsx +++ b/client/homebrew/pages/basePages/listPage/brewItem/brewItem.jsx @@ -141,11 +141,17 @@ const BrewItem = createClass({ : <> } - {brew.authors?.map((author, index)=>( - <> - {author} - {index < brew.authors.length - 1 && ', '} - ))} + + {brew.authors?.map((author, index) => ( + + {author === 'hidden' ? ( + {author} // Render as plain text if the author's name is "hidden" + ) : ( + {author} // Render as a link if not "hidden" + )} + {index < brew.authors.length - 1 && ', '} + + ))}
    diff --git a/client/homebrew/pages/vaultPage/vaultPage.jsx b/client/homebrew/pages/vaultPage/vaultPage.jsx index 377260d0f..b48a38360 100644 --- a/client/homebrew/pages/vaultPage/vaultPage.jsx +++ b/client/homebrew/pages/vaultPage/vaultPage.jsx @@ -435,22 +435,27 @@ const VaultPage = (props) => { } return ( -
    - - {`Brews found: `} - {totalBrews} - - {brewCollection.map((brew, index) => ( - - ))} - {renderPaginationControls()} -
    - ); - }; +
    + + {`Brews found: `} + {totalBrews} + + {brewCollection.map((brew, index) => { + const processedAuthors = brew.authors.map(author => + author.includes('@') ? 'hidden' : author + ); + return ( + + ); + })} + {renderPaginationControls()} +
    + ); + }; return (
    From c528c8639ab41ce3271fd16e3bcc0f7cf4079861 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?V=C3=ADctor=20Losada=20Hern=C3=A1ndez?= Date: Sat, 31 Aug 2024 23:21:14 +0200 Subject: [PATCH 178/252] title attribute to hidden authors --- .../homebrew/pages/basePages/listPage/brewItem/brewItem.jsx | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/client/homebrew/pages/basePages/listPage/brewItem/brewItem.jsx b/client/homebrew/pages/basePages/listPage/brewItem/brewItem.jsx index 01907bed4..8cec5c4b0 100644 --- a/client/homebrew/pages/basePages/listPage/brewItem/brewItem.jsx +++ b/client/homebrew/pages/basePages/listPage/brewItem/brewItem.jsx @@ -145,9 +145,9 @@ const BrewItem = createClass({ {brew.authors?.map((author, index) => ( {author === 'hidden' ? ( - {author} // Render as plain text if the author's name is "hidden" +  {author} ) : ( - {author} // Render as a link if not "hidden" + {author} )} {index < brew.authors.length - 1 && ', '} From f0b447866c79f2ba94cceda13894a5a4e4efe690 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?V=C3=ADctor=20Losada=20Hern=C3=A1ndez?= Date: Sun, 1 Sep 2024 11:10:46 +0200 Subject: [PATCH 179/252] suggested changes 2 --- .../basePages/listPage/brewItem/brewItem.jsx | 10 +- .../pages/errorPage/errors/errorIndex.js | 4 +- client/homebrew/pages/vaultPage/vaultPage.jsx | 140 +++++++----------- server/vault.api.js | 4 +- 4 files changed, 65 insertions(+), 93 deletions(-) diff --git a/client/homebrew/pages/basePages/listPage/brewItem/brewItem.jsx b/client/homebrew/pages/basePages/listPage/brewItem/brewItem.jsx index 8cec5c4b0..d569e4d02 100644 --- a/client/homebrew/pages/basePages/listPage/brewItem/brewItem.jsx +++ b/client/homebrew/pages/basePages/listPage/brewItem/brewItem.jsx @@ -144,12 +144,10 @@ const BrewItem = createClass({ {brew.authors?.map((author, index) => ( - {author === 'hidden' ? ( -  {author} - ) : ( - {author} - )} - {index < brew.authors.length - 1 && ', '} + {author === 'hidden' + ? {author} + : {author} + } ))} diff --git a/client/homebrew/pages/errorPage/errors/errorIndex.js b/client/homebrew/pages/errorPage/errors/errorIndex.js index 3f4ecb969..3df1fc7ae 100644 --- a/client/homebrew/pages/errorPage/errors/errorIndex.js +++ b/client/homebrew/pages/errorPage/errors/errorIndex.js @@ -172,8 +172,8 @@ const errorIndex = (props)=>{ **Brew Title:** ${props.brew.brewTitle}`, - '99' : dedent` An unexpected error ocurred while looking for these brews, try again in a few minutes, if this error persists, - contact the developers at the subreddit or discord provided in the home page.`, + '90' : dedent` An unexpected error occurred while looking for these brews. + Try again in a few minutes.`, }; }; diff --git a/client/homebrew/pages/vaultPage/vaultPage.jsx b/client/homebrew/pages/vaultPage/vaultPage.jsx index b48a38360..67d7c9fe0 100644 --- a/client/homebrew/pages/vaultPage/vaultPage.jsx +++ b/client/homebrew/pages/vaultPage/vaultPage.jsx @@ -2,7 +2,6 @@ require('./vaultPage.less'); const React = require('react'); const { useState, useEffect, useRef } = React; -const cx = require('classnames'); const Nav = require('naturalcrit/nav/nav.jsx'); const Navbar = require('../../navbar/navbar.jsx'); @@ -63,69 +62,57 @@ const VaultPage = (props) => { window.history.replaceState(null, null, url); }; + const performSearch = async ({ title, author, count, v3, legacy }) => { + updateUrl(title, author, count, v3, legacy, page); + console.log(title, author, count, v3, legacy); + if ((title || author) && (v3 || legacy)) { + const response = await request.get( + `/api/vault?title=${title}&author=${author}&v3=${v3}&legacy=${legacy}&count=${count}&page=${page}` + ).catch((error)=>{ + console.log('error at loadPage: ', error); + setError(`${error.response + ? error.response.status + : error.message}` + ); + updateStateWithBrews([], 1); + }); + + if (response.ok) + updateStateWithBrews(response.body.brews, page); + } else { + setError('404'); + } + }; + + const loadTotal = async ({ title, v3, legacy }) => { + setTotalBrews(null); + setError(null); + if ((title || author) && (v3 || legacy)) { + const response = await request.get( + `/api/vault/total?title=${title}&author=${author}&v3=${v3}&legacy=${legacy}` + ).catch((error)=>{ + console.log('error at loadTotal: ', error); + setError(`${error.response + ? error.response.status + : error.message}` + ); + updateStateWithBrews([], 1); + }); + + if (response.ok) + updateStateWithBrews(response.body.brews, page); + } + }; + const loadPage = async (page, update, total) => { //Different searches use the update or total props to make only the necessary queries and functions if (!validateForm()) { return; } - setSearching(true); setError(null); - const performSearch = async ({ title, author, count, v3, legacy }) => { - updateUrl(title, author, count, v3, legacy, page); - console.log(title, author, count, v3, legacy); - if ((title || author) && (v3 || legacy)) { - try { - const response = await request.get( - `/api/vault?title=${title}&author=${author}&v3=${v3}&legacy=${legacy}&count=${count}&page=${page}` - ); - if (response.ok) { - updateStateWithBrews(response.body.brews, page); - } else { - throw new Error(`Error: ${response.status}`); - } - } catch (error) { - console.log('error at loadPage: ', error); - setError( - `${ - error.response - ? error.response.status - : error.message - }` - ); - updateStateWithBrews([], 1); - } - } else { - setError('404'); - } - }; - - const loadTotal = async ({ title, v3, legacy }) => { - setTotalBrews(null); - setError(null); - if ((title || author) && (v3 || legacy)) { - try { - const response = await request.get( - `/api/vault/total?title=${title}&author=${author}&v3=${v3}&legacy=${legacy}` - ); - - if (response.ok) { - setTotalBrews(response.body.totalBrews); - } else { - throw new Error( - `Failed to load total brews: ${response.statusText}` - ); - } - } catch (error) { - console.log('error at loadTotal: ', error); - setError(`${error.response.status}`); - updateStateWithBrews([], 1); - } - } - }; - const title = titleRef.current.value || ''; const author = authorRef.current.value || ''; const count = countRef.current.value || 10; @@ -167,25 +154,18 @@ const VaultPage = (props) => { const validateForm = () => { //form validity: title or author must be written, and at least one renderer set - const { current: titleInput } = titleRef; - const { current: legacyCheckbox } = legacyRef; - const { current: v3Checkbox } = v3Ref; - const { current: authorInput } = authorRef; - const isTitleValid = titleInput.validity.valid && titleInput.value; - //because a pattern attr is set in the input, title must be over 2 chars long - const isAuthorValid = authorInput.validity.valid && authorInput.value; - const isCheckboxChecked = legacyCheckbox.checked || v3Checkbox.checked; + const isTitleValid = titleRef.current.validity.valid && titleRef.current.value; + const isAuthorValid = authorRef.current.validity.valid && authorRef.current.value; + const isCheckboxChecked = legacyRef.current.checked || v3Ref.current.checked; - const isFormValid = - (isTitleValid || isAuthorValid) && isCheckboxChecked; + const isFormValid = (isTitleValid || isAuthorValid) && isCheckboxChecked; return isFormValid; }; const disableSubmitIfFormInvalid = () => { - const { current: submitButton } = searchButtonRef; - submitButton.disabled = !validateForm(); + submitButtonRef.current.disabled = !validateForm(); }; const renderForm = () => ( @@ -274,10 +254,7 @@ const VaultPage = (props) => { > Search
    @@ -285,30 +262,27 @@ const VaultPage = (props) => {

    Tips and tricks

    • - You can only search brews with this tool if they are - published + Only published brews are searchable via this tool
    • Usernames are case sensitive, make sure you are writing it correctly
    • - You can use - to negate words, assuming - there is any word not negated, and "word" - to specify an exact string. + Use "word" to match an exact string, and + - to exclude words (at least one word + must not be negated).
    • - Some words like a, after, through, itself, or here, are - ignored in searches, make sure your search has relevant - words. The full list can be found   - - here - + Some common words like "a", "after", "through", "itself", "here", etc., + are ignored in searches. The full list can be found + + here +
    -
    ); diff --git a/server/vault.api.js b/server/vault.api.js index 7c489efd7..2b25779a3 100644 --- a/server/vault.api.js +++ b/server/vault.api.js @@ -76,7 +76,7 @@ const findBrews = async (req, res) => { }) .catch((error) => { console.error(error); - throw {...err, message: "Error finding brews in Vault search", HBErrorCode: '99'}; + throw {...err, message: "Error finding brews in Vault search", HBErrorCode: 90}; }); }; @@ -109,7 +109,7 @@ const findTotal = async (req, res) => { }) .catch((error) => { console.error(error); - throw {...err, message: "Error finding brews in Vault search", HBErrorCode: '99'}; + throw {...err, message: "Error finding brews in Vault search", HBErrorCode: 90}; }); }; From 3fc2e5202e3ff0fb7251bdcf0e60b6c38a08b513 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?V=C3=ADctor=20Losada=20Hern=C3=A1ndez?= Date: Sun, 1 Sep 2024 11:14:09 +0200 Subject: [PATCH 180/252] rest of the suggested changes --- .../pages/errorPage/errors/errorIndex.js | 2 ++ server/vault.api.js | 27 ++++++++----------- 2 files changed, 13 insertions(+), 16 deletions(-) diff --git a/client/homebrew/pages/errorPage/errors/errorIndex.js b/client/homebrew/pages/errorPage/errors/errorIndex.js index 3df1fc7ae..874d2d073 100644 --- a/client/homebrew/pages/errorPage/errors/errorIndex.js +++ b/client/homebrew/pages/errorPage/errors/errorIndex.js @@ -174,6 +174,8 @@ const errorIndex = (props)=>{ '90' : dedent` An unexpected error occurred while looking for these brews. Try again in a few minutes.`, + + '91' : dedent` An unexpected error occurred while trying to get the total of brews.`, }; }; diff --git a/server/vault.api.js b/server/vault.api.js index 2b25779a3..b03d2bb5b 100644 --- a/server/vault.api.js +++ b/server/vault.api.js @@ -4,7 +4,7 @@ const HomebrewModel = require('./homebrew.model.js').model; const router = express.Router(); -const buildTitleConditions = (title) => { +const titleConditions = (title) => { if (!title) return {}; return { $text: { @@ -14,12 +14,12 @@ const buildTitleConditions = (title) => { }; }; -const buildAuthorConditions = (author) => { +const authorConditions = (author) => { if (!author) return {}; return { authors: author }; }; -const buildRendererConditions = (legacy, v3) => { +const rendererConditions = (legacy, v3) => { const brewsQuery = {}; if (legacy === 'true' && v3 !== 'true') { @@ -40,9 +40,9 @@ const findBrews = async (req, res) => { const count = Math.max(parseInt(req.query.count) || 20, mincount); const skip = (page - 1) * count; - const brewsQuery = buildRendererConditions(req.query.legacy, req.query.v3); - const titleConditions = buildTitleConditions(title); - const authorConditions = buildAuthorConditions(author); + const brewsQuery = rendererConditions(req.query.legacy, req.query.v3); + const titleConditions = titleConditions(title); + const authorConditions = authorConditions(author); const combinedQuery = { $and: [ @@ -84,9 +84,9 @@ const findTotal = async (req, res) => { const title = req.query.title || ''; const author = req.query.author || ''; - const brewsQuery = buildRendererConditions(req.query.legacy, req.query.v3); - const titleConditions = buildTitleConditions(title); - const authorConditions = buildAuthorConditions(author); + const brewsQuery = rendererConditions(req.query.legacy, req.query.v3); + const titleConditions = titleConditions(title); + const authorConditions = authorConditions(author); const combinedQuery = { $and: [ @@ -99,17 +99,12 @@ const findTotal = async (req, res) => { await HomebrewModel.countDocuments(combinedQuery) .then((totalBrews) => { - console.log( - 'when returning, the total of brews is ', - totalBrews, - 'for the query', - JSON.stringify(combinedQuery) - ); + console.log(`when returning, the total of brews is ${totalBrews} for the query ${JSON.stringify(combinedQuery)}`); res.json({ totalBrews }); }) .catch((error) => { console.error(error); - throw {...err, message: "Error finding brews in Vault search", HBErrorCode: 90}; + throw {...err, message: "Error finding brews in Vault search findTotal function", HBErrorCode: 91}; }); }; From b6e904c9c8c9a603004c76fde5da65154acaff61 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?V=C3=ADctor=20Losada=20Hern=C3=A1ndez?= Date: Sun, 1 Sep 2024 11:19:00 +0200 Subject: [PATCH 181/252] "Rename searchButtonRef to submitButtonRef and update references" --- client/homebrew/pages/vaultPage/vaultPage.jsx | 18 ++++++------------ 1 file changed, 6 insertions(+), 12 deletions(-) diff --git a/client/homebrew/pages/vaultPage/vaultPage.jsx b/client/homebrew/pages/vaultPage/vaultPage.jsx index 67d7c9fe0..d722ba297 100644 --- a/client/homebrew/pages/vaultPage/vaultPage.jsx +++ b/client/homebrew/pages/vaultPage/vaultPage.jsx @@ -32,7 +32,7 @@ const VaultPage = (props) => { const countRef = useRef(null); const v3Ref = useRef(null); const legacyRef = useRef(null); - const searchButtonRef = useRef(null); + const submitButtonRef = useRef(null); useEffect(() => { disableSubmitIfFormInvalid(); @@ -183,11 +183,8 @@ const VaultPage = (props) => { pattern=".{3,}" title="At least 3 characters" onKeyDown={(e) => { - if (e.key === 'Enter') { - if (!searchButtonRef.current.disabled) { - loadPage(1, true, true); - } - } + if (e.key === 'Enter' && !submitButtonRef.current.disabled) + loadPage(1, true, true); }} placeholder="v3 Reference Document" /> @@ -203,11 +200,8 @@ const VaultPage = (props) => { defaultValue={author} onKeyUp={disableSubmitIfFormInvalid} onKeyDown={(e) => { - if (e.key === 'Enter') { - if (!searchButtonRef.current.disabled) { - loadPage(1, true, true); - } - } + if (e.key === 'Enter' && !submitButtonRef.current.disabled) + loadPage(1, true, true); }} placeholder="Gazook89" /> @@ -247,7 +241,7 @@ const VaultPage = (props) => { @@ -340,8 +341,8 @@ const VaultPage = (props) => { From 7474605b93d489f0306b89a44d6b0adb2342cb6e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?V=C3=ADctor=20Losada=20Hern=C3=A1ndez?= Date: Tue, 3 Sep 2024 15:58:31 +0200 Subject: [PATCH 189/252] rename 2 --- client/homebrew/pages/vaultPage/vaultPage.jsx | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/client/homebrew/pages/vaultPage/vaultPage.jsx b/client/homebrew/pages/vaultPage/vaultPage.jsx index 5eaa8dc91..3b73f6807 100644 --- a/client/homebrew/pages/vaultPage/vaultPage.jsx +++ b/client/homebrew/pages/vaultPage/vaultPage.jsx @@ -49,16 +49,16 @@ const VaultPage = (props) => { setSearching(false); }; - const updateUrl = (title, author, count, v3, legacy, page) => { + const updateUrl = (titleValue, authorValue, countValue, v3Value, legacyValue, page) => { const url = new URL(window.location.href); const urlParams = new URLSearchParams(); Object.entries({ - title, - author, - count, - v3, - legacy, + titleValue, + authorValue, + countValue, + v3Value, + legacyValue, page, }).forEach(([key, value]) => urlParams.set(key, value)); @@ -68,7 +68,7 @@ const VaultPage = (props) => { const performSearch = async ({ titleValue, authorValue, countValue, v3Value, legacyValue, page }) => { updateUrl(titleValue, authorValue, countValue, v3Value, legacyValue, page); - console.log(title, author, count, v3, legacy); + console.log(titleValue, authorValue, countValue, v3Value, legacyValue); if ((titleValue || authorValue) && (v3Value || legacyValue)) { const response = await request.get( `/api/vault?title=${titleValue}&author=${authorValue}&v3=${v3Value}&legacy=${legacyValue}&count=${countValue}&page=${page}` From 702f55bdbdecde98153a14f0cf551269535a4f26 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Tue, 3 Sep 2024 17:35:36 +0000 Subject: [PATCH 190/252] Bump eslint-plugin-jest from 28.8.0 to 28.8.2 Bumps [eslint-plugin-jest](https://github.com/jest-community/eslint-plugin-jest) from 28.8.0 to 28.8.2. - [Release notes](https://github.com/jest-community/eslint-plugin-jest/releases) - [Changelog](https://github.com/jest-community/eslint-plugin-jest/blob/main/CHANGELOG.md) - [Commits](https://github.com/jest-community/eslint-plugin-jest/compare/v28.8.0...v28.8.2) --- updated-dependencies: - dependency-name: eslint-plugin-jest dependency-type: direct:development update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] --- package-lock.json | 8 ++++---- package.json | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/package-lock.json b/package-lock.json index c1b24a6c2..27da64de0 100644 --- a/package-lock.json +++ b/package-lock.json @@ -52,7 +52,7 @@ "devDependencies": { "@stylistic/stylelint-plugin": "^3.0.1", "eslint": "^9.9.1", - "eslint-plugin-jest": "^28.8.0", + "eslint-plugin-jest": "^28.8.2", "eslint-plugin-react": "^7.35.0", "globals": "^15.9.0", "jest": "^29.7.0", @@ -5878,9 +5878,9 @@ } }, "node_modules/eslint-plugin-jest": { - "version": "28.8.0", - "resolved": "https://registry.npmjs.org/eslint-plugin-jest/-/eslint-plugin-jest-28.8.0.tgz", - "integrity": "sha512-Tubj1hooFxCl52G4qQu0edzV/+EZzPUeN8p2NnW5uu4fbDs+Yo7+qDVDc4/oG3FbCqEBmu/OC3LSsyiU22oghw==", + "version": "28.8.2", + "resolved": "https://registry.npmjs.org/eslint-plugin-jest/-/eslint-plugin-jest-28.8.2.tgz", + "integrity": "sha512-mC3OyklHmS5i7wYU1rGId9EnxRI8TVlnFG56AE+8U9iRy6zwaNygZR+DsdZuCL0gRG0wVeyzq+uWcPt6yJrrMA==", "dev": true, "dependencies": { "@typescript-eslint/utils": "^6.0.0 || ^7.0.0 || ^8.0.0" diff --git a/package.json b/package.json index 17c88f477..fd990c983 100644 --- a/package.json +++ b/package.json @@ -127,7 +127,7 @@ "devDependencies": { "@stylistic/stylelint-plugin": "^3.0.1", "eslint": "^9.9.1", - "eslint-plugin-jest": "^28.8.0", + "eslint-plugin-jest": "^28.8.2", "eslint-plugin-react": "^7.35.0", "globals": "^15.9.0", "jest": "^29.7.0", From 0d40f4eb162ab5f74cc89634c412947faf767cee Mon Sep 17 00:00:00 2001 From: Trevor Buckner Date: Tue, 3 Sep 2024 14:06:54 -0400 Subject: [PATCH 191/252] Small Rewording --- changelog.md | 33 +++++++++++---------------------- 1 file changed, 11 insertions(+), 22 deletions(-) diff --git a/changelog.md b/changelog.md index aa4fbe83f..7b3ea6384 100644 --- a/changelog.md +++ b/changelog.md @@ -85,42 +85,35 @@ pre { For a full record of development, visit our [Github Page](https://github.com/naturalcrit/homebrewery). ### Wednesday 8/28/2024 - v3.14.3 + {{taskList +##### calculuschild, G-Ambatte -##### Calculuschild +* [x] New {{openSans **IMAGES → {{fac,image-wrap-left}} IMAGE WRAP LEFT/RIGHT**}} snippets -* [x] Image wrapping snippets +Fixes issue [#380](https://github.com/naturalcrit/homebrewery/issues/380) -Fixes issue [#380](https://github.com/naturalcrit/homebrewery/issues/380), supersedes [#3126](https://github.com/naturalcrit/homebrewery/issues/3126) - -* [x] Add regex to detect when to interrupt a table - -Fixes v3.14.2 bug with tables and multiple colons +* [x] Fix v3.14.2 bug with `꞉꞉꞉꞉` failing after tables ##### 5e-Cleric -* [x] Fix Account page error for invalid users +* [x] Fix Account page crash when not logged in Fixes issue [#3605](https://github.com/naturalcrit/homebrewery/issues/3605) ##### dbolack-ab -* [x] Fix for jump hotkeys - -Fixes v3.14.2 bug; Preview and Source movement shortcuts now use `CTRL+SHIFT+META+Arrow` keys +* [x] Fix jump hotkeys conflicting with `CTRL + SHIFT`. Preview and Source movement shortcuts now use `CTRL + SHIFT + META + LEFT\RIGHTARROW` ##### G-Ambatte -* [x] Fix image wrap icons - -Fixes icons for new image wrap snippets - +* [x] Fix display issue with image wrap icons }} ### Tuesday 8/27/2024 - v3.14.2 -{{taskList +{{taskList ##### calculuschild * [x] Reroute invalid urls to homepage @@ -153,7 +146,7 @@ Fixes issues [#3572](https://github.com/naturalcrit/homebrewery/issues/3572) Fixes issues [#1430](https://github.com/naturalcrit/homebrewery/issues/1430) -* [x] Fix colon `:::` being parsed in codeblocks +* [x] Fix colon `꞉꞉꞉꞉` being parsed in codeblocks * [x] Prevent crashes when loading undefined renderer or theme bundle @@ -167,12 +160,11 @@ Fixes issues [#1430](https://github.com/naturalcrit/homebrewery/issues/1430) ##### 5e-Cleric, Gazook89 * [x] Viewer tools for zoom/page navigation - }} ### Tuesday 8/13/2024 - v3.14.1 -{{taskList +{{taskList ##### abquintic * [x] Allow Table of Contents to flow across columns @@ -215,16 +207,13 @@ Fixes issues [#3613](https://github.com/naturalcrit/homebrewery/issues/3613) Fixes issues [#3622](https://github.com/naturalcrit/homebrewery/issues/3622) - ##### calculuschild * [x] Fix `/migrate` page using an editor context instead of share context - ##### 5e-Cleric * [x] Fix Monster Stat Blocks losing color in Safari - }} \page From 36b026d89e0fc6fa1af33a193b427b8afa21f7a1 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Tue, 3 Sep 2024 18:09:47 +0000 Subject: [PATCH 192/252] Bump eslint-plugin-react from 7.35.0 to 7.35.1 Bumps [eslint-plugin-react](https://github.com/jsx-eslint/eslint-plugin-react) from 7.35.0 to 7.35.1. - [Release notes](https://github.com/jsx-eslint/eslint-plugin-react/releases) - [Changelog](https://github.com/jsx-eslint/eslint-plugin-react/blob/master/CHANGELOG.md) - [Commits](https://github.com/jsx-eslint/eslint-plugin-react/compare/v7.35.0...v7.35.1) --- updated-dependencies: - dependency-name: eslint-plugin-react dependency-type: direct:development update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] --- package-lock.json | 11 +++++------ package.json | 2 +- 2 files changed, 6 insertions(+), 7 deletions(-) diff --git a/package-lock.json b/package-lock.json index 843c5314d..de7bf5532 100644 --- a/package-lock.json +++ b/package-lock.json @@ -6,7 +6,7 @@ "packages": { "": { "name": "homebrewery", - "version": "3.14.2", + "version": "3.14.3", "hasInstallScript": true, "license": "MIT", "dependencies": { @@ -53,7 +53,7 @@ "@stylistic/stylelint-plugin": "^3.0.1", "eslint": "^9.9.1", "eslint-plugin-jest": "^28.8.2", - "eslint-plugin-react": "^7.35.0", + "eslint-plugin-react": "^7.35.1", "globals": "^15.9.0", "jest": "^29.7.0", "jest-expect-message": "^1.1.3", @@ -5903,11 +5903,10 @@ } }, "node_modules/eslint-plugin-react": { - "version": "7.35.0", - "resolved": "https://registry.npmjs.org/eslint-plugin-react/-/eslint-plugin-react-7.35.0.tgz", - "integrity": "sha512-v501SSMOWv8gerHkk+IIQBkcGRGrO2nfybfj5pLxuJNFTPxxA3PSryhXTK+9pNbtkggheDdsC0E9Q8CuPk6JKA==", + "version": "7.35.1", + "resolved": "https://registry.npmjs.org/eslint-plugin-react/-/eslint-plugin-react-7.35.1.tgz", + "integrity": "sha512-B5ok2JgbaaWn/zXbKCGgKDNL2tsID3Pd/c/yvjcpsd9HQDwyYc/TQv3AZMmOvrJgCs3AnYNUHRCQEMMQAYJ7Yg==", "dev": true, - "license": "MIT", "dependencies": { "array-includes": "^3.1.8", "array.prototype.findlast": "^1.2.5", diff --git a/package.json b/package.json index f7ec1fe72..0350bf5b3 100644 --- a/package.json +++ b/package.json @@ -128,7 +128,7 @@ "@stylistic/stylelint-plugin": "^3.0.1", "eslint": "^9.9.1", "eslint-plugin-jest": "^28.8.2", - "eslint-plugin-react": "^7.35.0", + "eslint-plugin-react": "^7.35.1", "globals": "^15.9.0", "jest": "^29.7.0", "jest-expect-message": "^1.1.3", From 9bc5701006f925953dd892f5b98a8fb7714a0cf1 Mon Sep 17 00:00:00 2001 From: Trevor Buckner Date: Tue, 3 Sep 2024 14:18:17 -0400 Subject: [PATCH 193/252] Indent --- .../basePages/listPage/brewItem/brewItem.jsx | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/client/homebrew/pages/basePages/listPage/brewItem/brewItem.jsx b/client/homebrew/pages/basePages/listPage/brewItem/brewItem.jsx index d569e4d02..bab58e722 100644 --- a/client/homebrew/pages/basePages/listPage/brewItem/brewItem.jsx +++ b/client/homebrew/pages/basePages/listPage/brewItem/brewItem.jsx @@ -141,15 +141,15 @@ const BrewItem = createClass({ : <> } - - {brew.authors?.map((author, index) => ( - - {author === 'hidden' - ? {author} - : {author} - } - - ))} + + {brew.authors?.map((author, index) => ( + + {author === 'hidden' + ? {author} + : {author} + } + + ))}
    From 3c6f49aa0a5bd3632ec2187db81d77c97406c8b9 Mon Sep 17 00:00:00 2001 From: Gazook89 Date: Tue, 3 Sep 2024 14:48:45 -0500 Subject: [PATCH 194/252] Move focus method to handleViewChange --- client/homebrew/editor/editor.jsx | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/client/homebrew/editor/editor.jsx b/client/homebrew/editor/editor.jsx index 0cc31cb40..24e975ebc 100644 --- a/client/homebrew/editor/editor.jsx +++ b/client/homebrew/editor/editor.jsx @@ -82,7 +82,6 @@ const Editor = createClass({ if(prevProps.moveSource !== this.props.moveSource) { this.sourceJump(); }; - this.codeEditor.current?.codeMirror.focus(); }, handleControlKeys : function(e){ @@ -114,7 +113,10 @@ const Editor = createClass({ this.props.setMoveArrows(newView === 'text'); this.setState({ view : newView - }, this.updateEditorSize); //TODO: not sure if updateeditorsize needed + }, ()=>{ + this.codeEditor.current?.codeMirror.focus(); + this.updateEditorSize(); + }); //TODO: not sure if updateeditorsize needed }, getCurrentPage : function(){ From 9e694e5e46530efcb8df10d4cf4054f2df595f56 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?V=C3=ADctor=20Losada=20Hern=C3=A1ndez?= Date: Tue, 3 Sep 2024 22:56:45 +0200 Subject: [PATCH 195/252] move email catching to api --- client/homebrew/pages/vaultPage/vaultPage.jsx | 5 +---- server/vault.api.js | 14 +++++++++----- 2 files changed, 10 insertions(+), 9 deletions(-) diff --git a/client/homebrew/pages/vaultPage/vaultPage.jsx b/client/homebrew/pages/vaultPage/vaultPage.jsx index 3b73f6807..fe6ff9736 100644 --- a/client/homebrew/pages/vaultPage/vaultPage.jsx +++ b/client/homebrew/pages/vaultPage/vaultPage.jsx @@ -393,12 +393,9 @@ const VaultPage = (props) => { {totalBrews} {brewCollection.map((brew, index) => { - const processedAuthors = brew.authors.map(author => - author.includes('@') ? 'hidden' : author - ); return ( diff --git a/server/vault.api.js b/server/vault.api.js index a652c5f93..b7db12699 100644 --- a/server/vault.api.js +++ b/server/vault.api.js @@ -68,11 +68,15 @@ const findBrews = async (req, res) => { .maxTimeMS(5000) .exec() .then((brews) => { - console.log( - 'Query in findBrews: ', - JSON.stringify(combinedQuery, null, 2) - ); - res.json({ brews, page }); + const emailRegex = /^[^\s@]+@[^\s@]+\.[^\s@]+$/; + + const processedBrews = brews.map((brew) => { + brew.authors = brew.authors.map(author => + emailRegex.test(author) ? 'hidden' : author + ); + return brew; + }); + res.json({ brews: processedBrews, page }); }) .catch((error) => { console.error(error); From 1e36e63ed65bf1467009d7eb1319840433883c54 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?V=C3=ADctor=20Losada=20Hern=C3=A1ndez?= Date: Tue, 3 Sep 2024 23:07:23 +0200 Subject: [PATCH 196/252] bring back the comma! --- .../homebrew/pages/basePages/listPage/brewItem/brewItem.jsx | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/client/homebrew/pages/basePages/listPage/brewItem/brewItem.jsx b/client/homebrew/pages/basePages/listPage/brewItem/brewItem.jsx index bab58e722..bace49e23 100644 --- a/client/homebrew/pages/basePages/listPage/brewItem/brewItem.jsx +++ b/client/homebrew/pages/basePages/listPage/brewItem/brewItem.jsx @@ -141,13 +141,13 @@ const BrewItem = createClass({ : <> } - - {brew.authors?.map((author, index) => ( + {brew.authors?.map((author, index) => ( {author === 'hidden' ? {author} : {author} } + {index < brew.authors.length - 1 && ', '} ))} From 849da23829f60b3bba7d765f588018230a15a9eb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?V=C3=ADctor=20Losada=20Hern=C3=A1ndez?= Date: Tue, 3 Sep 2024 23:17:33 +0200 Subject: [PATCH 197/252] bring back thumbnails! --- server/vault.api.js | 1 - 1 file changed, 1 deletion(-) diff --git a/server/vault.api.js b/server/vault.api.js index b7db12699..fbfa95de4 100644 --- a/server/vault.api.js +++ b/server/vault.api.js @@ -59,7 +59,6 @@ const findBrews = async (req, res) => { text: 0, textBin: 0, version: 0, - thumbnail: 0, }; await HomebrewModel.find(combinedQuery, projection) From e54d81ceefbc7758ec67b2138df198e5c35f16f1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?V=C3=ADctor=20Losada=20Hern=C3=A1ndez?= Date: Tue, 3 Sep 2024 23:28:33 +0200 Subject: [PATCH 198/252] small css fixes --- client/homebrew/pages/vaultPage/vaultPage.less | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/client/homebrew/pages/vaultPage/vaultPage.less b/client/homebrew/pages/vaultPage/vaultPage.less index 7b19856f7..31cf9a748 100644 --- a/client/homebrew/pages/vaultPage/vaultPage.less +++ b/client/homebrew/pages/vaultPage/vaultPage.less @@ -266,6 +266,15 @@ body { line-height : 1.5em; } } + + hr { + margin: 0px; + visibility: hidden; + } + + .thumbnail { + z-index:1; + } } .paginationControls { From ebae351033826d2170f7d2c669802f9223c3e991 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?V=C3=ADctor=20Losada=20Hern=C3=A1ndez?= Date: Wed, 4 Sep 2024 00:11:58 +0200 Subject: [PATCH 199/252] remove unnecesary state --- client/homebrew/pages/vaultPage/vaultPage.jsx | 46 +++++++------------ 1 file changed, 16 insertions(+), 30 deletions(-) diff --git a/client/homebrew/pages/vaultPage/vaultPage.jsx b/client/homebrew/pages/vaultPage/vaultPage.jsx index fe6ff9736..2af188cba 100644 --- a/client/homebrew/pages/vaultPage/vaultPage.jsx +++ b/client/homebrew/pages/vaultPage/vaultPage.jsx @@ -16,12 +16,6 @@ const ErrorIndex = require('../errorPage/errors/errorIndex.js'); const request = require('../../utils/request-middleware.js'); const VaultPage = (props) => { - //Form state - const [titleState, setTitle] = useState(props.query.title || ''); - const [authorState, setAuthor] = useState(props.query.author || ''); - const [legacyState, setLegacy] = useState(props.query.legacy !== 'false'); - const [v3State, setV3] = useState(props.query.v3 !== 'false'); - const [countState, setCount] = useState(props.query.count || 20); const [pageState, setPage] = useState(parseInt(props.query.page) || 1); //Response state @@ -51,24 +45,21 @@ const VaultPage = (props) => { const updateUrl = (titleValue, authorValue, countValue, v3Value, legacyValue, page) => { const url = new URL(window.location.href); - const urlParams = new URLSearchParams(); - - Object.entries({ - titleValue, - authorValue, - countValue, - v3Value, - legacyValue, - page, - }).forEach(([key, value]) => urlParams.set(key, value)); - + const urlParams = new URLSearchParams(url.search); + + urlParams.set('title', titleValue); + urlParams.set('author', authorValue); + urlParams.set('count', countValue); + urlParams.set('v3', v3Value); + urlParams.set('legacy', legacyValue); + urlParams.set('page', page); + url.search = urlParams.toString(); - window.history.replaceState(null, null, url); + window.history.replaceState(null, '', url.toString()); }; const performSearch = async ({ titleValue, authorValue, countValue, v3Value, legacyValue, page }) => { updateUrl(titleValue, authorValue, countValue, v3Value, legacyValue, page); - console.log(titleValue, authorValue, countValue, v3Value, legacyValue); if ((titleValue || authorValue) && (v3Value || legacyValue)) { const response = await request.get( `/api/vault?title=${titleValue}&author=${authorValue}&v3=${v3Value}&legacy=${legacyValue}&count=${countValue}&page=${page}` @@ -119,11 +110,6 @@ const VaultPage = (props) => { const legacyValue = legacyRef.current.checked != false; if (update) { - setTitle(titleValue); - setAuthor(authorValue); - setCount(countValue); - setV3(v3Value); - setLegacy(legacyValue); setPage(page); } @@ -177,7 +163,7 @@ const VaultPage = (props) => { ref={titleRef} type="text" name="title" - defaultValue={titleState} + defaultValue={props.query.title || ''} onKeyUp={disableSubmitIfFormInvalid} pattern=".{3,}" title="At least 3 characters" @@ -196,7 +182,7 @@ const VaultPage = (props) => { type="text" name="author" pattern=".{1,}" - defaultValue={authorState} + defaultValue={props.query.author || ''} onKeyUp={disableSubmitIfFormInvalid} onKeyDown={(e) => { if (e.key === 'Enter' && !submitButtonRef.current.disabled) @@ -208,7 +194,7 @@ const VaultPage = (props) => {