Files
api/web/components/Notifications/List.vue
Eli Bosley 345e83bfb0 feat: upgrade nuxt-custom-elements (#1461)
<!-- This is an auto-generated comment: release notes by coderabbit.ai
-->
## Summary by CodeRabbit

* **New Features**
* Added new modal dialogs and UI components, including activation steps,
OS update feedback, and expanded notification management.
* Introduced a plugin to configure internationalization, state
management, and Apollo client support in web components.
* Added a new Log Viewer page with a streamlined interface for viewing
logs.

* **Improvements**
* Centralized Pinia state management by consolidating all stores to use
a shared global Pinia instance.
* Simplified component templates by removing redundant
internationalization host wrappers.
* Enhanced ESLint configuration with stricter rules and global variable
declarations.
* Refined custom element build process to prevent jQuery conflicts and
optimize minification.
* Updated component imports and templates for consistent structure and
maintainability.
* Streamlined log viewer dropdowns using simplified select components
with improved formatting.
* Improved notification sidebar with filtering by importance and modular
components.
* Replaced legacy notification popups with new UI components and added
automatic root session creation for localhost requests.
* Updated OS version display and user profile UI with refined styling
and component usage.

* **Bug Fixes**
* Fixed component tag capitalization and improved type annotations
across components.

* **Chores**
* Updated development dependencies including ESLint plugins and build
tools.
* Removed deprecated log viewer patch class and cleaned up related test
fixtures.
  * Removed unused imports and simplified Apollo client setup.
* Cleaned up test mocks and removed obsolete i18n host component tests.
<!-- end of auto-generated comment: release notes by coderabbit.ai -->

---
- To see the specific tasks where the Asana app for GitHub is being
used, see below:
  - https://app.asana.com/0/0/1210730229632804

---------

Co-authored-by: Pujit Mehrotra <pujit@lime-technology.com>
Co-authored-by: Zack Spear <zackspear@users.noreply.github.com>
2025-07-08 10:05:39 -04:00

118 lines
3.7 KiB
Vue

<script setup lang="ts">
import { computed, ref, watch } from 'vue';
import { useQuery } from '@vue/apollo-composable';
import { vInfiniteScroll } from '@vueuse/components';
import { CheckIcon } from '@heroicons/vue/24/solid';
import { Error as LoadingError, Spinner as LoadingSpinner } from '@unraid/ui';
import type { NotificationImportance as Importance, NotificationType } from '~/composables/gql/graphql';
import { useHaveSeenNotifications } from '~/composables/api/use-notifications';
import { useFragment } from '~/composables/gql/fragment-masking';
import { useUnraidApiStore } from '~/store/unraidApi';
import { getNotifications, NOTIFICATION_FRAGMENT } from './graphql/notification.query';
import NotificationsItem from './Item.vue';
/**
* Page size is the max amount of items fetched from the api in a single request.
*/
const props = withDefaults(
defineProps<{
type: NotificationType;
pageSize?: number;
importance?: Importance;
}>(),
{
pageSize: 15,
importance: undefined,
}
);
/** whether we should continue trying to load more notifications */
const canLoadMore = ref(true);
/** reset custom state when props (e.g. props.type filter) change*/
watch(props, () => {
canLoadMore.value = true;
});
const { offlineError } = useUnraidApiStore();
const { result, error, loading, fetchMore, refetch } = useQuery(getNotifications, () => ({
filter: {
offset: 0,
limit: props.pageSize,
type: props.type,
importance: props.importance,
},
}));
const notifications = computed(() => {
if (!result.value?.notifications.list) return [];
const list = useFragment(NOTIFICATION_FRAGMENT, result.value?.notifications.list);
// necessary because some items in this list may change their type (e.g. archival)
// and we don't want to display them in the wrong list client-side.
return list.filter((n) => n.type === props.type);
});
// saves timestamp of latest visible notification to local storage
const { latestSeenTimestamp } = useHaveSeenNotifications();
watch(
notifications,
() => {
const [latest] = notifications.value;
if (!latest?.timestamp) return;
if (new Date(latest.timestamp) > new Date(latestSeenTimestamp.value)) {
console.log('[notif list] setting last seen timestamp', latest.timestamp);
latestSeenTimestamp.value = latest.timestamp;
}
},
{ immediate: true }
);
async function onLoadMore() {
console.log('[getNotifications] onLoadMore');
const incoming = await fetchMore({
variables: {
filter: {
offset: notifications.value.length,
limit: props.pageSize,
type: props.type,
importance: props.importance,
},
},
});
const incomingCount = incoming?.data.notifications.list.length ?? 0;
if (incomingCount === 0 || incomingCount < props.pageSize) {
canLoadMore.value = false;
}
}
</script>
<template>
<div
v-if="notifications?.length > 0"
v-infinite-scroll="[onLoadMore, { canLoadMore: () => canLoadMore }]"
class="divide-y px-7 flex flex-col overflow-y-scroll flex-1 min-h-0"
>
<NotificationsItem
v-for="notification in notifications"
:key="notification.id"
v-bind="notification"
/>
<div v-if="loading" class="py-5 grid place-content-center">
<LoadingSpinner />
</div>
<div v-if="!canLoadMore" class="py-5 grid place-content-center text-secondary-foreground">
You've reached the end...
</div>
</div>
<LoadingError v-else :loading="loading" :error="offlineError ?? error" @retry="refetch">
<div v-if="notifications?.length === 0" class="contents">
<CheckIcon class="h-10 text-green-600 translate-y-3" />
{{ `No ${props.importance?.toLowerCase() ?? ''} notifications to see here!` }}
</div>
</LoadingError>
</template>