- Expand NotificationRepository (unread list paginated, count, markRead ownership-scoped); new ActivityLogRepository (create, findByProject paginated) with deterministic created_at+id ordering - NotificationService (notifyOnEvent, resolveTargets for 8 event types, injectable SseBroadcaster for M8) + ActivityLogService (logActivity, listByProject) - NotificationEvent/SseEvent/SseBroadcaster types in lib/types - APIs: GET /api/notifications, POST /api/notifications/:id/read, GET /api/projects/:projectId/activity - Screens: notifications list + MarkReadButton, NotificationBadge in Header, project activity page + ProjectNav link - Unit tests for both repositories and services (28 new)
32 lines
716 B
TypeScript
32 lines
716 B
TypeScript
'use client';
|
|
|
|
import { useState } from 'react';
|
|
import { useRouter } from 'next/navigation';
|
|
|
|
export function MarkReadButton({ notificationId }: { notificationId: number }) {
|
|
const router = useRouter();
|
|
const [busy, setBusy] = useState(false);
|
|
|
|
async function onRead() {
|
|
setBusy(true);
|
|
const res = await fetch(`/api/notifications/${notificationId}/read`, {
|
|
method: 'POST',
|
|
});
|
|
setBusy(false);
|
|
if (res.ok) {
|
|
router.refresh();
|
|
}
|
|
}
|
|
|
|
return (
|
|
<button
|
|
type="button"
|
|
onClick={onRead}
|
|
disabled={busy}
|
|
className="text-xs text-gray-500 hover:underline disabled:opacity-50"
|
|
>
|
|
{busy ? '処理中...' : '既読にする'}
|
|
</button>
|
|
);
|
|
}
|