25 lines
1.2 KiB
TypeScript
25 lines
1.2 KiB
TypeScript
import type { LoaderFunctionArgs } from "react-router";
|
|
import { CatalogError, foundationErrors } from "@hivegrid/foundation";
|
|
import { loadProjectBoard } from "~/utils/integrations/projects/projectService.server";
|
|
import { loadProjectContext, requireProjectPermission } from "~/utils/integrations/projects/projectAccess.server";
|
|
import { eventStream } from "~/utils/stream/event-stream";
|
|
|
|
export async function loader({ request, params }: LoaderFunctionArgs) {
|
|
const ctx = requireProjectPermission(await loadProjectContext({ request, params, requireModule: true }), "projects.read_own");
|
|
const pipelineId = params.pipelineId;
|
|
if (!pipelineId) throw new CatalogError(foundationErrors.notFound);
|
|
return eventStream(request.signal, (send) => {
|
|
let closed = false;
|
|
void loadProjectBoard({ tenantId: ctx.tenantId, ctx, pipelineId }).then((board) => {
|
|
if (!closed) send({ event: "projects.board.snapshot", data: JSON.stringify(board) });
|
|
});
|
|
const heartbeat = setInterval(() => {
|
|
send({ event: "projects.board.heartbeat", data: JSON.stringify({ pipelineId, at: new Date().toISOString() }) });
|
|
}, 30_000);
|
|
return () => {
|
|
closed = true;
|
|
clearInterval(heartbeat);
|
|
};
|
|
});
|
|
}
|