Skip to content

Commit

Permalink
Add App Version Update Button on Home page
Browse files Browse the repository at this point in the history
  • Loading branch information
Florian Jud committed May 17, 2024
1 parent a671af3 commit 7dac10b
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 6 deletions.
42 changes: 42 additions & 0 deletions src/components/home/AppVersion.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
import AutorenewIcon from '@mui/icons-material/Autorenew';
import { IconButton, Stack, Typography } from '@mui/material';
import packageJson from '../../../package.json';
import useNotification from '../../hooks/useNotification';
const AppVersion = () => {
const { notifyContext } = useNotification();
const APPLICATION_VERSION = packageJson.version;

/*
Update service worker on new version
*/
const updateServiceWorker = () => {
if ('serviceWorker' in navigator) {
navigator.serviceWorker.ready
.then((registration) => {
registration.unregister().then(() => {
window.location.reload();
notifyContext.addNotification('Deine App wurde aktualisiert', 'success');
});
})
.catch((error) => {
notifyContext.addNotification('Ops da hat was nicht geklappt!', 'error');
console.error('Service Worker Error: ', error);
});
} else {
notifyContext.addNotification('Es wurde kein Update gefunden', 'info');
}
};

return (
<Stack direction="row" justifyContent="space-between" alignItems="center" gap={0}>
<Typography variant="caption" color="text.disabled">
Du nutzt die v{APPLICATION_VERSION}, auf Updates prüfen?
</Typography>
<IconButton aria-label="delete" size="small" onClick={updateServiceWorker}>
<AutorenewIcon fontSize="inherit" />
</IconButton>
</Stack>
);
};

export default AppVersion;
9 changes: 3 additions & 6 deletions src/components/home/UserHomePage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,13 @@ import { Stack, Typography } from '@mui/material';
import { BarChart, Gauge, LineChart } from '@mui/x-charts';
import { Dayjs } from 'dayjs';
import { useEffect, useState } from 'react';
import packageJson from '../../../package.json';

import { useAppSelector } from '../../store/hooks';
import { ReactComponent as HomeSvg } from '../../svg/home.svg';
import AbsenceUtils from '../../utils/AbsenceUtils';
import DayjsUtils from '../../utils/DayjsUtils';
import TimeUtils from '../../utils/TimeUtils';
import AppVersion from './AppVersion';
import HomeCard from './HomeCard';

const UserHomePage = () => {
Expand All @@ -34,8 +35,6 @@ const UserHomePage = () => {
const firstDayOfMonth = DayjsUtils.firstDayOfCurrentMonth();
const startOfCurrentYear = DayjsUtils.startOfCurrentYear();

const APPLICATION_VERSION = packageJson.version;

const evaluateTimes = useAppSelector((state) => state.times.evaluateTimes);

const dataset = evaluateTimes.map((item) => ({
Expand Down Expand Up @@ -190,9 +189,7 @@ const UserHomePage = () => {
</HomeCard>
)}

<Typography variant="caption" color="text.disabled" align="center">
v{APPLICATION_VERSION}
</Typography>
<AppVersion />
</Stack>
</Stack>
);
Expand Down

0 comments on commit 7dac10b

Please sign in to comment.