refactor: restart logic creates new client then gets server details

This commit is contained in:
Zack Spear
2023-07-25 14:40:00 -07:00
parent 31f29229da
commit f409e33adb
4 changed files with 27 additions and 38 deletions

View File

@@ -52,7 +52,7 @@ const status = computed((): StatusOutput | undefined => {
<template>
<li
v-if="status"
class="flex flex-row justify-start items-center gap-8px px-8px"
class="flex flex-row justify-start items-center gap-8px mt-8px px-8px"
>
<component
:is="status.icon"

View File

@@ -82,7 +82,7 @@ const showKeyline = computed(() => showConnectStatus.value && (keyActions.value?
</h2>
</header>
<ul class="list-reset flex flex-col gap-y-4px p-0">
<UpcDropdownConnectStatus v-if="showConnectStatus" class="mt-8px" />
<UpcDropdownConnectStatus v-if="showConnectStatus" />
<UpcDropdownError v-if="showErrors" />
<li v-if="showKeyline" class="my-8px">

View File

@@ -771,6 +771,7 @@ export const useServerStore = defineStore('server', () => {
setServer(mutatedServerStateResult);
}
});
return resultServerState;
};
const phpServerStateRefresh = async () => {

View File

@@ -42,9 +42,12 @@ export const useUnraidApiStore = defineStore('unraidApi', () => {
const unraidApiClient = ref<ApolloClient<any>>();
watch(unraidApiClient, (newVal, oldVal) => {
console.debug('[watch:unraidApiStore.unraidApiClient]', { newVal, oldVal });
if (newVal && !oldVal) { // first time
unraidApiStatus.value = 'online';
serverStore.fetchServerFromApi();
if (newVal) {
const apiResponse = serverStore.fetchServerFromApi();
if (apiResponse) {
// we have a response, so we're online
unraidApiStatus.value = 'online';
}
}
});
@@ -54,6 +57,19 @@ export const useUnraidApiStore = defineStore('unraidApi', () => {
console.debug('[watch:unraidApiStore.unraidApiStatus]', { newVal, oldVal });
});
const unraidApiRestartAction = computed((): UserProfileLink | undefined => {
const { connectPluginInstalled, stateDataError } = serverStore;
if (unraidApiStatus.value !== 'offline' || !connectPluginInstalled || stateDataError) {
return undefined;
}
return {
click: () => restartUnraidApiClient(),
emphasize: true,
icon: ArrowPathIcon,
text: 'Restart unraid-api',
};
});
/**
* Automatically called when an apiKey is set in the serverStore
*/
@@ -147,35 +163,6 @@ export const useUnraidApiStore = defineStore('unraidApi', () => {
console.debug('[useUnraidApiStore.closeUnraidApiClient] DONE');
};
// const clientErrors = ref<any>();
const unraidApiRestartAction = computed((): UserProfileLink | undefined => {
const { connectPluginInstalled, stateDataError } = serverStore;
if (unraidApiStatus.value !== 'offline' || !connectPluginInstalled || stateDataError) {
return undefined;
}
return {
click: () => restartUnraidApiClient(),
emphasize: true,
icon: ArrowPathIcon,
name: 'Restart unraid-api',
text: 'Restart unraid-api',
title: 'Restart unraid-api',
};
});
// /**
// * @name detectOfflineTimer
// * @description if after 30secs the api isn't started we want to possibly enable apiEnableRestartButton
// */
// const detectOfflineTimer = () => {
// console.debug('[detectOfflineTimer]');
// setTimeout(() => {
// if (!unraidApiClient.value && serverStore.registered) {
// // offlineTimer.value = true;
// sessionStorage.setItem('offlineTimer', Date.now());
// }
// }, 30000);
// };
const restartUnraidApiClient = async () => {
unraidApiStatus.value = 'restarting';
const response = await WebguiUnraidApiCommand({
@@ -183,10 +170,11 @@ export const useUnraidApiStore = defineStore('unraidApi', () => {
command: 'start',
});
console.debug('[restartUnraidApiClient]', response);
// reset so the detectOfflineTimer can be used again without a page refresh
// offlineTimer.value = false;
// this.restartTriggered = true;
// sessionStorage.removeItem('offlineTimer');
return setTimeout(() => {
if (unraidApiClient.value) {
createApolloClient();
}
}, 5000);
};
return {