|
@@ -2,20 +2,28 @@ import React from "react";
|
|
|
import { OK } from "../shared/StatusMessage";
|
|
|
import Tile from "../shared/Tile";
|
|
|
import useApi from "../../hooks/useApi";
|
|
|
+import useHealthPolling from "../../hooks/useHealthPolling";
|
|
|
|
|
|
const ms = 1000 * 60 * 20;
|
|
|
-const fetchOptions = { credentials: "include" };
|
|
|
+const fetchOptions = { credentials: "same-origin" };
|
|
|
const apiOptions = { ms, fetchOptions };
|
|
|
const homepage = "https://kirkleon.ddns.net/commafeed/";
|
|
|
const unreadLookup = "https://kirkleon.ddns.net/commafeed/rest/category/entries?id=all&limit=20&offset=0&order=desc&readType=unread";
|
|
|
|
|
|
export default () => {
|
|
|
- const [health, data] = useApi(unreadLookup, apiOptions);
|
|
|
+ const health = useHealthPolling(homepage, { ms });
|
|
|
+ const [apiRes, data] = useApi(unreadLookup, apiOptions);
|
|
|
+
|
|
|
+ const message = health !== OK
|
|
|
+ ? null
|
|
|
+ : apiRes === OK
|
|
|
+ ? `${data.entries.length} item(s) unread`
|
|
|
+ : "Could not retrieve unread"
|
|
|
|
|
|
return <Tile
|
|
|
link={homepage}
|
|
|
title="CommaFeed"
|
|
|
health={health}
|
|
|
- data={health === OK ? `${data.entries.length} item(s) unread` : null}
|
|
|
+ data={message}
|
|
|
/>
|
|
|
}
|