Skip to content

Commit

Permalink
Nothing fancy but should give articles a better chance to load if we …
Browse files Browse the repository at this point in the history
…have dry months.
  • Loading branch information
8BallBomBom committed Jan 2, 2021
1 parent 2d7e596 commit 87edae9
Showing 1 changed file with 23 additions and 8 deletions.
31 changes: 23 additions & 8 deletions src/pages/News.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,9 @@ import moment from 'moment';

import eye from '../assets/eye.mp4';

const artLimit = 64;
const articleLimit = 64;
const attemptLimit = 6;
let attempt = 0;

class News extends Component {
date = new Date();
Expand All @@ -32,6 +34,13 @@ class News extends Component {
found: true
}

adjustDates = () => {
this.date.setMonth( this.date.getMonth() - 1 );
this.dateStr = moment( this.date ).format( 'MM-YYYY' );

this.setState( { loading: false } );
}

loadArticles = async () => {
const { data, length, loading, more } = this.state;
if ( loading || !more ) { return; };
Expand All @@ -49,13 +58,19 @@ class News extends Component {
length: length + response.data.length
} );

this.date.setMonth( this.date.getMonth() - 1 );
this.dateStr = moment( this.date ).format( 'MM-YYYY' );
this.adjustDates();

attempt = 0;
} else {
this.setState( { more: false } );
if ( attempt >= attemptLimit ) {
this.setState( { more: false } );
} else {
attempt = attempt + 1;

this.adjustDates();
this.loadArticles();
};
};

this.setState( { loading: false } );
}

throttleSearching( func, delay ) {
Expand Down Expand Up @@ -221,7 +236,7 @@ class News extends Component {
dataLength={length}
next={this.loadArticles}
hasMore={more}
scrollThreshold={(length > artLimit) ? 0.75 : 0.4}
scrollThreshold={(length > articleLimit) ? 0.6 : 0.4}
loader={this.renderLoading()}
endMessage={
<div className={Style.placeholder}>
Expand All @@ -248,7 +263,7 @@ class News extends Component {
{
this.renderArticle(article)
}
{!((i+1) % (artLimit*6)) &&
{!((i+1) % (articleLimit*6)) &&
<a href="/#donate" className={Style.advert}>
<h3>
Please support us
Expand Down

0 comments on commit 87edae9

Please sign in to comment.