mirror of
https://github.com/naturalcrit/homebrewery.git
synced 2026-01-06 01:22:44 +00:00
initial commit
This commit is contained in:
@@ -1,6 +1,6 @@
|
|||||||
const React = require('react');
|
const React = require('react');
|
||||||
const createClass = require('create-react-class');
|
const { useState, useEffect } = require('react');
|
||||||
const _ = require('lodash');
|
const _ = require('lodash');
|
||||||
|
|
||||||
const ListPage = require('../basePages/listPage/listPage.jsx');
|
const ListPage = require('../basePages/listPage/listPage.jsx');
|
||||||
|
|
||||||
@@ -14,69 +14,50 @@ 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',
|
const { username = '', brews = [], query = '', error = null } = props;
|
||||||
getDefaultProps : function() {
|
const usernameWithS = username + (username.endsWith('s') ? `’` : `’s`);
|
||||||
return {
|
|
||||||
username : '',
|
|
||||||
brews : [],
|
|
||||||
query : '',
|
|
||||||
error : null
|
|
||||||
};
|
|
||||||
},
|
|
||||||
getInitialState : function() {
|
|
||||||
const usernameWithS = this.props.username + (this.props.username.endsWith('s') ? `’` : `’s`);
|
|
||||||
|
|
||||||
const brews = _.groupBy(this.props.brews, (brew)=>{
|
const groupedBrews = _.groupBy(brews, (brew) => {
|
||||||
return (brew.published ? 'published' : 'private');
|
return brew.published ? 'published' : 'private';
|
||||||
});
|
});
|
||||||
|
|
||||||
const brewCollection = [
|
const brewCollection = [
|
||||||
{
|
{
|
||||||
title : `${usernameWithS} published brews`,
|
title: `${usernameWithS} published brews`,
|
||||||
class : 'published',
|
class: 'published',
|
||||||
brews : brews.published
|
brews: groupedBrews.published || []
|
||||||
}
|
},
|
||||||
];
|
...(username === global.account?.username ? [{
|
||||||
if(this.props.username == global.account?.username){
|
title: `${usernameWithS} unpublished brews`,
|
||||||
brewCollection.push(
|
class: 'unpublished',
|
||||||
{
|
brews: groupedBrews.private || []
|
||||||
title : `${usernameWithS} unpublished brews`,
|
}] : [])
|
||||||
class : 'unpublished',
|
];
|
||||||
brews : brews.private
|
|
||||||
}
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
return {
|
const [currentError, setCurrentError] = useState(error);
|
||||||
brewCollection : brewCollection
|
|
||||||
};
|
|
||||||
},
|
|
||||||
errorReported : function(error) {
|
|
||||||
this.setState({
|
|
||||||
error
|
|
||||||
});
|
|
||||||
},
|
|
||||||
|
|
||||||
navItems : function() {
|
const errorReported = (error) => {
|
||||||
return <Navbar>
|
setCurrentError(error);
|
||||||
<Nav.section>
|
};
|
||||||
{this.state.error ?
|
|
||||||
<ErrorNavItem error={this.state.error} parent={this}></ErrorNavItem> :
|
|
||||||
null
|
|
||||||
}
|
|
||||||
<NewBrew />
|
|
||||||
<HelpNavItem />
|
|
||||||
<VaultNavitem/>
|
|
||||||
<RecentNavItem />
|
|
||||||
<Account />
|
|
||||||
</Nav.section>
|
|
||||||
</Navbar>;
|
|
||||||
},
|
|
||||||
|
|
||||||
render : function(){
|
const navItems = () => (
|
||||||
return <ListPage brewCollection={this.state.brewCollection} navItems={this.navItems()} query={this.props.query} reportError={this.errorReported}></ListPage>;
|
<Navbar>
|
||||||
}
|
<Nav.section>
|
||||||
});
|
{currentError && (<ErrorNavItem error={currentError} parent={null}></ErrorNavItem>)}
|
||||||
|
<NewBrew />
|
||||||
|
<HelpNavItem />
|
||||||
|
<VaultNavitem />
|
||||||
|
<RecentNavItem />
|
||||||
|
<Account />
|
||||||
|
</Nav.section>
|
||||||
|
</Navbar>
|
||||||
|
);
|
||||||
|
|
||||||
|
return (
|
||||||
|
<ListPage brewCollection={brewCollection} navItems={navItems()} query={query} reportError={errorReported}
|
||||||
|
/>
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
module.exports = UserPage;
|
module.exports = UserPage;
|
||||||
|
|||||||
Reference in New Issue
Block a user