Skip to content

Commit

Permalink
Fixed eslint warnings in index.js
Browse files Browse the repository at this point in the history
  • Loading branch information
c3ho committed Apr 15, 2020
1 parent 24b7abc commit f9a4c87
Showing 1 changed file with 10 additions and 12 deletions.
22 changes: 10 additions & 12 deletions src/frontend/src/pages/index.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React, { useEffect, useState, useRef } from 'react';
import React, { useEffect, useState, useRef, useCallback } from 'react';
import { makeStyles } from '@material-ui/core/styles';
import { CircularProgress, Button, Grid } from '@material-ui/core';
import parse from 'parse-link-header';
Expand Down Expand Up @@ -81,14 +81,14 @@ export default function IndexPage() {
}

getPosts();
}, [telescopeUrl, numPages]);
}, [telescopeUrl, numPages, nextPageLink, posts]);

function getNewPosts() {
setLoading(true);
setNumPages(numPages + 1);
}

async function getPostsCount() {
const getPostsCount = useCallback(async () => {
try {
const res = await fetch(`${telescopeUrl}/posts`, { method: 'HEAD' });
if (!res.ok) {
Expand All @@ -99,17 +99,15 @@ export default function IndexPage() {
console.log(error);
}
return null;
}
}, [telescopeUrl]);

function callback() {
getPostsCount()
.then(setCurrentNumPosts)
.catch((error) => console.log(error));
}
const callback = useCallback(async () => {
setCurrentNumPosts(await getPostsCount());
}, [getPostsCount]);

useEffect(() => {
savedCallback.current = callback;
});
}, [callback]);

// Get the current + initial posts count when page loads
useEffect(() => {
Expand All @@ -124,7 +122,7 @@ export default function IndexPage() {
}
}
setPostsInfo();
}, []);
});

useEffect(() => {
function getCurrentNumPosts() {
Expand All @@ -135,7 +133,7 @@ export default function IndexPage() {
// Polls every 5 minutes
const interval = setInterval(getCurrentNumPosts, 5 * 60 * 1000);
return () => clearInterval(interval);
}, [currentNumPosts]);
}, [callback, currentNumPosts]);

function GenerateLoadButtonContent() {
if (endOfPosts) {
Expand Down

0 comments on commit f9a4c87

Please sign in to comment.