|
@@ -1,27 +1,21 @@
|
|
|
-import React, { useState } from "react";
|
|
|
-import useJsonHealthCheck from "../../hooks/useJsonHealthCheck";
|
|
|
-import { UNKNOWN, OK, BAD, FAILED } from "../shared/StatusMessage";
|
|
|
+import React from "react";
|
|
|
+import { OK } from "../shared/StatusMessage";
|
|
|
import Tile from "../shared/Tile";
|
|
|
+import useApi from "../../hooks/useApi";
|
|
|
|
|
|
-const update = 1000 * 60 * 20
|
|
|
+const ms = 1000 * 60 * 20;
|
|
|
+const fetchOptions = { credentials: "include" };
|
|
|
+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 [{ unread, health }, setState] = useState({ unread: null, health: UNKNOWN });
|
|
|
- useJsonHealthCheck(
|
|
|
- unreadLookup,
|
|
|
- ({ entries }) => setState({ unread: entries.length, health: OK }),
|
|
|
- () => setState({ unread: null, health: BAD }),
|
|
|
- () => setState({ unread: null, health: FAILED }),
|
|
|
- update,
|
|
|
- "include",
|
|
|
- );
|
|
|
+ const [health, data] = useApi(unreadLookup, apiOptions);
|
|
|
|
|
|
return <Tile
|
|
|
link={homepage}
|
|
|
title="CommaFeed"
|
|
|
health={health}
|
|
|
- data={unread === null ? null : `${unread} items unread`}
|
|
|
+ data={health === OK ? `${data.entries.length} item(s) unread` : null}
|
|
|
/>
|
|
|
}
|