fix(dashboard): refresh page when update is successful
This commit is contained in:
parent
2dbddfc084
commit
f71af5b28f
2 changed files with 13 additions and 5 deletions
|
@ -16,6 +16,11 @@ const StatusWrapper: React.FC<IProps> = ({ children }) => {
|
|||
const { data } = useSWR('/api/status', fetcher, { refreshInterval: 1000 });
|
||||
|
||||
useEffect(() => {
|
||||
// If previous was not running and current is running, we need to refresh the page
|
||||
if (data?.status === SystemStatus.RUNNING && s !== SystemStatus.RUNNING) {
|
||||
window.location.reload();
|
||||
}
|
||||
|
||||
if (data?.status === SystemStatus.RUNNING) {
|
||||
setS(SystemStatus.RUNNING);
|
||||
}
|
||||
|
@ -25,7 +30,7 @@ const StatusWrapper: React.FC<IProps> = ({ children }) => {
|
|||
if (data?.status === SystemStatus.UPDATING) {
|
||||
setS(SystemStatus.UPDATING);
|
||||
}
|
||||
}, [data?.status]);
|
||||
}, [data?.status, s]);
|
||||
|
||||
if (s === SystemStatus.RESTARTING) {
|
||||
return (
|
||||
|
|
|
@ -1,10 +1,12 @@
|
|||
import type { NextPage } from 'next';
|
||||
import { AlertDialog, AlertDialogBody, AlertDialogContent, AlertDialogFooter, AlertDialogHeader, AlertDialogOverlay, Button, Text, useDisclosure, useToast } from '@chakra-ui/react';
|
||||
import Layout from '../components/Layout';
|
||||
import { useLogoutMutation, useRestartMutation, useUpdateMutation, useVersionQuery } from '../generated/graphql';
|
||||
import { useRestartMutation, useUpdateMutation, useVersionQuery } from '../generated/graphql';
|
||||
import { useRef, useState } from 'react';
|
||||
import semver from 'semver';
|
||||
|
||||
const wait = (time: number) => new Promise((resolve) => setTimeout(resolve, time));
|
||||
|
||||
const Settings: NextPage = () => {
|
||||
const toast = useToast();
|
||||
const restartDisclosure = useDisclosure();
|
||||
|
@ -15,7 +17,6 @@ const Settings: NextPage = () => {
|
|||
|
||||
const [restart] = useRestartMutation();
|
||||
const [update] = useUpdateMutation();
|
||||
const [logout] = useLogoutMutation({ refetchQueries: ['Me'] });
|
||||
|
||||
const defaultVersion = '0.0.0';
|
||||
const isLatest = semver.gte(data?.version.current || defaultVersion, data?.version.latest || defaultVersion);
|
||||
|
@ -55,7 +56,8 @@ const Settings: NextPage = () => {
|
|||
setLoading(true);
|
||||
try {
|
||||
restart();
|
||||
logout();
|
||||
await wait(1000);
|
||||
localStorage.removeItem('token');
|
||||
} catch (error) {
|
||||
handleError(error);
|
||||
} finally {
|
||||
|
@ -67,7 +69,8 @@ const Settings: NextPage = () => {
|
|||
setLoading(true);
|
||||
try {
|
||||
update();
|
||||
logout();
|
||||
await wait(1000);
|
||||
localStorage.removeItem('token');
|
||||
} catch (error) {
|
||||
handleError(error);
|
||||
} finally {
|
||||
|
|
Loading…
Add table
Reference in a new issue