0
0
mirror of https://github.com/naturalcrit/homebrewery.git synced 2026-01-03 08:22:42 +00:00

fix url params

This commit is contained in:
Víctor Losada Hernández
2024-01-23 18:35:09 +01:00
parent 162929bdca
commit 4ed9fc7d0e
2 changed files with 17 additions and 22 deletions

View File

@@ -76,7 +76,6 @@ const Homebrew = createClass({
<Route path='/print/:id' element={<WithRoute el={PrintPage} brew={this.props.brew} />} /> <Route path='/print/:id' element={<WithRoute el={PrintPage} brew={this.props.brew} />} />
<Route path='/print' element={<WithRoute el={PrintPage} />} /> <Route path='/print' element={<WithRoute el={PrintPage} />} />
<Route path='/archive' element={<WithRoute el={ArchivePage}/>}/> <Route path='/archive' element={<WithRoute el={ArchivePage}/>}/>
<Route path='/archive/:query' element={<WithRoute el={ArchivePage}/>}/>
<Route path='/changelog' element={<WithRoute el={SharePage} brew={this.props.brew} />} /> <Route path='/changelog' element={<WithRoute el={SharePage} brew={this.props.brew} />} />
<Route path='/faq' element={<WithRoute el={SharePage} brew={this.props.brew} />} /> <Route path='/faq' element={<WithRoute el={SharePage} brew={this.props.brew} />} />
<Route path='/account' element={<WithRoute el={AccountPage} brew={this.props.brew} uiItems={this.props.brew.uiItems} />} /> <Route path='/account' element={<WithRoute el={AccountPage} brew={this.props.brew} uiItems={this.props.brew.uiItems} />} />

View File

@@ -10,7 +10,7 @@ const RecentNavItem = require('../../navbar/recent.navitem.jsx').both;
const Account = require('../../navbar/account.navitem.jsx'); const Account = require('../../navbar/account.navitem.jsx');
const NewBrew = require('../../navbar/newbrew.navitem.jsx'); const NewBrew = require('../../navbar/newbrew.navitem.jsx');
const HelpNavItem = require('../../navbar/help.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'); const request = require('superagent');
@@ -21,34 +21,26 @@ const ArchivePage = createClass({
}, },
getInitialState: function () { getInitialState: function () {
return { return {
query : '', title : this.props.query.title || '',
brewCollection : null, brewCollection : null,
searching : false, searching : false,
error : null, error : null,
}; };
}, },
componentDidMount: function () { componentDidMount : function() {
const url = new URL(window.location.href); console.log(this.state.title);
const pathSegments = url.pathname.split('/'); this.lookup();
// 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) { handleChange(e) {
this.setState({ query: e.target.value }); this.setState({ title: e.target.value });
}, },
lookup() { lookup() {
this.setState({ searching: true, error: null }); this.setState({ searching: true, error: null });
request request
.get(`/archive/${this.state.query}`) .get(`/archive/${this.state.title}`)
.then((res) => this.setState({ brewCollection: res.body })) .then((res) => this.setState({ brewCollection: res.body }))
.catch((err) => this.setState({ error: err })) .catch((err) => this.setState({ error: err }))
.finally(() => this.setState({ searching: false })); .finally(() => this.setState({ searching: false }));
@@ -61,8 +53,8 @@ const ArchivePage = createClass({
urlParams.delete('dir'); urlParams.delete('dir');
urlParams.delete('filter'); urlParams.delete('filter');
// Set the pathname to '/archive/query' // Set the pathname to '/archive/?query'
url.pathname = `/archive/${this.state.query}`; urlParams.set('title', this.state.title);
url.search = urlParams; url.search = urlParams;
window.history.replaceState(null, null, url); window.history.replaceState(null, null, url);
@@ -73,9 +65,13 @@ const ArchivePage = createClass({
if (!brews || brews.length === 0) { if (!brews || brews.length === 0) {
return <div>No brews found.</div>; return <div>No brews found.</div>;
} }
console.table(brews);
this.updateUrl(); this.updateUrl();
return <ListPage brewCollection={this.state.brewCollection} /*navItems={this.navItems()}*/ reportError={this.errorReported}></ListPage>; return <div className="foundBrews">
{brews.map((brew, index) => (
<BrewItem brew={brew} key={index} reportError={this.props.reportError}/>
))}
</div>
}, },
@@ -86,7 +82,7 @@ const ArchivePage = createClass({
<label>Title of the brew</label> <label>Title of the brew</label>
<input <input
type='text' type='text'
value={this.state.query} value={this.state.title}
onChange={this.handleChange} onChange={this.handleChange}
placeholder='v3 Reference Document' placeholder='v3 Reference Document'
/> />