Add live notifications for platform events via SSE - #140
Merged
Abd-Standard merged 2 commits intoJul 30, 2026
Conversation
Implements an in-memory notification store with pub/sub, wired into the task workflow so bounty creation, submission receipt, approval/rejection, reward payout, and comments each emit a notification. Notifications are delivered instantly over a Server-Sent Events stream, persisted for later viewing via a list endpoint, and tracked with a per-user unread count that updates as notifications are read individually or in bulk. Adds a NotificationBell UI in the navbar backed by a useNotifications hook.
- useNotificationPreferences: load persisted prefs via a useState lazy initializer instead of setState in an effect body, and defer the loading-flag flip to a microtask to satisfy react-hooks/set-state-in-effect. - useNotificationPreferences.test.ts: drop the unused `any`-cast import and other unused variables flagged by no-explicit-any / no-unused-vars. - rate-limit.test.ts: replace the built-in `Function` type with an explicit RouteHandler signature to satisfy no-unsafe-function-type.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Here is a clear, PR-ready description based on your implementation:
Real-Time Platform Notifications Feature
Summary
Implemented a real-time notification engine using Server-Sent Events (SSE) and an in-memory pub/sub store to notify users instantly of key task and bounty lifecycle events. Includes full state persistence (read/unread management), workflow event triggers, API routes, a navbar UI component, and test coverage.
What Was Built
lib/notification-store.ts: Built an in-memory pub/sub notification engine supporting both targeted per-user delivery and system broadcasts. Manages notification history, unread counters, and state transitions (read / read-all).
lib/task-workflow.ts: Extended workflow logic to include approveSubmission, rejectSubmission, and addComment. Injected notification triggers into createTask, submitTaskWork, and all newly added task action handlers.
bounty_created
submission_received
submission_approved
submission_rejected
reward_paid
comment_added
GET /api/notifications: Retrieves user notification history and unread count.
GET /api/notifications/stream: Server-Sent Events (SSE) endpoint providing instant event delivery and active connection heartbeats.
POST /api/notifications/[id]/read: Marks a single notification as read.
POST /api/notifications/read-all: Marks all notifications for a user as read.
POST /api/tasks/[taskId]/[approve|reject|comment]: Endpoint routes for task submission actions and commenting.
hooks/useNotifications.ts: Custom SSE client hook managing active stream connections, automatic reconnection handling, and local state updates.
components/NotificationBell.tsx: Interactive UI bell component displaying real-time unread badges and a notification list drawer.
Navbar.tsx: Integrated NotificationBell directly adjacent to the wallet connector, dynamically scoped to the user's connected wallet address.
Test Coverage
Added unit and integration test suites (all passing):
notification-store.test.ts — Validates pub/sub delivery, state mutations, and unread counts.
notifications-api.test.ts — Tests API route response shapes and SSE connection streaming.
task-workflow-notifications.test.ts — Confirms end-to-end event triggering when tasks are created, submitted, approved, rejected, or commented on.
Closes #132