From b1bd71f2e23243513436560bbfe9b85b28799fce Mon Sep 17 00:00:00 2001 From: Zack Spear Date: Thu, 11 Jan 2024 18:52:24 -0600 Subject: [PATCH] refactor: updateOs callback button action --- web/components/UpdateOs/Update.vue | 4 +- web/components/UpdateOs/UpdateIneligible.vue | 4 +- web/store/updateOsActions.ts | 41 +++++--------------- 3 files changed, 13 insertions(+), 36 deletions(-) diff --git a/web/components/UpdateOs/Update.vue b/web/components/UpdateOs/Update.vue index b3c685918..d29a03fb7 100644 --- a/web/components/UpdateOs/Update.vue +++ b/web/components/UpdateOs/Update.vue @@ -117,9 +117,9 @@ const disableCallbackButton = computed(() => !acknowledgeBackup.value || flashBa watchEffect(() => { if (available.value) { - updateButton.value = updateOsActionsStore.initUpdateOsCallback(); + updateButton.value = updateOsActionsStore.updateCallbackButton(); } else { - updateButton.value = updateOsActionsStore.initUpdateOsCallback(); + updateButton.value = updateOsActionsStore.updateCallbackButton(); } if (flashBackupBasicStatus.value === 'complete') { acknowledgeBackup.value = true; // auto check the box diff --git a/web/components/UpdateOs/UpdateIneligible.vue b/web/components/UpdateOs/UpdateIneligible.vue index f3aea709d..45c7535e8 100644 --- a/web/components/UpdateOs/UpdateIneligible.vue +++ b/web/components/UpdateOs/UpdateIneligible.vue @@ -47,9 +47,9 @@ const updateButton = ref(); watchEffect(() => { if (availableWithRenewal.value) { - updateButton.value = updateOsActionsStore.initUpdateOsCallback(); + updateButton.value = updateOsActionsStore.updateCallbackButton(); } else { - updateButton.value = updateOsActionsStore.initUpdateOsCallback(); + updateButton.value = updateOsActionsStore.updateCallbackButton(); } }); diff --git a/web/store/updateOsActions.ts b/web/store/updateOsActions.ts index cc5ad1e35..355a654ab 100644 --- a/web/store/updateOsActions.ts +++ b/web/store/updateOsActions.ts @@ -4,9 +4,9 @@ import { defineStore, createPinia, setActivePinia } from 'pinia'; import useInstallPlugin from '~/composables/installPlugin'; import { getOsReleaseBySha256 } from '~/composables/services/keyServer'; -import { ACCOUNT_CALLBACK, WEBGUI_TOOLS_UPDATE } from '~/helpers/urls'; +import { WEBGUI_TOOLS_UPDATE } from '~/helpers/urls'; -import { useCallbackStore } from '~/store/callbackActions'; +import { useAccountStore } from '~/store/account'; // import { useErrorsStore } from '~/store/errors'; import { useServerStore } from '~/store/server'; import { useUpdateOsStore } from '~/store/updateOs'; @@ -37,7 +37,7 @@ export interface Release { } export const useUpdateOsActionsStore = defineStore('updateOsActions', () => { - const callbackStore = useCallbackStore(); + const accountStore = useAccountStore(); // const errorsStore = useErrorsStore(); const serverStore = useServerStore(); // in this instance we don't need to pass a payload because we're already in the store that would be passed to it @@ -49,12 +49,10 @@ export const useUpdateOsActionsStore = defineStore('updateOsActions', () => { const updateAction = ref(); const guid = computed(() => serverStore.guid); - const inIframe = computed(() => serverStore.inIframe); const keyfile = computed(() => serverStore.keyfile); const osVersion = computed(() => serverStore.osVersion); const osVersionBranch = computed(() => serverStore.osVersionBranch); const regUpdatesExpired = computed(() => serverStore.regUpdatesExpired); - const serverAccountPayload = computed(() => serverStore.serverAccountPayload); const updateOsAvailable = computed(() => updateOsStore.available); /** used when coming back from callback, this will be the release to install */ @@ -106,43 +104,23 @@ export const useUpdateOsActionsStore = defineStore('updateOsActions', () => { }); // Actions - const initUpdateOsCallback = (): UserProfileLink => { + + + const updateCallbackButton = (): UserProfileLink => { return { click: () => { - callbackStore.send( - ACCOUNT_CALLBACK.toString(), - [{ - server: { - ...serverAccountPayload.value, - }, - type: 'updateOs', - }], - inIframe.value ? 'newTab' : undefined, - ); + accountStore.updateOs(); }, disabled: rebootType.value !== '', external: true, icon: updateOsAvailable.value ? BellAlertIcon : ArrowPathIcon, name: 'updateOs', - text: updateOsAvailable.value ? 'Unraid OS {0} Update Available' : 'Check for OS Updates', + text: updateOsAvailable.value ? 'Unraid OS {0} Update Available' : 'View Available Updates', textParams: [updateOsAvailable.value ?? ''], title: rebootType.value !== '' ? rebootTypeText.value : '', }; }; - const executeUpdateOsCallback = async (autoRedirectReplace?: boolean) => { - await callbackStore.send( - ACCOUNT_CALLBACK.toString(), - [{ - server: { - ...serverAccountPayload.value, - }, - type: 'updateOs', - }], - inIframe.value ? 'newTab' : (autoRedirectReplace ? 'replace' : undefined), - ); - }; - const setUpdateOsAction = (payload: ExternalUpdateOsAction | undefined) => (updateAction.value = payload); /** * @description When receiving the callback the Account update page we'll use the provided sha256 of the release to get the release from the keyserver @@ -238,8 +216,7 @@ export const useUpdateOsActionsStore = defineStore('updateOsActions', () => { actOnUpdateOsAction, confirmUpdateOs, installOsUpdate, - initUpdateOsCallback, - executeUpdateOsCallback, + updateCallbackButton, rebootServer, setStatus, setUpdateOsAction,