28 lines
641 B
TypeScript
28 lines
641 B
TypeScript
"use client";
|
|
|
|
import { useRouter } from "next/navigation";
|
|
import { useEffect, useRef } from "react";
|
|
|
|
type AnnouncementReadMarkerProps = {
|
|
id: string;
|
|
read: boolean;
|
|
};
|
|
|
|
export function AnnouncementReadMarker({ id, read }: AnnouncementReadMarkerProps) {
|
|
const router = useRouter();
|
|
const sentRef = useRef(false);
|
|
|
|
useEffect(() => {
|
|
if (read || sentRef.current) return;
|
|
|
|
sentRef.current = true;
|
|
void fetch(`/api/mobile/announcements/${encodeURIComponent(id)}/read`, { method: "POST" }).then((response) => {
|
|
if (response.ok) {
|
|
router.refresh();
|
|
}
|
|
});
|
|
}, [id, read, router]);
|
|
|
|
return null;
|
|
}
|