Skip to content

Commit

Permalink
Fix auto-load-more-news
Browse files Browse the repository at this point in the history
The button appears a bit later, so it can't stop listening to changes as soon as it can't find it
  • Loading branch information
fregante committed May 17, 2018
1 parent e7a2689 commit 1fae7b6
Showing 1 changed file with 2 additions and 4 deletions.
6 changes: 2 additions & 4 deletions source/features/auto-load-more-news.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@ import debounce from 'debounce-fn';
import observeEl from '../libs/simplified-element-observer';

let btn;
let newsfeedObserver;

const loadMore = debounce(() => {
btn.click();
btn.textContent = 'loading...';

// If GH hasn't loaded the JS, the click will not load anything.
// We can detect if it worked by looking at the button's state,
Expand Down Expand Up @@ -37,8 +37,6 @@ const findButton = () => {
btn = select('.ajax-pagination-btn');
if (btn) {
inView.observe(btn);
} else if (newsfeedObserver) {
newsfeedObserver.disconnect();
}
};

Expand All @@ -48,6 +46,6 @@ export default () => {
// If GH hasn't loaded the JS,
// the fake click will submit the form without ajax.
form.addEventListener('submit', event => event.preventDefault());
newsfeedObserver = observeEl('#dashboard .news', findButton);
observeEl('#dashboard .news', findButton);
}
};

0 comments on commit 1fae7b6

Please sign in to comment.