require('./archivePage.less'); const React = require('react'); const createClass = require('create-react-class'); const _ = require('lodash'); const cx = require('classnames'); const Nav = require('naturalcrit/nav/nav.jsx'); const Navbar = require('../../navbar/navbar.jsx'); const RecentNavItem = require('../../navbar/recent.navitem.jsx').both; const Account = require('../../navbar/account.navitem.jsx'); const NewBrew = require('../../navbar/newbrew.navitem.jsx'); const HelpNavItem = require('../../navbar/help.navitem.jsx'); const BrewItem = require('../basePages/listPage/brewItem/brewItem.jsx'); const request = require('superagent'); const ArchivePage = createClass({ displayName: 'ArchivePage', getDefaultProps: function () { return {}; }, getInitialState: function () { return { title : this.props.query.title || '', brewCollection : null, searching : false, error : null, limit : '', }; }, componentDidMount : function() { this.lookup(); }, handleChange(e) { this.setState({ title: e.target.value }); }, lookup() { this.setState({ searching: true, error: null }); request .get(`/archive/${this.state.title}`) .then((res) => this.setState({ brewCollection: res.body.brews }, this.setState({ limit: res.body.message}, this.setState({ error: null})))) .catch((err) => this.setState({ error: err })) .finally(() => this.setState({ searching: false })); }, updateUrl: function() { 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' urlParams.set('title', this.state.title); url.search = urlParams; window.history.replaceState(null, null, url); }, renderFoundBrews() { const brews = this.state.brewCollection; console.log('brews: ',brews); if (this.state.error !== null) { return(

I'm sorry, your request didn't work


Your search is not enough specific, too many brews meet this criteria for us to forward them.

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

Brew Lookup

{ if (e.key === 'Enter') { this.handleChange(e); this.lookup(); } }} placeholder='v3 Reference Document' /> {/* In the future, we should be able to filter the results by adding tags. */}
); }, renderNavItems: function () { return ( Archive: Search for brews ); }, render: function () { return (
{this.renderNavItems()}

Welcome to the Archive

{this.renderForm()}

Your results, my lordship

{this.renderFoundBrews()}
); }, }); module.exports = ArchivePage;