|
8 | 8 | Row, |
9 | 9 | } from '@sveltestrap/sveltestrap'; |
10 | 10 | import { installPlugin, removePlugin } from '$lib/services/plugin-service'; |
11 | | - import { goto } from '$app/navigation'; |
| 11 | + import Swal from 'sweetalert2/dist/sweetalert2.js'; |
| 12 | + import "sweetalert2/src/sweetalert2.scss"; |
12 | 13 |
|
13 | 14 | /** @type {import('$types').PluginDefModel[]} */ |
14 | 15 | export let plugins; |
15 | | - |
16 | | - /** |
| 16 | +
|
| 17 | + /** |
17 | 18 | * @param {string} id |
| 19 | + * @param {string} name |
18 | 20 | * @param {boolean} enable |
19 | | - */ |
20 | | - async function handlePluginStatus(id, enable) { |
21 | | - if (enable) { |
22 | | - await installPlugin(id); |
23 | | - } else { |
24 | | - await removePlugin(id); |
25 | | - } |
26 | | - |
27 | | - // refresh page |
28 | | - const path = window.location.pathname; |
29 | | - goto('').then(() => goto(path)); |
| 21 | + */ |
| 22 | + function handlePluginStatus(id, name, enable) { |
| 23 | + // @ts-ignore |
| 24 | + Swal.fire({ |
| 25 | + title: 'Are you sure?', |
| 26 | + text: `We will ${enable ? 'install' : 'remove'} ${name}.`, |
| 27 | + icon: 'warning', |
| 28 | + showCancelButton: true, |
| 29 | + confirmButtonText: 'Yes', |
| 30 | + cancelButtonText: 'No' |
| 31 | + // @ts-ignore |
| 32 | + }).then((result) => { |
| 33 | + if (result.value) { |
| 34 | + if (enable) { |
| 35 | + installPlugin(id).then(() => { |
| 36 | + refresh(); |
| 37 | + }); |
| 38 | + } else { |
| 39 | + removePlugin(id).then(() => { |
| 40 | + refresh(); |
| 41 | + }) |
| 42 | + } |
| 43 | + } |
| 44 | + }); |
| 45 | + } |
| 46 | +
|
| 47 | + function refresh() { |
| 48 | + window.location.reload(); |
30 | 49 | } |
31 | 50 | </script> |
32 | 51 |
|
|
68 | 87 | <a href="page/setting#{item.settings_name}" class="btn btn-soft-success btn-sm">{$_('Settings')}</a> |
69 | 88 | {/if} |
70 | 89 | {#if !item.is_core} |
71 | | - <button class="btn btn-soft-warning btn-sm" on:click={() => handlePluginStatus(item.id, !item.enabled)}>{item.enabled ? $_("Remove") : $_("Install")}</button> |
| 90 | + <button class="btn btn-soft-warning btn-sm" on:click={() => handlePluginStatus(item.id, item.name, !item.enabled)}>{item.enabled ? $_("Remove") : $_("Install")}</button> |
72 | 91 | {/if} |
73 | 92 | </div> |
74 | 93 | </CardBody> |
|
0 commit comments