From 0400188ea7ccedc056e77f187a67a7fc5b5cf4af Mon Sep 17 00:00:00 2001 From: ajnart Date: Wed, 18 May 2022 22:09:13 +0200 Subject: [PATCH] :truck: Move the update indicator to the Footer Co-authored-by: Bjorn L. --- src/components/layout/Footer.tsx | 104 +++++++++++++++++++++++-------- 1 file changed, 77 insertions(+), 27 deletions(-) diff --git a/src/components/layout/Footer.tsx b/src/components/layout/Footer.tsx index e93a4ff7f..b944eb5f5 100644 --- a/src/components/layout/Footer.tsx +++ b/src/components/layout/Footer.tsx @@ -1,4 +1,4 @@ -import React from 'react'; +import React, { useEffect, useState } from 'react'; import { createStyles, Anchor, @@ -6,9 +6,11 @@ import { Group, ActionIcon, Footer as FooterComponent, + Alert, + useMantineTheme, } from '@mantine/core'; -import { BrandGithub } from 'tabler-icons-react'; -import { CURRENT_VERSION } from '../../../data/constants'; +import { AlertCircle, BrandGithub } from 'tabler-icons-react'; +import { CURRENT_VERSION, REPO_URL } from '../../../data/constants'; const useStyles = createStyles((theme) => ({ footer: { @@ -41,6 +43,8 @@ interface FooterCenteredProps { } export function Footer({ links }: FooterCenteredProps) { + const [update, setUpdate] = useState(false); + const theme = useMantineTheme(); const { classes } = useStyles(); const items = links.map((link) => ( @@ -55,42 +59,88 @@ export function Footer({ links }: FooterCenteredProps) { )); + const [latestVersion, setLatestVersion] = useState(CURRENT_VERSION); + const [isOpen, setOpen] = useState(true); + useEffect(() => { + // Fetch Data here when component first mounted + fetch(`https://api.github.com/repos/${REPO_URL}/releases/latest`).then((res) => { + res.json().then((data) => { + setLatestVersion(data.tag_name); + if (data.tag_name !== CURRENT_VERSION) { + setUpdate(true); + } + }); + }); + }, []); + return ( - - - component="a" href="https://github.com/ajnart/homarr" size="lg"> - - + + + setOpen(false)} + icon={} + title={`Updated version: ${latestVersion} is available. Current version: ${CURRENT_VERSION}`} + withCloseButton + radius="lg" + hidden={CURRENT_VERSION === latestVersion || !isOpen} + variant="outline" + styles={{ + root: { + backgroundColor: + theme.colorScheme === 'dark' ? theme.colors.dark[6] : theme.colors.gray[1], + }, + + closeButton: { + marginLeft: '5px', + }, + }} + children={undefined} + /> + + + + component="a" href="https://github.com/ajnart/homarr" size="lg"> + + + + {CURRENT_VERSION} + + - {CURRENT_VERSION} + Made with ❤️ by @ + + ajnart + - - Made with ❤️ by @ - - ajnart - - );