diff --git a/web/components/Notifications/List.vue b/web/components/Notifications/List.vue index 2dc82d900..cd2ab6cc3 100644 --- a/web/components/Notifications/List.vue +++ b/web/components/Notifications/List.vue @@ -6,11 +6,8 @@ import { import type { NotificationType } from "~/composables/gql/graphql"; import { useFragment } from "~/composables/gql/fragment-masking"; import { useQuery } from "@vue/apollo-composable"; -// import { useInfiniteScroll } from "@vueuse/core"; import { vInfiniteScroll } from "@vueuse/components"; -const element = ref(null); - /** * Page size is the max amount of items fetched from the api in a single request. */ @@ -20,7 +17,7 @@ const props = withDefaults( pageSize?: number; }>(), { - pageSize: 25, + pageSize: 15, } ); @@ -49,20 +46,16 @@ const notifications = computed(() => { async function onLoadMore() { console.log("[getNotifications] onLoadMore"); - // void fetchMore({ - // variables: { - // filter: { - // offset: notifications.value.length, - // limit: props.pageSize, - // type: props.type, - // }, - // }, - // }); + void fetchMore({ + variables: { + filter: { + offset: notifications.value.length, + limit: props.pageSize, + type: props.type, + }, + }, + }); } - -// const { isLoading } = useInfiniteScroll(element, onLoadMore, { -// distance: 25, -// }); diff --git a/web/composables/gql/graphql.ts b/web/composables/gql/graphql.ts index 320fff965..8ca0f4e66 100644 --- a/web/composables/gql/graphql.ts +++ b/web/composables/gql/graphql.ts @@ -636,7 +636,7 @@ export type Mutation = { connectSignIn: Scalars['Boolean']['output']; connectSignOut: Scalars['Boolean']['output']; createNotification: Notification; - deleteNotification: Notification; + deleteNotification: NotificationOverview; /** Delete a user */ deleteUser?: Maybe; enableDynamicRemoteAccess: Scalars['Boolean']['output']; diff --git a/web/helpers/apollo-cache.ts b/web/helpers/apollo-cache.ts index 4356183c4..bd67526a8 100644 --- a/web/helpers/apollo-cache.ts +++ b/web/helpers/apollo-cache.ts @@ -2,6 +2,23 @@ import { InMemoryCache, type InMemoryCacheConfig } from "@apollo/client/core"; const defaultCacheConfig: InMemoryCacheConfig = { typePolicies: { + Notifications: { + fields: { + list: { + keyArgs: ["filter", ["type", "importance"]], + merge(existing = [], incoming, { args }) { + // copied from https://www.apollographql.com/docs/react/pagination/core-api#improving-the-merge-function + const offset = args?.filter?.offset ?? 0; + const merged = existing.slice(0); + + for (let i = 0; i < incoming.length; ++i) { + merged[offset + i] = incoming[i]; + } + return merged; + }, + }, + }, + }, Mutation: { fields: { archiveAll: {