⚙️ Atualização local para GPI - Sync via Antigravity
This commit is contained in:
@@ -1,16 +1,16 @@
|
||||
import React, { useState, useEffect, useCallback } from 'react';
|
||||
import { useAuth } from '@clerk/clerk-react';
|
||||
import { useAuth } from '../context/useAuth';
|
||||
import api from '../services/api';
|
||||
import type { INotification } from '../types';
|
||||
import { NotificationContext } from './NotificationContextState';
|
||||
|
||||
export const NotificationProvider: React.FC<{ children: React.ReactNode }> = ({ children }) => {
|
||||
const { orgId, isSignedIn } = useAuth();
|
||||
const { appUser, isSignedIn } = useAuth();
|
||||
const [notifications, setNotifications] = useState<INotification[]>([]);
|
||||
const [loading, setLoading] = useState(false);
|
||||
|
||||
const fetchNotifications = useCallback(async () => {
|
||||
if (!orgId || !isSignedIn) return;
|
||||
if (!isSignedIn) return;
|
||||
|
||||
try {
|
||||
if (notifications.length === 0) setLoading(true);
|
||||
@@ -21,7 +21,7 @@ export const NotificationProvider: React.FC<{ children: React.ReactNode }> = ({
|
||||
} finally {
|
||||
setLoading(false);
|
||||
}
|
||||
}, [orgId, isSignedIn, notifications.length]);
|
||||
}, [isSignedIn, notifications.length]);
|
||||
|
||||
const markAsRead = async (id: string) => {
|
||||
try {
|
||||
@@ -70,7 +70,7 @@ export const NotificationProvider: React.FC<{ children: React.ReactNode }> = ({
|
||||
|
||||
// Polling effect
|
||||
useEffect(() => {
|
||||
if (isSignedIn && orgId) {
|
||||
if (isSignedIn) {
|
||||
fetchNotifications(); // Initial fetch
|
||||
|
||||
const interval = setInterval(() => {
|
||||
@@ -81,7 +81,7 @@ export const NotificationProvider: React.FC<{ children: React.ReactNode }> = ({
|
||||
} else {
|
||||
setNotifications([]);
|
||||
}
|
||||
}, [isSignedIn, orgId, fetchNotifications]);
|
||||
}, [isSignedIn, fetchNotifications]);
|
||||
|
||||
const unreadCount = notifications.filter(n => !n.isRead).length;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user