mirror of
https://github.com/multica-ai/multica.git
synced 2026-07-23 10:08:38 +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>
44 lines
1.3 KiB
TypeScript
44 lines
1.3 KiB
TypeScript
import { queryOptions } from "@tanstack/react-query";
|
|
import { api } from "../api";
|
|
import type { InboxItem } from "../types";
|
|
|
|
export const inboxKeys = {
|
|
all: (wsId: string) => ["inbox", wsId] as const,
|
|
list: (wsId: string) => [...inboxKeys.all(wsId), "list"] as const,
|
|
};
|
|
|
|
export function inboxListOptions(wsId: string) {
|
|
return queryOptions({
|
|
queryKey: inboxKeys.list(wsId),
|
|
queryFn: () => api.listInbox(),
|
|
});
|
|
}
|
|
|
|
/**
|
|
* Deduplicate inbox items by issue_id (one entry per issue, Linear-style).
|
|
* Exported for consumers to use in useMemo — not in queryOptions select
|
|
* (to avoid new array references on every cache update).
|
|
*/
|
|
export function deduplicateInboxItems(items: InboxItem[]): InboxItem[] {
|
|
const active = items.filter((i) => !i.archived);
|
|
const groups = new Map<string, InboxItem[]>();
|
|
for (const item of active) {
|
|
const key = item.issue_id ?? item.id;
|
|
const group = groups.get(key) ?? [];
|
|
group.push(item);
|
|
groups.set(key, group);
|
|
}
|
|
const merged: InboxItem[] = [];
|
|
for (const group of groups.values()) {
|
|
group.sort(
|
|
(a, b) =>
|
|
new Date(b.created_at).getTime() - new Date(a.created_at).getTime(),
|
|
);
|
|
if (group[0]) merged.push(group[0]);
|
|
}
|
|
return merged.sort(
|
|
(a, b) =>
|
|
new Date(b.created_at).getTime() - new Date(a.created_at).getTime(),
|
|
);
|
|
}
|