forked from umami-software/umami
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add hook to check version with GitHub API
1 parent
85f791e
commit d79c804
Showing
1 changed file
with
28 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
import { useMemo } from 'react'; | ||
import useFetch from 'hooks/useFetch'; | ||
|
||
export default function useVersion() { | ||
const { data } = useMemo(() => | ||
useFetch('https://api.github.com/repos/mikecao/umami/releases/latest'), | ||
); | ||
|
||
if (!data || !data['tag_name']) return null; | ||
|
||
const latest = data['tag_name'].startsWith('v') ? data['tag_name'].slice(1) : data['tag_name']; | ||
const current = process.env.VERSION; | ||
|
||
if (latest === current) return null; | ||
|
||
const latestArray = latest.split('.'); | ||
const currentArray = current.split('.'); | ||
|
||
for (let i = 0; i < 3; i++) { | ||
if (Number(latestArray[i]) > Number(currentArray[i])) | ||
return { | ||
current: current, | ||
latest: latest, | ||
}; | ||
} | ||
|
||
return null; | ||
} |