Hotfixes in ci/cd and notifications
This commit is contained in:
@@ -16,6 +16,7 @@ function App() {
|
||||
const [authChecked, setAuthChecked] = useState(false);
|
||||
const [showLogin, setShowLogin] = useState(false);
|
||||
const [showSaved, setShowSaved] = useState(false);
|
||||
const [badgeCount, setBadgeCount] = useState(0);
|
||||
const [screenSize, setScreenSize] = useState({
|
||||
width: window.innerWidth,
|
||||
height: window.innerHeight
|
||||
@@ -45,6 +46,31 @@ function App() {
|
||||
return () => window.removeEventListener('resize', handleResize);
|
||||
}, []);
|
||||
|
||||
useEffect(() => {
|
||||
if (!currentUser) { setBadgeCount(0); return; }
|
||||
let cancelled = false;
|
||||
fetch('/api/notifications/mine', { credentials: 'include' })
|
||||
.then(r => r.ok ? r.json() : null)
|
||||
.then(data => {
|
||||
if (cancelled || !data) return;
|
||||
const count = (data.global?.length || 0) + (data.pharmacy?.length || 0);
|
||||
setBadgeCount(count);
|
||||
})
|
||||
.catch(() => {});
|
||||
return () => { cancelled = true; };
|
||||
}, [currentUser]);
|
||||
|
||||
function refreshBadgeCount() {
|
||||
if (!currentUser) return;
|
||||
fetch('/api/notifications/mine', { credentials: 'include' })
|
||||
.then(r => r.ok ? r.json() : null)
|
||||
.then(data => {
|
||||
if (!data) return;
|
||||
setBadgeCount((data.global?.length || 0) + (data.pharmacy?.length || 0));
|
||||
})
|
||||
.catch(() => {});
|
||||
}
|
||||
|
||||
function handleLogin(user) {
|
||||
setCurrentUser(user);
|
||||
setShowLogin(false);
|
||||
@@ -98,7 +124,7 @@ function App() {
|
||||
);
|
||||
break;
|
||||
case 'alerts':
|
||||
activeView = <AlertsView />;
|
||||
activeView = <AlertsView onNotificationChange={refreshBadgeCount} />;
|
||||
break;
|
||||
case 'search':
|
||||
activeView = (
|
||||
@@ -143,7 +169,7 @@ function App() {
|
||||
activeTab={screen}
|
||||
onChange={handleNavChange}
|
||||
isLoggedIn={Boolean(currentUser)}
|
||||
badgeCount={currentUser ? 2 : 0}
|
||||
badgeCount={badgeCount}
|
||||
/>
|
||||
|
||||
{showLogin && (
|
||||
@@ -154,7 +180,7 @@ function App() {
|
||||
)}
|
||||
|
||||
{showSaved && currentUser && (
|
||||
<SavedNotifications onClose={() => setShowSaved(false)} />
|
||||
<SavedNotifications onClose={() => setShowSaved(false)} onNotificationChange={refreshBadgeCount} />
|
||||
)}
|
||||
</div>
|
||||
);
|
||||
|
||||
Reference in New Issue
Block a user