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

Merge pull request #1491 from G-Ambatte/addPageCountToUserPage

Display Brew page count on User Page
This commit is contained in:
Trevor Buckner
2021-08-18 10:52:42 -04:00
committed by GitHub
6 changed files with 77 additions and 61 deletions

View File

@@ -196,11 +196,14 @@ const EditPage = createClass({
const transfer = this.state.saveGoogle == _.isNil(this.state.brew.googleId);
const brew = this.state.brew;
brew.pageCount = ((brew.renderer=='legacy' ? brew.text.match(/\\page/g) : brew.text.match(/^\\page/gm)) || []).length + 1;
if(this.state.saveGoogle) {
if(transfer) {
const res = await request
.post('/api/newGoogle/')
.send(this.state.brew)
.send(brew)
.catch((err)=>{
console.log(err.status === 401
? 'Not signed in!'
@@ -211,7 +214,7 @@ const EditPage = createClass({
if(!res) { return; }
console.log('Deleting Local Copy');
await request.delete(`/api/${this.state.brew.editId}`)
await request.delete(`/api/${brew.editId}`)
.send()
.catch((err)=>{
console.log('Error deleting Local Copy');
@@ -221,8 +224,8 @@ const EditPage = createClass({
history.replaceState(null, null, `/edit/${this.savedBrew.googleId}${this.savedBrew.editId}`); //update URL to match doc ID
} else {
const res = await request
.put(`/api/updateGoogle/${this.state.brew.editId}`)
.send(this.state.brew)
.put(`/api/updateGoogle/${brew.editId}`)
.send(brew)
.catch((err)=>{
console.log(err.status === 401
? 'Not signed in!'
@@ -236,14 +239,14 @@ const EditPage = createClass({
} else {
if(transfer) {
const res = await request.post('/api')
.send(this.state.brew)
.send(brew)
.catch((err)=>{
console.log('Error creating Local Copy');
this.setState({ errors: err });
return;
});
await request.get(`/api/removeGoogle/${this.state.brew.googleId}${this.state.brew.editId}`)
await request.get(`/api/removeGoogle/${brew.googleId}${brew.editId}`)
.send()
.catch((err)=>{
console.log('Error Deleting Google Brew');
@@ -253,8 +256,8 @@ const EditPage = createClass({
history.replaceState(null, null, `/edit/${this.savedBrew.editId}`); //update URL to match doc ID
} else {
const res = await request
.put(`/api/update/${this.state.brew.editId}`)
.send(this.state.brew)
.put(`/api/update/${brew.editId}`)
.send(brew)
.catch((err)=>{
console.log('Error Updating Local Brew');
this.setState({ errors: err });

View File

@@ -161,6 +161,8 @@ const NewPage = createClass({
brew.text = brew.text.slice(index + 5);
};
brew.pageCount=((brew.renderer=='legacy' ? brew.text.match(/\\page/g) : brew.text.match(/^\\page/gm)) || []).length + 1;
if(this.state.saveGoogle) {
const res = await request
.post('/api/newGoogle/')

View File

@@ -104,26 +104,28 @@ const BrewItem = createClass({
const dateFormatString = 'YYYY-MM-DD HH:mm:ss';
return <div className='brewItem'>
<h2>{brew.title}</h2>
<p className='description'>{brew.description}</p>
<div className='text'>
<h2>{brew.title}</h2>
<p className='description'>{brew.description}</p>
</div>
<hr />
<div className='info'>
<span title={`Authors:\n${brew.authors.join('\n')}`}>
<i className='fas fa-user'/> {brew.authors.join(', ')}
</span>
<span title={`Last viewed: ${moment(brew.lastViewed).local().format(dateFormatString)}`}>
<i className='fas fa-eye'/> {brew.views}
</span>
<span
title={
`Created: ${brew.createdAt ? moment(brew.createdAt).local().format(dateFormatString) : 'UNKNOWN'}\n` +
`Last updated: ${brew.updatedAt ? moment(brew.updatedAt).local().format(dateFormatString) : 'UNKNOWN'}`
}>
<i className='fas fa-sync-alt' />
{moment(brew.updatedAt).fromNow()}
{brew.pageCount &&
<span title={`Page count: ${brew.pageCount}`}>
<i className='far fa-file' /> {brew.pageCount}
</span>
}
<span>
<i className='fas fa-sync-alt' /> {moment(brew.updatedAt).fromNow()}
</span>
{this.renderGoogleDriveIcon()}
<br />
<span title={`Authors:\n${brew.authors.join('\n')}`}>
<i className='fas fa-user'/> {brew.authors.join(', ')}
</span>
</div>
<div className='links'>

View File

@@ -10,24 +10,28 @@
min-height : 105px;
margin-right : 15px;
margin-bottom : 15px;
padding : 5px 15px 5px 8px;
padding : 5px 15px 2px 8px;
padding-right : 15px;
border : 1px solid #c9ad6a;
border-radius : 5px;
-webkit-column-break-inside : avoid;
page-break-inside : avoid;
break-inside : avoid;
h4{
margin-bottom : 5px;
font-size : 2.2em;
.text {
min-height : 54px;
h4{
margin-bottom : 5px;
font-size : 2.2em;
}
}
.info{
position: absolute;
bottom: 0px;
position: initial;
bottom: 2px;
margin-bottom: 4px;
font-family : ScalySans;
font-size : 1.2em;
&>span{
display : float;
margin-right : 12px;
}
}