aboutsummaryrefslogtreecommitdiff
path: root/src/hooks/APIClient.ts
diff options
context:
space:
mode:
authoreug-vs <eug-vs@keemail.me>2020-10-09 02:12:36 +0300
committereug-vs <eug-vs@keemail.me>2020-10-09 02:12:36 +0300
commit2f7a4bb3de4ff346a928f6887bc2fb4a5973977d (patch)
tree9ba9d366ab615937a62b8488290a61671f9e613c /src/hooks/APIClient.ts
parenta5d0f3edcd5478c81262524cbfef8273a065df36 (diff)
downloadwhich-ui-2f7a4bb3de4ff346a928f6887bc2fb4a5973977d.tar.gz
feat: show latest release patchnotes on homepage
Diffstat (limited to 'src/hooks/APIClient.ts')
-rw-r--r--src/hooks/APIClient.ts19
1 files changed, 19 insertions, 0 deletions
diff --git a/src/hooks/APIClient.ts b/src/hooks/APIClient.ts
index 68413b0..1d4110c 100644
--- a/src/hooks/APIClient.ts
+++ b/src/hooks/APIClient.ts
@@ -1,5 +1,6 @@
import useSWR, { responseInterface } from 'swr';
import { User, Poll, Feedback } from 'which-types';
+import axios from 'axios';
import { get } from '../requests';
type Response<T> = responseInterface<T, Error>;
@@ -24,3 +25,21 @@ export const useFeed = (): Response<Poll[]> => {
export const useFeedback = (): Response<Feedback[]> => {
return useSWR('/feedback', fetcher);
};
+
+interface Release {
+ url: string;
+ description: string;
+ version: string;
+ name: string;
+}
+
+export const usePatchNotes = (): Response<Release> => {
+ const fetchRelease = () => axios.get('https://api.github.com/repos/which-ecosystem/which/releases/latest')
+ .then(({ data }) => ({
+ name: data.name,
+ url: data.html_url,
+ version: data.tag_name,
+ description: data.body
+ }));
+ return useSWR('/patchnotes', fetchRelease, { revalidateOnFocus: false });
+};