From 2f7a4bb3de4ff346a928f6887bc2fb4a5973977d Mon Sep 17 00:00:00 2001 From: eug-vs Date: Fri, 9 Oct 2020 02:12:36 +0300 Subject: feat: show latest release patchnotes on homepage --- src/hooks/APIClient.ts | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) (limited to 'src/hooks/APIClient.ts') 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 = responseInterface; @@ -24,3 +25,21 @@ export const useFeed = (): Response => { export const useFeedback = (): Response => { return useSWR('/feedback', fetcher); }; + +interface Release { + url: string; + description: string; + version: string; + name: string; +} + +export const usePatchNotes = (): Response => { + 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 }); +}; -- cgit v1.2.3