mirror of
https://github.com/naturalcrit/homebrewery.git
synced 2026-01-03 01:52:42 +00:00
Merge pull request #1799 from G-Ambatte/createBasePages
Create Base Page structure - ListPage
This commit is contained in:
@@ -6,7 +6,7 @@ const cx = require('classnames');
|
|||||||
const moment = require('moment');
|
const moment = require('moment');
|
||||||
const request = require('superagent');
|
const request = require('superagent');
|
||||||
|
|
||||||
const googleDriveIcon = require('../../../googleDrive.png');
|
const googleDriveIcon = require('../../../../googleDrive.png');
|
||||||
const dedent = require('dedent-tabs').default;
|
const dedent = require('dedent-tabs').default;
|
||||||
|
|
||||||
const BrewItem = createClass({
|
const BrewItem = createClass({
|
||||||
160
client/homebrew/pages/basePages/listPage/listPage.jsx
Normal file
160
client/homebrew/pages/basePages/listPage/listPage.jsx
Normal file
@@ -0,0 +1,160 @@
|
|||||||
|
require('./listPage.less');
|
||||||
|
const React = require('react');
|
||||||
|
const createClass = require('create-react-class');
|
||||||
|
const _ = require('lodash');
|
||||||
|
const moment = require('moment');
|
||||||
|
|
||||||
|
const BrewItem = require('./brewItem/brewItem.jsx');
|
||||||
|
|
||||||
|
const ListPage = createClass({
|
||||||
|
displayName : 'ListPage',
|
||||||
|
getDefaultProps : function() {
|
||||||
|
return {
|
||||||
|
brewCollection : [
|
||||||
|
{
|
||||||
|
title : '',
|
||||||
|
class : '',
|
||||||
|
brews : []
|
||||||
|
}
|
||||||
|
],
|
||||||
|
navItems : <></>
|
||||||
|
};
|
||||||
|
},
|
||||||
|
getInitialState : function() {
|
||||||
|
return {
|
||||||
|
sortType : 'alpha',
|
||||||
|
sortDir : 'asc',
|
||||||
|
filterString : ''
|
||||||
|
};
|
||||||
|
},
|
||||||
|
|
||||||
|
renderBrews : function(brews){
|
||||||
|
if(!brews || !brews.length) return <div className='noBrews'>No Brews.</div>;
|
||||||
|
|
||||||
|
return _.map(brews, (brew, idx)=>{
|
||||||
|
return <BrewItem brew={brew} key={idx}/>;
|
||||||
|
});
|
||||||
|
},
|
||||||
|
|
||||||
|
sortBrewOrder : function(brew){
|
||||||
|
if(!brew.title){brew.title = 'No Title';}
|
||||||
|
const mapping = {
|
||||||
|
'alpha' : _.deburr(brew.title.toLowerCase()),
|
||||||
|
'created' : moment(brew.createdAt).format(),
|
||||||
|
'updated' : moment(brew.updatedAt).format(),
|
||||||
|
'views' : brew.views,
|
||||||
|
'latest' : moment(brew.lastViewed).format()
|
||||||
|
};
|
||||||
|
return mapping[this.state.sortType];
|
||||||
|
},
|
||||||
|
|
||||||
|
handleSortOptionChange : function(event){
|
||||||
|
this.setState({
|
||||||
|
sortType : event.target.value
|
||||||
|
});
|
||||||
|
},
|
||||||
|
|
||||||
|
handleSortDirChange : function(event){
|
||||||
|
this.setState({
|
||||||
|
sortDir : `${(this.state.sortDir == 'asc' ? 'desc' : 'asc')}`
|
||||||
|
});
|
||||||
|
},
|
||||||
|
|
||||||
|
renderSortOption : function(sortTitle, sortValue){
|
||||||
|
return <td>
|
||||||
|
<button
|
||||||
|
value={`${sortValue}`}
|
||||||
|
onClick={this.handleSortOptionChange}
|
||||||
|
className={`${(this.state.sortType == sortValue ? 'active' : '')}`}
|
||||||
|
>
|
||||||
|
{`${sortTitle}`}
|
||||||
|
</button>
|
||||||
|
</td>;
|
||||||
|
},
|
||||||
|
|
||||||
|
handleFilterTextChange : function(e){
|
||||||
|
this.setState({
|
||||||
|
filterString : e.target.value
|
||||||
|
});
|
||||||
|
return;
|
||||||
|
},
|
||||||
|
|
||||||
|
renderFilterOption : function(){
|
||||||
|
return <td>
|
||||||
|
<label>
|
||||||
|
<i className='fas fa-search'></i>
|
||||||
|
<input
|
||||||
|
type='search'
|
||||||
|
placeholder='search title/description'
|
||||||
|
onChange={this.handleFilterTextChange}
|
||||||
|
/>
|
||||||
|
</label>
|
||||||
|
</td>;
|
||||||
|
},
|
||||||
|
|
||||||
|
renderSortOptions : function(){
|
||||||
|
return <div className='sort-container'>
|
||||||
|
<table>
|
||||||
|
<tbody>
|
||||||
|
<tr>
|
||||||
|
<td>
|
||||||
|
<h6>Sort by :</h6>
|
||||||
|
</td>
|
||||||
|
{this.renderSortOption('Title', 'alpha')}
|
||||||
|
{this.renderSortOption('Created Date', 'created')}
|
||||||
|
{this.renderSortOption('Updated Date', 'updated')}
|
||||||
|
{this.renderSortOption('Views', 'views')}
|
||||||
|
{/* {this.renderSortOption('Latest', 'latest')} */}
|
||||||
|
<td>
|
||||||
|
<h6>Direction :</h6>
|
||||||
|
</td>
|
||||||
|
<td>
|
||||||
|
<button
|
||||||
|
onClick={this.handleSortDirChange}
|
||||||
|
className='sortDir'
|
||||||
|
>
|
||||||
|
{`${(this.state.sortDir == 'asc' ? '\u25B2 ASC' : '\u25BC DESC')}`}
|
||||||
|
</button>
|
||||||
|
</td>
|
||||||
|
{this.renderFilterOption()}
|
||||||
|
</tr>
|
||||||
|
</tbody>
|
||||||
|
</table>
|
||||||
|
</div>;
|
||||||
|
},
|
||||||
|
|
||||||
|
getSortedBrews : function(brews){
|
||||||
|
const testString = _.deburr(this.state.filterString).toLowerCase();
|
||||||
|
brews = _.filter(brews, (brew)=>{
|
||||||
|
return (_.deburr(brew.title).toLowerCase().includes(testString)) ||
|
||||||
|
(_.deburr(brew.description).toLowerCase().includes(testString));
|
||||||
|
});
|
||||||
|
|
||||||
|
return _.orderBy(brews, (brew)=>{ return this.sortBrewOrder(brew); }, this.state.sortDir);
|
||||||
|
},
|
||||||
|
|
||||||
|
renderBrewCollection : function(brewCollection){
|
||||||
|
return _.map(brewCollection, (brewGroup, idx)=>{
|
||||||
|
return <div key={idx} className={`brewCollection ${brewGroup.class ?? ''}`}>
|
||||||
|
<h1>{brewGroup.title || 'No Title'}</h1>
|
||||||
|
{this.renderBrews(this.getSortedBrews(brewGroup.brews))}
|
||||||
|
</div>;
|
||||||
|
});
|
||||||
|
},
|
||||||
|
|
||||||
|
render : function(){
|
||||||
|
return <div className='listPage sitePage'>
|
||||||
|
<link href='/themes/5ePhbLegacy.style.css' rel='stylesheet'/>
|
||||||
|
{this.props.navItems}
|
||||||
|
|
||||||
|
<div className='content V3'>
|
||||||
|
<div className='phb'>
|
||||||
|
{this.renderSortOptions()}
|
||||||
|
{this.renderBrewCollection(this.props.brewCollection)}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
module.exports = ListPage;
|
||||||
@@ -11,7 +11,7 @@
|
|||||||
-webkit-column-gap : auto;
|
-webkit-column-gap : auto;
|
||||||
-moz-column-gap : auto;
|
-moz-column-gap : auto;
|
||||||
}
|
}
|
||||||
.userPage{
|
.listPage{
|
||||||
.content{
|
.content{
|
||||||
overflow-y : scroll;
|
overflow-y : scroll;
|
||||||
.phb{
|
.phb{
|
||||||
@@ -1,10 +1,9 @@
|
|||||||
require('./userPage.less');
|
|
||||||
const React = require('react');
|
const React = require('react');
|
||||||
const createClass = require('create-react-class');
|
const createClass = require('create-react-class');
|
||||||
const _ = require('lodash');
|
const _ = require('lodash');
|
||||||
const cx = require('classnames');
|
const cx = require('classnames');
|
||||||
|
|
||||||
const moment = require('moment');
|
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');
|
||||||
@@ -12,17 +11,8 @@ 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');
|
||||||
const BrewItem = require('./brewItem/brewItem.jsx');
|
|
||||||
const HelpNavItem = require('../../navbar/help.navitem.jsx');
|
const HelpNavItem = require('../../navbar/help.navitem.jsx');
|
||||||
|
|
||||||
// const brew = {
|
|
||||||
// title : 'SUPER Long title woah now',
|
|
||||||
// authors : []
|
|
||||||
// };
|
|
||||||
|
|
||||||
//const BREWS = _.times(25, ()=>{ return brew;});
|
|
||||||
|
|
||||||
|
|
||||||
const UserPage = createClass({
|
const UserPage = createClass({
|
||||||
displayName : 'UserPage',
|
displayName : 'UserPage',
|
||||||
getDefaultProps : function() {
|
getDefaultProps : function() {
|
||||||
@@ -32,160 +22,47 @@ const UserPage = createClass({
|
|||||||
};
|
};
|
||||||
},
|
},
|
||||||
getInitialState : function() {
|
getInitialState : function() {
|
||||||
return {
|
const usernameWithS = this.props.username + (this.props.username.endsWith('s') ? `'` : `'s`);
|
||||||
sortType : 'alpha',
|
|
||||||
sortDir : 'asc',
|
|
||||||
filterString : ''
|
|
||||||
};
|
|
||||||
},
|
|
||||||
getUsernameWithS : function() {
|
|
||||||
if(this.props.username.endsWith('s'))
|
|
||||||
return `${this.props.username}'`;
|
|
||||||
return `${this.props.username}'s`;
|
|
||||||
},
|
|
||||||
|
|
||||||
renderBrews : function(brews){
|
const brews = _.groupBy(this.props.brews, (brew)=>{
|
||||||
if(!brews || !brews.length) return <div className='noBrews'>No Brews.</div>;
|
|
||||||
|
|
||||||
const sortedBrews = this.sortBrews(brews);
|
|
||||||
|
|
||||||
return _.map(sortedBrews, (brew, idx)=>{
|
|
||||||
return <BrewItem brew={brew} key={idx}/>;
|
|
||||||
});
|
|
||||||
},
|
|
||||||
|
|
||||||
sortBrewOrder : function(brew){
|
|
||||||
if(!brew.title){brew.title = 'No Title';}
|
|
||||||
const mapping = {
|
|
||||||
'alpha' : _.deburr(brew.title.toLowerCase()),
|
|
||||||
'created' : moment(brew.createdAt).format(),
|
|
||||||
'updated' : moment(brew.updatedAt).format(),
|
|
||||||
'views' : brew.views,
|
|
||||||
'latest' : moment(brew.lastViewed).format()
|
|
||||||
};
|
|
||||||
return mapping[this.state.sortType];
|
|
||||||
},
|
|
||||||
|
|
||||||
sortBrews : function(brews){
|
|
||||||
return _.orderBy(brews, (brew)=>{ return this.sortBrewOrder(brew); }, this.state.sortDir);
|
|
||||||
},
|
|
||||||
|
|
||||||
handleSortOptionChange : function(event){
|
|
||||||
this.setState({
|
|
||||||
sortType : event.target.value
|
|
||||||
});
|
|
||||||
},
|
|
||||||
|
|
||||||
handleSortDirChange : function(event){
|
|
||||||
this.setState({
|
|
||||||
sortDir : `${(this.state.sortDir == 'asc' ? 'desc' : 'asc')}`
|
|
||||||
});
|
|
||||||
},
|
|
||||||
|
|
||||||
renderSortOption : function(sortTitle, sortValue){
|
|
||||||
return <td>
|
|
||||||
<button
|
|
||||||
value={`${sortValue}`}
|
|
||||||
onClick={this.handleSortOptionChange}
|
|
||||||
className={`sortOption ${(this.state.sortType == sortValue ? 'active' : '')}`}
|
|
||||||
>
|
|
||||||
{`${sortTitle}`}
|
|
||||||
</button>
|
|
||||||
</td>;
|
|
||||||
},
|
|
||||||
|
|
||||||
handleFilterTextChange : function(e){
|
|
||||||
this.setState({
|
|
||||||
filterString : e.target.value
|
|
||||||
});
|
|
||||||
return;
|
|
||||||
},
|
|
||||||
|
|
||||||
renderFilterOption : function(){
|
|
||||||
return <td>
|
|
||||||
<label className='filterOption'>
|
|
||||||
<i className='fas fa-search'></i>
|
|
||||||
<input
|
|
||||||
type='search'
|
|
||||||
placeholder='search title/description'
|
|
||||||
onChange={this.handleFilterTextChange}
|
|
||||||
/>
|
|
||||||
</label>
|
|
||||||
</td>;
|
|
||||||
},
|
|
||||||
|
|
||||||
renderSortOptions : function(){
|
|
||||||
return <div className='sort-container'>
|
|
||||||
<table>
|
|
||||||
<tbody>
|
|
||||||
<tr>
|
|
||||||
<td>
|
|
||||||
<h6>Sort by :</h6>
|
|
||||||
</td>
|
|
||||||
{this.renderSortOption('Title', 'alpha')}
|
|
||||||
{this.renderSortOption('Created Date', 'created')}
|
|
||||||
{this.renderSortOption('Updated Date', 'updated')}
|
|
||||||
{this.renderSortOption('Views', 'views')}
|
|
||||||
{/* {this.renderSortOption('Latest', 'latest')} */}
|
|
||||||
<td>
|
|
||||||
<h6>Direction :</h6>
|
|
||||||
</td>
|
|
||||||
<td>
|
|
||||||
<button
|
|
||||||
onClick={this.handleSortDirChange}
|
|
||||||
className='sortDir'
|
|
||||||
>
|
|
||||||
{`${(this.state.sortDir == 'asc' ? '\u25B2 ASC' : '\u25BC DESC')}`}
|
|
||||||
</button>
|
|
||||||
</td>
|
|
||||||
{this.renderFilterOption()}
|
|
||||||
</tr>
|
|
||||||
</tbody>
|
|
||||||
</table>
|
|
||||||
</div>;
|
|
||||||
},
|
|
||||||
|
|
||||||
getSortedBrews : function(){
|
|
||||||
const testString = _.deburr(this.state.filterString).toLowerCase();
|
|
||||||
const brewCollection = this.state.filterString ? _.filter(this.props.brews, (brew)=>{
|
|
||||||
return (_.deburr(brew.title).toLowerCase().includes(testString)) ||
|
|
||||||
(_.deburr(brew.description).toLowerCase().includes(testString));
|
|
||||||
}) : this.props.brews;
|
|
||||||
return _.groupBy(brewCollection, (brew)=>{
|
|
||||||
return (brew.published ? 'published' : 'private');
|
return (brew.published ? 'published' : 'private');
|
||||||
});
|
});
|
||||||
|
|
||||||
|
const brewCollection = [
|
||||||
|
{
|
||||||
|
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 {
|
||||||
|
brewCollection : brewCollection
|
||||||
|
};
|
||||||
|
},
|
||||||
|
|
||||||
|
navItems : function() {
|
||||||
|
return <Navbar>
|
||||||
|
<Nav.section>
|
||||||
|
<NewBrew />
|
||||||
|
<HelpNavItem />
|
||||||
|
<RecentNavItem />
|
||||||
|
<Account />
|
||||||
|
</Nav.section>
|
||||||
|
</Navbar>;
|
||||||
},
|
},
|
||||||
|
|
||||||
render : function(){
|
render : function(){
|
||||||
const brews = this.getSortedBrews();
|
return <ListPage brewCollection={this.state.brewCollection} navItems={this.navItems()}></ListPage>;
|
||||||
|
|
||||||
return <div className='userPage sitePage'>
|
|
||||||
<link href='/themes/5ePhbLegacy.style.css' rel='stylesheet'/>
|
|
||||||
<Navbar>
|
|
||||||
<Nav.section>
|
|
||||||
<NewBrew />
|
|
||||||
<HelpNavItem />
|
|
||||||
<RecentNavItem />
|
|
||||||
<Account />
|
|
||||||
</Nav.section>
|
|
||||||
</Navbar>
|
|
||||||
|
|
||||||
<div className='content V3'>
|
|
||||||
<div className='phb'>
|
|
||||||
{this.renderSortOptions()}
|
|
||||||
<div className='published'>
|
|
||||||
<h1>{this.getUsernameWithS()} published brews</h1>
|
|
||||||
{this.renderBrews(brews.published)}
|
|
||||||
</div>
|
|
||||||
{this.props.username == global.account?.username &&
|
|
||||||
<div className='unpublished'>
|
|
||||||
<h1>{this.getUsernameWithS()} unpublished brews</h1>
|
|
||||||
{this.renderBrews(brews.private)}
|
|
||||||
</div>
|
|
||||||
}
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</div>;
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user