src/drawer/Notifications.tsx
@@ -42,7 +42,15 @@ NotificationsDrawer const { items } = useNotifications();− useEffect(() => { if (open) refetch(); });+ const socket = useNotificationSocket();+ useEffect(() => {+ if (!open) return;+ return socket.on('notification:new',+ (n) => setItems((p) => [n, ...p]));+ }, [open, socket]); return <Drawer open={open}> @@ -8,6 +8,18 @@ useNotificationSocket const socket = useSocket();+ const on = useCallback((evt, fn) => {+ socket.on(evt, fn);+ return () => socket.off(evt, fn);+ }, [socket]);− return socket;+ return { on }; @@ -0,0 +1,4 @@+ it('appends a pushed notification',+ async () => {+ render(<NotificationsDrawer open />);+ socket.emit('notification:new', n);+ expect(await findByText(n.title))+ .toBeVisible();