|
1 | 1 | <template> |
2 | | - <div class="p-4 flex gap-4"> |
| 2 | + <ServicePlaceholder v-if="loadingOverlay" /> |
| 3 | + <div v-else class="p-4 flex gap-4"> |
3 | 4 | <div class="flex-shrink-0 flex"> |
4 | 5 | <a :href="link" :target="target" class="self-center w-16 h-16 overflow-hidden rounded-2xl border border-fg/10 dark:border-fg/15"> |
5 | | - <slot name="icon"> |
| 6 | + <slot name="icon" :service="data"> |
6 | 7 | <ServiceBaseIcon v-if="icon" v-bind="icon" /> |
7 | 8 | </slot> |
8 | 9 | </a> |
9 | 10 | </div> |
10 | 11 | <div> |
11 | 12 | <h3 class="text-lg mt-1 font-semibold line-clamp-1 flex gap-2 items-center"> |
12 | | - <slot name="title"> |
| 13 | + <slot name="title" :service="data"> |
13 | 14 | <a :href="link" :target="target">{{ title }}</a> |
14 | 15 | </slot> |
15 | | - <slot v-if="props?.status" name="status"> |
| 16 | + <slot v-if="status" name="status" :data="data"> |
16 | 17 | <ServiceBaseStatus :ping="data?.ping" /> |
17 | 18 | </slot> |
18 | 19 | </h3> |
19 | 20 |
|
20 | 21 | <p class="text-sm text-fg-dimmed line-clamp-1"> |
21 | | - <slot name="description"> |
| 22 | + <slot name="description" :service="data"> |
22 | 23 | {{ description }} |
23 | 24 | </slot> |
24 | 25 | </p> |
|
27 | 28 | </template> |
28 | 29 |
|
29 | 30 | <script setup lang="ts"> |
30 | | -import type { BaseService } from '~/types' |
31 | | -import { useServiceData } from '~/composables/services' |
| 31 | +import type { Service, ServiceClient } from '~/types' |
32 | 32 |
|
33 | | -const props = defineProps<BaseService>() |
| 33 | +const props = defineProps<ServiceClient<Service>>() |
34 | 34 |
|
35 | 35 | const { $settings } = useNuxtApp() |
36 | 36 | const target = computed(() => props.target || $settings.behaviour.target) |
37 | 37 |
|
38 | | -// Right now, queries for "base" are only needed for statuses. |
39 | | -// When the situation will change it is necessary to remove/add condition for "immediate" |
40 | | -const { data, pauseUpdate } = useServiceData<BaseService, { ping: { time: number, status: boolean } }>(props, { |
41 | | - immediate: props.status?.enabled || false, |
| 38 | +const immediate = computed(() => props.status?.enabled || !!props.type || false) |
| 39 | +const { data, pauseUpdate } = useServiceData<Service>(props, { |
| 40 | + immediate: immediate.value, |
42 | 41 | }) |
43 | 42 |
|
| 43 | +const loadingOverlay = computed(() => { |
| 44 | + if (props.type && !data.value) { |
| 45 | + return true |
| 46 | + } |
| 47 | +
|
| 48 | + return false |
| 49 | +}) |
| 50 | +
|
| 51 | +defineExpose({ data }) |
| 52 | +
|
44 | 53 | onBeforeUnmount(pauseUpdate) |
45 | 54 | </script> |
0 commit comments