diff --git a/dashboard/src/components/app/Uninstall.vue b/dashboard/src/components/app/Uninstall.vue index 708805260..558ce325f 100644 --- a/dashboard/src/components/app/Uninstall.vue +++ b/dashboard/src/components/app/Uninstall.vue @@ -5,9 +5,9 @@ const i18n = useI18n(); const t = i18n.t; import { ref, onMounted, useTemplateRef } from 'vue'; -import { Button, InputDialog } from '@cloudron/pankow'; +import { Button, InputDialog, Spinner } from '@cloudron/pankow'; import { prettyLongDate } from '@cloudron/pankow/utils'; -import { APP_TYPES } from '../../constants.js'; +import { APP_TYPES, RSTATES } from '../../constants.js'; import AppsModel from '../../models/AppsModel.js'; const appsModel = AppsModel.create(); @@ -55,6 +55,47 @@ async function onArchive() { window.location.href = '/#/apps'; } +const TARGET_RUN_STATE = { + START: Symbol('start'), + STOP: Symbol('stop'), +}; + +function targetRunState() { + // if we have an error, we want to retry the pending state, otherwise toggle the runstate + if (props.app.error) { + if (props.app.error.installationState === ISTATES.PENDING_START) return TARGET_RUN_STATE.START; + else return TARGET_RUN_STATE.STOP; + } else { + if (props.app.runState === RSTATES.STOPPED) return TARGET_RUN_STATE.START; + else return TARGET_RUN_STATE.STOP; + } +} + +const toggleRunStateBusy = ref(false); +async function onStartApp() { + toggleRunStateBusy.value = true; + + const [error] = await appsModel.start(props.app.id); + if (error) { + toggleRunStateBusy.value = false; + return console.error(error); + } + + setTimeout(() => toggleRunStateBusy.value = false, 3000); +} + +async function onStopApp() { + toggleRunStateBusy.value = true; + + const [error] = await appsModel.stop(props.app.id); + if (error) { + toggleRunStateBusy.value = false; + return console.error(error); + } + + setTimeout(() => toggleRunStateBusy.value = false, 3000); +} + onMounted(async () => { let [error, result] = await appsModel.backups(props.app.id); if (error) return console.error(error); @@ -75,6 +116,16 @@ onMounted(async () => {