Increment version to 2.14.1 and refactor notifications stream hook
- Bumped package version in package.json from 2.14.0 to 2.14.1. - Refactored the `useNotificationsStream` hook to remove unnecessary `useQuery` and streamline the subscription logic for real-time notifications, enhancing performance and clarity.
This commit is contained in:
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "next-supabase-saas-kit-turbo",
|
"name": "next-supabase-saas-kit-turbo",
|
||||||
"version": "2.14.0",
|
"version": "2.14.1",
|
||||||
"private": true,
|
"private": true,
|
||||||
"sideEffects": false,
|
"sideEffects": false,
|
||||||
"engines": {
|
"engines": {
|
||||||
|
|||||||
@@ -1,7 +1,5 @@
|
|||||||
import { useEffect } from 'react';
|
import { useEffect } from 'react';
|
||||||
|
|
||||||
import { useQuery } from '@tanstack/react-query';
|
|
||||||
|
|
||||||
import { useSupabase } from '@kit/supabase/hooks/use-supabase';
|
import { useSupabase } from '@kit/supabase/hooks/use-supabase';
|
||||||
|
|
||||||
type Notification = {
|
type Notification = {
|
||||||
@@ -20,32 +18,27 @@ export function useNotificationsStream(params: {
|
|||||||
}) {
|
}) {
|
||||||
const client = useSupabase();
|
const client = useSupabase();
|
||||||
|
|
||||||
const { data: subscription } = useQuery({
|
|
||||||
enabled: params.enabled,
|
|
||||||
queryKey: ['realtime-notifications', ...params.accountIds],
|
|
||||||
queryFn: () => {
|
|
||||||
const channel = client.channel('notifications-channel');
|
|
||||||
|
|
||||||
return channel
|
|
||||||
.on(
|
|
||||||
'postgres_changes',
|
|
||||||
{
|
|
||||||
event: 'INSERT',
|
|
||||||
schema: 'public',
|
|
||||||
filter: `account_id=in.(${params.accountIds.join(', ')})`,
|
|
||||||
table: 'notifications',
|
|
||||||
},
|
|
||||||
(payload) => {
|
|
||||||
params.onNotifications([payload.new as Notification]);
|
|
||||||
},
|
|
||||||
)
|
|
||||||
.subscribe();
|
|
||||||
},
|
|
||||||
});
|
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
|
const channel = client.channel('notifications-channel');
|
||||||
|
|
||||||
|
const subscription = channel
|
||||||
|
.on(
|
||||||
|
'postgres_changes',
|
||||||
|
{
|
||||||
|
event: 'INSERT',
|
||||||
|
schema: 'public',
|
||||||
|
filter: `account_id=in.(${params.accountIds.join(', ')})`,
|
||||||
|
table: 'notifications',
|
||||||
|
},
|
||||||
|
(payload) => {
|
||||||
|
console.log('payload', payload);
|
||||||
|
params.onNotifications([payload.new as Notification]);
|
||||||
|
},
|
||||||
|
)
|
||||||
|
.subscribe();
|
||||||
|
|
||||||
return () => {
|
return () => {
|
||||||
void subscription?.unsubscribe();
|
void subscription?.unsubscribe();
|
||||||
};
|
};
|
||||||
}, [subscription]);
|
}, [client, params]);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user