mirror of
https://github.com/naturalcrit/homebrewery.git
synced 2026-01-05 03:42:38 +00:00
Merge branch 'master' into erase-unnecessary-divs
This commit is contained in:
@@ -1,12 +1,11 @@
|
|||||||
const React = require('react');
|
const React = require('react');
|
||||||
const createClass = require('create-react-class');
|
const { useState } = React;
|
||||||
const _ = require('lodash');
|
const _ = require('lodash');
|
||||||
|
|
||||||
const ListPage = require('../basePages/listPage/listPage.jsx');
|
const ListPage = require('../basePages/listPage/listPage.jsx');
|
||||||
|
|
||||||
const Nav = require('naturalcrit/nav/nav.jsx');
|
const Nav = require('naturalcrit/nav/nav.jsx');
|
||||||
const Navbar = require('../../navbar/navbar.jsx');
|
const Navbar = require('../../navbar/navbar.jsx');
|
||||||
|
|
||||||
const RecentNavItem = require('../../navbar/recent.navitem.jsx').both;
|
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');
|
||||||
@@ -14,69 +13,48 @@ const HelpNavItem = require('../../navbar/help.navitem.jsx');
|
|||||||
const ErrorNavItem = require('../../navbar/error-navitem.jsx');
|
const ErrorNavItem = require('../../navbar/error-navitem.jsx');
|
||||||
const VaultNavitem = require('../../navbar/vault.navitem.jsx');
|
const VaultNavitem = require('../../navbar/vault.navitem.jsx');
|
||||||
|
|
||||||
const UserPage = createClass({
|
const UserPage = (props)=>{
|
||||||
displayName : 'UserPage',
|
props = {
|
||||||
getDefaultProps : function() {
|
username : '',
|
||||||
return {
|
brews : [],
|
||||||
username : '',
|
query : '',
|
||||||
brews : [],
|
...props
|
||||||
query : '',
|
};
|
||||||
error : null
|
|
||||||
};
|
|
||||||
},
|
|
||||||
getInitialState : function() {
|
|
||||||
const usernameWithS = this.props.username + (this.props.username.endsWith('s') ? `’` : `’s`);
|
|
||||||
|
|
||||||
const brews = _.groupBy(this.props.brews, (brew)=>{
|
const [error, setError] = useState(null);
|
||||||
return (brew.published ? 'published' : 'private');
|
|
||||||
});
|
|
||||||
|
|
||||||
const brewCollection = [
|
const usernameWithS = props.username + (props.username.endsWith('s') ? `’` : `’s`);
|
||||||
{
|
const groupedBrews = _.groupBy(props.brews, (brew)=>brew.published ? 'published' : 'private');
|
||||||
title : `${usernameWithS} published brews`,
|
|
||||||
class : 'published',
|
|
||||||
brews : brews.published
|
|
||||||
}
|
|
||||||
];
|
|
||||||
if(this.props.username == global.account?.username){
|
|
||||||
brewCollection.push(
|
|
||||||
{
|
|
||||||
title : `${usernameWithS} unpublished brews`,
|
|
||||||
class : 'unpublished',
|
|
||||||
brews : brews.private
|
|
||||||
}
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
return {
|
const brewCollection = [
|
||||||
brewCollection : brewCollection
|
{
|
||||||
};
|
title : `${usernameWithS} published brews`,
|
||||||
},
|
class : 'published',
|
||||||
errorReported : function(error) {
|
brews : groupedBrews.published || []
|
||||||
this.setState({
|
},
|
||||||
error
|
...(props.username === global.account?.username ? [{
|
||||||
});
|
title : `${usernameWithS} unpublished brews`,
|
||||||
},
|
class : 'unpublished',
|
||||||
|
brews : groupedBrews.private || []
|
||||||
|
}] : [])
|
||||||
|
];
|
||||||
|
|
||||||
navItems : function() {
|
const navItems = (
|
||||||
return <Navbar>
|
<Navbar>
|
||||||
<Nav.section>
|
<Nav.section>
|
||||||
{this.state.error ?
|
{error && (<ErrorNavItem error={error} parent={null}></ErrorNavItem>)}
|
||||||
<ErrorNavItem error={this.state.error} parent={this}></ErrorNavItem> :
|
|
||||||
null
|
|
||||||
}
|
|
||||||
<NewBrew />
|
<NewBrew />
|
||||||
<HelpNavItem />
|
<HelpNavItem />
|
||||||
<VaultNavitem/>
|
<VaultNavitem />
|
||||||
<RecentNavItem />
|
<RecentNavItem />
|
||||||
<Account />
|
<Account />
|
||||||
</Nav.section>
|
</Nav.section>
|
||||||
</Navbar>;
|
</Navbar>
|
||||||
},
|
);
|
||||||
|
|
||||||
render : function(){
|
return (
|
||||||
return <ListPage brewCollection={this.state.brewCollection} navItems={this.navItems()} query={this.props.query} reportError={this.errorReported}></ListPage>;
|
<ListPage brewCollection={brewCollection} navItems={navItems} query={props.query} reportError={(err)=>setError(err)} />
|
||||||
}
|
);
|
||||||
});
|
};
|
||||||
|
|
||||||
module.exports = UserPage;
|
module.exports = UserPage;
|
||||||
|
|||||||
Reference in New Issue
Block a user