| 1 | <template> |
| 2 | <div class="stack-provisioning-list"> |
| 3 | <n-spin :show="loading"> |
| 4 | <div class="my-3 flex min-h-52 flex-col gap-2"> |
| 5 | <template v-if="list.length"> |
| 6 | <StackProvisioningItem v-for="item of list" :key="item.name" :content-pack="item" /> |
| 7 | </template> |
| 8 | <template v-else> |
| 9 | <n-empty v-if="!loading" description="No items found" class="h-48 justify-center" /> |
| 10 | </template> |
| 11 | </div> |
| 12 | </n-spin> |
| 13 | </div> |
| 14 | </template> |
| 15 | |
| 16 | <script setup lang="ts"> |
| 17 | import type { AvailableContentPack } from "@/types/stackProvisioning.d" |
| 18 | import { NEmpty, NSpin, useMessage } from "naive-ui" |
| 19 | import { computed, onBeforeMount, ref } from "vue" |
| 20 | import Api from "@/api" |
| 21 | import StackProvisioningItem from "./StackProvisioningItem.vue" |
| 22 | |
| 23 | const message = useMessage() |
| 24 | const loadingList = ref(false) |
| 25 | const list = ref<AvailableContentPack[]>([]) |
| 26 | const loading = computed(() => loadingList.value) |
| 27 | |
| 28 | function getData() { |
| 29 | loadingList.value = true |
| 30 | |
| 31 | Api.stackProvisioning |
| 32 | .getAvailableContentPacks() |
| 33 | .then(res => { |
| 34 | if (res.data.success) { |
| 35 | list.value = res.data.available_content_packs || [] |
| 36 | } else { |
| 37 | message.warning(res.data?.message || "An error occurred. Please try again later.") |
| 38 | } |
| 39 | }) |
| 40 | .catch(err => { |
| 41 | message.error(err.response?.data?.message || "An error occurred. Please try again later.") |
| 42 | }) |
| 43 | .finally(() => { |
| 44 | loadingList.value = false |
| 45 | }) |
| 46 | } |
| 47 | |
| 48 | onBeforeMount(() => { |
| 49 | getData() |
| 50 | }) |
| 51 | </script> |