mirror of
https://github.com/multica-ai/multica.git
synced 2026-07-16 22:59:04 +02:00
Phase 1: Monorepo infrastructure - Add Turborepo with turbo.json pipeline (build, dev, typecheck, test) - Update pnpm-workspace.yaml to include packages/* - Create shared TypeScript config (packages/tsconfig) Phase 2: Extract packages/core (zero react-dom, all-platform reuse) - Move domain types, API client, logger, utils → packages/core/ - Move TanStack Query modules (issues, inbox, workspace, runtimes) - Move Zustand stores (auth, workspace, issues, navigation, modals) - Move realtime sync (WSProvider, hooks, ws-updaters) - Refactor auth/workspace stores to factory pattern for DI - Refactor ApiClient with onUnauthorized callback - Refactor useWorkspaceId to React Context (WorkspaceIdProvider) - Refactor WSProvider to accept wsUrl + store props - Create apps/web/platform/ bridge layer (api singleton, store instances) - Update 91 import paths across apps/web/ - Fix 3 test files for new import paths Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
34 lines
899 B
TypeScript
34 lines
899 B
TypeScript
"use client";
|
|
|
|
import { useEffect } from "react";
|
|
import type { WSEventType } from "../types";
|
|
import { useWS } from "./provider";
|
|
|
|
type EventHandler = (payload: unknown, actorId?: string) => void;
|
|
|
|
/**
|
|
* Hook that subscribes to a WebSocket event and calls the handler.
|
|
* Automatically unsubscribes on cleanup.
|
|
*/
|
|
export function useWSEvent(event: WSEventType, handler: EventHandler) {
|
|
const { subscribe } = useWS();
|
|
|
|
useEffect(() => {
|
|
const unsub = subscribe(event, handler);
|
|
return unsub;
|
|
}, [event, handler, subscribe]);
|
|
}
|
|
|
|
/**
|
|
* Hook that registers a callback to run on WebSocket reconnection.
|
|
* Useful for refetching component-local data after a network interruption.
|
|
*/
|
|
export function useWSReconnect(callback: () => void) {
|
|
const { onReconnect } = useWS();
|
|
|
|
useEffect(() => {
|
|
const unsub = onReconnect(callback);
|
|
return unsub;
|
|
}, [callback, onReconnect]);
|
|
}
|