mirror of
https://github.com/multica-ai/multica.git
synced 2026-07-29 14:37:44 +02:00
- Create core/inbox/ with queries, mutations, ws-updaters - Migrate inbox page: useQuery + mutation hooks replace useInboxStore + api.* - Migrate sidebar unread badge to read from TQ cache - Delete useInboxStore (127 lines) — inbox has no client-only state - Remove inbox deps from workspace store (hydrate + switch) - Fix WS sync: use useQueryClient() instead of getQueryClient() singleton to ensure WS handlers write to the same QueryClient instance that components read from (singleton is unreliable under Next.js HMR) - Add onInboxIssueStatusChanged for issue status sync in inbox items 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 "@/shared/api";
|
|
import type { InboxItem } from "@/shared/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(),
|
|
);
|
|
}
|