fix(dashboard): only check status if restart or update has been requested
This commit is contained in:
parent
d802e515e9
commit
0825257a2e
7 changed files with 24 additions and 16 deletions
11
.gitignore
vendored
11
.gitignore
vendored
|
@ -49,14 +49,13 @@ logs
|
||||||
!.env.test
|
!.env.test
|
||||||
github.secrets
|
github.secrets
|
||||||
node_modules/
|
node_modules/
|
||||||
app-data
|
/app-data/
|
||||||
data
|
/data/
|
||||||
data
|
/repos/
|
||||||
repos
|
/apps/
|
||||||
apps
|
|
||||||
traefik/shared
|
traefik/shared
|
||||||
|
|
||||||
# media folder
|
# media folder
|
||||||
media
|
media
|
||||||
|
|
||||||
state
|
/state/
|
||||||
|
|
|
@ -8,12 +8,13 @@ interface IProps {
|
||||||
}
|
}
|
||||||
|
|
||||||
export const StatusProvider: React.FC<IProps> = ({ children }) => {
|
export const StatusProvider: React.FC<IProps> = ({ children }) => {
|
||||||
const { status } = useSystemStore();
|
const { status, setPollStatus } = useSystemStore();
|
||||||
const s = useRef(status);
|
const s = useRef(status);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
// If previous was not running and current is running, we need to refresh the page
|
// If previous was not running and current is running, we need to refresh the page
|
||||||
if (status === 'RUNNING' && s.current !== 'RUNNING') {
|
if (status === 'RUNNING' && s.current !== 'RUNNING') {
|
||||||
|
setPollStatus(false);
|
||||||
router.reload();
|
router.reload();
|
||||||
}
|
}
|
||||||
if (status === 'RUNNING') {
|
if (status === 'RUNNING') {
|
||||||
|
@ -25,7 +26,7 @@ export const StatusProvider: React.FC<IProps> = ({ children }) => {
|
||||||
if (status === 'UPDATING') {
|
if (status === 'UPDATING') {
|
||||||
s.current = 'UPDATING';
|
s.current = 'UPDATING';
|
||||||
}
|
}
|
||||||
}, [status, s]);
|
}, [status, s, setPollStatus]);
|
||||||
|
|
||||||
if (s.current === 'LOADING') {
|
if (s.current === 'LOADING') {
|
||||||
return <StatusScreen title="" subtitle="" />;
|
return <StatusScreen title="" subtitle="" />;
|
||||||
|
|
|
@ -28,7 +28,7 @@ export const InstallForm: React.FC<IProps> = ({ formFields, onSubmit, initalValu
|
||||||
const {
|
const {
|
||||||
register,
|
register,
|
||||||
handleSubmit,
|
handleSubmit,
|
||||||
formState: { errors },
|
formState: { errors, isDirty },
|
||||||
setValue,
|
setValue,
|
||||||
watch,
|
watch,
|
||||||
setError,
|
setError,
|
||||||
|
@ -36,12 +36,12 @@ export const InstallForm: React.FC<IProps> = ({ formFields, onSubmit, initalValu
|
||||||
const watchExposed = watch('exposed', false);
|
const watchExposed = watch('exposed', false);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (initalValues) {
|
if (initalValues && !isDirty) {
|
||||||
Object.entries(initalValues).forEach(([key, value]) => {
|
Object.entries(initalValues).forEach(([key, value]) => {
|
||||||
setValue(key, value);
|
setValue(key, value);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}, [initalValues, setValue]);
|
}, [initalValues, isDirty, setValue]);
|
||||||
|
|
||||||
const renderField = (field: FormField) => (
|
const renderField = (field: FormField) => (
|
||||||
<Input
|
<Input
|
||||||
|
|
|
@ -7,6 +7,7 @@ import { useToastStore } from '../../../../state/toastStore';
|
||||||
import { RestartModal } from '../../components/RestartModal';
|
import { RestartModal } from '../../components/RestartModal';
|
||||||
import { UpdateModal } from '../../components/UpdateModal/UpdateModal';
|
import { UpdateModal } from '../../components/UpdateModal/UpdateModal';
|
||||||
import { trpc } from '../../../../utils/trpc';
|
import { trpc } from '../../../../utils/trpc';
|
||||||
|
import { useSystemStore } from '../../../../state/systemStore';
|
||||||
|
|
||||||
type IProps = { data: SystemRouterOutput['getVersion'] };
|
type IProps = { data: SystemRouterOutput['getVersion'] };
|
||||||
|
|
||||||
|
@ -14,6 +15,7 @@ export const SettingsContainer: React.FC<IProps> = ({ data }) => {
|
||||||
const [loading, setLoading] = React.useState(false);
|
const [loading, setLoading] = React.useState(false);
|
||||||
const { current, latest } = data;
|
const { current, latest } = data;
|
||||||
const { addToast } = useToastStore();
|
const { addToast } = useToastStore();
|
||||||
|
const { setPollStatus } = useSystemStore();
|
||||||
const restartDisclosure = useDisclosure();
|
const restartDisclosure = useDisclosure();
|
||||||
const updateDisclosure = useDisclosure();
|
const updateDisclosure = useDisclosure();
|
||||||
|
|
||||||
|
@ -26,6 +28,7 @@ export const SettingsContainer: React.FC<IProps> = ({ data }) => {
|
||||||
},
|
},
|
||||||
onSuccess: async () => {
|
onSuccess: async () => {
|
||||||
setLoading(false);
|
setLoading(false);
|
||||||
|
setPollStatus(true);
|
||||||
localStorage.removeItem('token');
|
localStorage.removeItem('token');
|
||||||
},
|
},
|
||||||
onError: (error) => {
|
onError: (error) => {
|
||||||
|
@ -41,7 +44,7 @@ export const SettingsContainer: React.FC<IProps> = ({ data }) => {
|
||||||
},
|
},
|
||||||
onSuccess: async () => {
|
onSuccess: async () => {
|
||||||
setLoading(false);
|
setLoading(false);
|
||||||
|
setPollStatus(true);
|
||||||
localStorage.removeItem('token');
|
localStorage.removeItem('token');
|
||||||
},
|
},
|
||||||
onError: (error) => {
|
onError: (error) => {
|
||||||
|
|
|
@ -10,14 +10,18 @@ export type SystemStatus = (typeof SYSTEM_STATUS)[keyof typeof SYSTEM_STATUS];
|
||||||
|
|
||||||
type Store = {
|
type Store = {
|
||||||
status: SystemStatus;
|
status: SystemStatus;
|
||||||
|
pollStatus: boolean;
|
||||||
version: { current: string; latest?: string };
|
version: { current: string; latest?: string };
|
||||||
setStatus: (status: SystemStatus) => void;
|
setStatus: (status: SystemStatus) => void;
|
||||||
setVersion: (version: { current: string; latest?: string }) => void;
|
setVersion: (version: { current: string; latest?: string }) => void;
|
||||||
|
setPollStatus: (pollStatus: boolean) => void;
|
||||||
};
|
};
|
||||||
|
|
||||||
export const useSystemStore = create<Store>((set) => ({
|
export const useSystemStore = create<Store>((set) => ({
|
||||||
status: 'RUNNING',
|
status: 'RUNNING',
|
||||||
version: { current: '0.0.0', latest: '0.0.0' },
|
version: { current: '0.0.0', latest: '0.0.0' },
|
||||||
|
pollStatus: false,
|
||||||
setStatus: (status: SystemStatus) => set((state) => ({ ...state, status })),
|
setStatus: (status: SystemStatus) => set((state) => ({ ...state, status })),
|
||||||
setVersion: (version: { current: string; latest?: string }) => set((state) => ({ ...state, version })),
|
setVersion: (version: { current: string; latest?: string }) => set((state) => ({ ...state, version })),
|
||||||
|
setPollStatus: (pollStatus: boolean) => set((state) => ({ ...state, pollStatus })),
|
||||||
}));
|
}));
|
||||||
|
|
|
@ -11,9 +11,9 @@ import { SystemStatus, useSystemStore } from '../client/state/systemStore';
|
||||||
|
|
||||||
function MyApp({ Component, pageProps }: AppProps) {
|
function MyApp({ Component, pageProps }: AppProps) {
|
||||||
const { setDarkMode } = useUIStore();
|
const { setDarkMode } = useUIStore();
|
||||||
const { setStatus, setVersion } = useSystemStore();
|
const { setStatus, setVersion, pollStatus } = useSystemStore();
|
||||||
|
|
||||||
trpc.system.status.useQuery(undefined, { networkMode: 'online', refetchInterval: 5000, onSuccess: (d) => setStatus((d.status as SystemStatus) || 'RUNNING') });
|
trpc.system.status.useQuery(undefined, { networkMode: 'online', refetchInterval: 2000, onSuccess: (d) => setStatus((d.status as SystemStatus) || 'RUNNING'), enabled: pollStatus });
|
||||||
const version = trpc.system.getVersion.useQuery(undefined, { networkMode: 'online' });
|
const version = trpc.system.getVersion.useQuery(undefined, { networkMode: 'online' });
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
|
|
|
@ -2,6 +2,7 @@ import { type GetServerSidePropsContext } from 'next';
|
||||||
import jwt from 'jsonwebtoken';
|
import jwt from 'jsonwebtoken';
|
||||||
import { getConfig } from '../core/TipiConfig';
|
import { getConfig } from '../core/TipiConfig';
|
||||||
import TipiCache from '../core/TipiCache';
|
import TipiCache from '../core/TipiCache';
|
||||||
|
import { Logger } from '../core/Logger';
|
||||||
|
|
||||||
export const getServerAuthSession = async (ctx: { req: GetServerSidePropsContext['req']; res: GetServerSidePropsContext['res'] }) => {
|
export const getServerAuthSession = async (ctx: { req: GetServerSidePropsContext['req']; res: GetServerSidePropsContext['res'] }) => {
|
||||||
const { req } = ctx;
|
const { req } = ctx;
|
||||||
|
@ -19,7 +20,7 @@ export const getServerAuthSession = async (ctx: { req: GetServerSidePropsContext
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
console.error(err);
|
Logger.info(err);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue