2023-09-28 13:36:18 +00:00
|
|
|
<script lang="ts" setup>
|
|
|
|
import { useUserStore } from "@/stores/user";
|
|
|
|
import { relativeTimeTo } from "@/utils/date";
|
2024-06-26 10:42:50 +00:00
|
|
|
import type { Notification } from "@halo-dev/api-client";
|
|
|
|
import { ucApiClient } from "@halo-dev/api-client";
|
2023-09-28 13:36:18 +00:00
|
|
|
import {
|
|
|
|
VButton,
|
|
|
|
VCard,
|
|
|
|
VEmpty,
|
|
|
|
VEntity,
|
|
|
|
VEntityField,
|
|
|
|
VLoading,
|
|
|
|
} from "@halo-dev/components";
|
|
|
|
import { useQuery } from "@tanstack/vue-query";
|
|
|
|
import { OverlayScrollbarsComponent } from "overlayscrollbars-vue";
|
|
|
|
|
|
|
|
const { currentUser } = useUserStore();
|
|
|
|
|
|
|
|
const {
|
|
|
|
data: notifications,
|
|
|
|
isLoading,
|
|
|
|
refetch,
|
|
|
|
isFetching,
|
|
|
|
} = useQuery({
|
|
|
|
queryKey: ["user-notifications"],
|
|
|
|
queryFn: async () => {
|
2024-06-25 04:31:44 +00:00
|
|
|
const { data } =
|
|
|
|
await ucApiClient.notification.notification.listUserNotifications({
|
|
|
|
username: currentUser?.metadata.name as string,
|
|
|
|
page: 1,
|
|
|
|
size: 20,
|
|
|
|
fieldSelector: ["spec.unread=true"],
|
|
|
|
});
|
2023-09-28 13:36:18 +00:00
|
|
|
|
|
|
|
return data.items;
|
|
|
|
},
|
|
|
|
});
|
2023-11-13 08:56:08 +00:00
|
|
|
|
|
|
|
function handleRouteToNotification(notification: Notification) {
|
|
|
|
window.location.href = `/uc/notifications?name=${notification.metadata.name}`;
|
|
|
|
}
|
2023-09-28 13:36:18 +00:00
|
|
|
</script>
|
|
|
|
|
|
|
|
<template>
|
|
|
|
<VCard
|
|
|
|
:body-class="['h-full', '@container', '!p-0', '!overflow-auto']"
|
|
|
|
class="h-full"
|
2023-11-30 10:56:10 +00:00
|
|
|
:title="$t('core.dashboard.widgets.presets.notification.title')"
|
2023-09-28 13:36:18 +00:00
|
|
|
>
|
|
|
|
<template #actions>
|
|
|
|
<div style="padding: 12px 16px">
|
2023-11-13 08:56:08 +00:00
|
|
|
<a
|
2023-09-28 13:36:18 +00:00
|
|
|
class="text-sm text-gray-600 hover:text-gray-900"
|
2023-11-13 08:56:08 +00:00
|
|
|
href="/uc/notifications"
|
2023-09-28 13:36:18 +00:00
|
|
|
>
|
|
|
|
{{ $t("core.common.buttons.view_all") }}
|
2023-11-13 08:56:08 +00:00
|
|
|
</a>
|
2023-09-28 13:36:18 +00:00
|
|
|
</div>
|
|
|
|
</template>
|
|
|
|
<VLoading v-if="isLoading" />
|
|
|
|
<VEmpty
|
|
|
|
v-else-if="!notifications?.length"
|
2023-11-30 10:56:10 +00:00
|
|
|
:title="$t('core.dashboard.widgets.presets.notification.empty.title')"
|
2023-09-28 13:36:18 +00:00
|
|
|
>
|
|
|
|
<template #actions>
|
|
|
|
<VButton :loading="isFetching" @click="refetch">
|
|
|
|
{{ $t("core.common.buttons.refresh") }}
|
|
|
|
</VButton>
|
|
|
|
</template>
|
|
|
|
</VEmpty>
|
|
|
|
<OverlayScrollbarsComponent
|
|
|
|
v-else
|
|
|
|
element="div"
|
|
|
|
:options="{ scrollbars: { autoHide: 'scroll' } }"
|
|
|
|
class="h-full w-full"
|
|
|
|
defer
|
|
|
|
>
|
|
|
|
<ul class="box-border h-full w-full divide-y divide-gray-100" role="list">
|
|
|
|
<li
|
|
|
|
v-for="notification in notifications"
|
|
|
|
:key="notification.metadata.name"
|
|
|
|
>
|
|
|
|
<VEntity>
|
|
|
|
<template #start>
|
|
|
|
<VEntityField
|
|
|
|
:title="notification.spec?.title"
|
|
|
|
:description="notification.spec?.rawContent"
|
2023-11-13 08:56:08 +00:00
|
|
|
@click="handleRouteToNotification(notification)"
|
2023-09-28 13:36:18 +00:00
|
|
|
/>
|
|
|
|
</template>
|
|
|
|
<template #end>
|
|
|
|
<VEntityField>
|
|
|
|
<template #description>
|
|
|
|
<span class="truncate text-xs tabular-nums text-gray-500">
|
|
|
|
{{
|
|
|
|
relativeTimeTo(notification.metadata.creationTimestamp)
|
|
|
|
}}
|
|
|
|
</span>
|
|
|
|
</template>
|
|
|
|
</VEntityField>
|
|
|
|
</template>
|
|
|
|
</VEntity>
|
|
|
|
</li>
|
|
|
|
</ul>
|
|
|
|
</OverlayScrollbarsComponent>
|
|
|
|
</VCard>
|
|
|
|
</template>
|