0
0
mirror of https://github.com/naturalcrit/homebrewery.git synced 2025-12-24 16:22:44 +00:00

"Removed ArchivePage and related files, replaced with VaultPage, updated routes and API endpoints, and made minor changes to theme configuration and error handling."

This commit is contained in:
Víctor Losada Hernández
2024-06-11 00:33:36 +02:00
parent 99b0c2b54e
commit 90431efbc9
8 changed files with 43 additions and 37 deletions

View File

@@ -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({
<Route path='/new/:id' element={<WithRoute el={NewPage} brew={this.props.brew} />} />
<Route path='/new' element={<WithRoute el={NewPage}/>} />
<Route path='/user/:username' element={<WithRoute el={UserPage} brews={this.props.brews} />} />
<Route path='/print/:id' element={<WithRoute el={PrintPage} brew={this.props.brew} />} />
<Route path='/print' element={<WithRoute el={PrintPage} />} />
<Route path='/changelog' element={<WithRoute el={SharePage} brew={this.props.brew} />} />
<Route path='/vault' element={<WithRoute el={VaultPage}/>}/>
<Route path='/faq' element={<WithRoute el={SharePage} brew={this.props.brew} />} />
<Route path='/account' element={<WithRoute el={AccountPage} brew={this.props.brew} accountDetails={this.props.brew.accountDetails} />} />
<Route path='/legacy' element={<WithRoute el={HomePage} brew={this.props.brew} />} />

View File

@@ -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 <div className='brewItem'>
{brew.thumbnail &&

View File

@@ -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 =
'<span class="searchAnim"></span>';
} 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) => {
<Navbar>
<Nav.section>
<Nav.item className="brewTitle">
Archive: Search for brews
Vault: Search for brews
</Nav.item>
</Nav.section>
<Nav.section>
@@ -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) => {
<div className="foundBrews">
<span className="totalBrews">
{`Brews found: `}
{title === '' ? (
'0'
) : totalBrews ? (
totalBrews
) : (
<span className="searchAnim"></span>
)}
<span ref={totalBrewsSpanRef}></span>
</span>
{brewCollection.map((brew, index) => (
<BrewItem
@@ -383,7 +392,7 @@ const ArchivePage = (props) => {
};
return (
<div className="archivePage">
<div className="vaultPage">
<link href="/themes/V3/Blank/style.css" rel="stylesheet" />
<link href="/themes/V3/5ePHB/style.css" rel="stylesheet" />
{renderNavItems()}
@@ -398,4 +407,4 @@ const ArchivePage = (props) => {
);
};
module.exports = ArchivePage;
module.exports = VaultPage;

View File

@@ -25,7 +25,7 @@ body {
}
}
.archivePage {
.vaultPage {
overflow-y: hidden;
height: 100%;
background-color: #2C3E50;

View File

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

View File

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

View File

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

View File

@@ -34,7 +34,7 @@
"renderer": "V3",
"baseTheme": false,
"baseSnippets": "5ePHB",
"path": "Journal"
"path": "journal"
}
}
}