1- import { Accessor , createEffect , onCleanup , onMount } from 'solid-js' ;
1+ import { Accessor , createEffect , onCleanup } from 'solid-js' ;
22import { ListNotificationsArgs , ListNotificationsResponse } from '../../../notifications' ;
33import type { NotificationFilter } from '../../../types' ;
44import { isSameFilter } from '../../../utils/notification-utils' ;
@@ -10,21 +10,22 @@ type UseNotificationsInfiniteScrollProps = {
1010} ;
1111
1212export const useNotificationsInfiniteScroll = ( props : UseNotificationsInfiniteScrollProps ) => {
13- const novu = useNovu ( ) ;
13+ const novuAccessor = useNovu ( ) ;
1414 let filter = { ...props . options ( ) } ;
1515
1616 const [ data , { initialLoading, setEl, end, mutate, reset } ] = createInfiniteScroll (
1717 async ( after ) => {
18- const { data } = await novu . notifications . list ( { ...( props . options ( ) || { } ) , after } ) ;
18+ const { data } = await novuAccessor ( ) . notifications . list ( { ...( props . options ( ) || { } ) , after } ) ;
1919
2020 return { data : data ?. notifications ?? [ ] , hasMore : data ?. hasMore ?? false } ;
2121 } ,
2222 {
2323 paginationField : 'id' ,
24+ dependency : novuAccessor ,
2425 }
2526 ) ;
2627
27- onMount ( ( ) => {
28+ createEffect ( ( ) => {
2829 const listener = ( { data } : { data : ListNotificationsResponse } ) => {
2930 if ( ! data || ! isSameFilter ( filter , data . filter ) ) {
3031 return ;
@@ -33,7 +34,7 @@ export const useNotificationsInfiniteScroll = (props: UseNotificationsInfiniteSc
3334 mutate ( { data : data . notifications , hasMore : data . hasMore } ) ;
3435 } ;
3536
36- const cleanup = novu . on ( 'notifications.list.updated' , listener ) ;
37+ const cleanup = novuAccessor ( ) . on ( 'notifications.list.updated' , listener ) ;
3738
3839 onCleanup ( ( ) => cleanup ( ) ) ;
3940 } ) ;
@@ -44,13 +45,13 @@ export const useNotificationsInfiniteScroll = (props: UseNotificationsInfiniteSc
4445 return ;
4546 }
4647
47- novu . notifications . clearCache ( ) ;
48+ novuAccessor ( ) . notifications . clearCache ( ) ;
4849 await reset ( ) ;
4950 filter = newFilter ;
5051 } ) ;
5152
5253 const refetch = async ( { filter } : { filter ?: NotificationFilter } ) => {
53- novu . notifications . clearCache ( { filter } ) ;
54+ novuAccessor ( ) . notifications . clearCache ( { filter } ) ;
5455 await reset ( ) ;
5556 } ;
5657
0 commit comments