- Create core/workspace/ with queries (members, agents, skills, list) and mutations - Create core/runtimes/ with queries - Migrate 11 consumer files from useWorkspaceStore.members/agents/skills to useQuery - Replace all WS refreshMap entries with qc.invalidateQueries - Simplify workspace store: delete members/agents/skills fields + refresh methods, hydrateWorkspace becomes synchronous (TQ auto-fetches on component mount) - Delete useRuntimeStore (no consumers left), runtimes-page uses local useState + TQ - Remove workspace→runtime cross-store dependency - Clean up dead test helper mocks Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
45 lines
1.4 KiB
TypeScript
45 lines
1.4 KiB
TypeScript
"use client";
|
|
|
|
import { useQuery } from "@tanstack/react-query";
|
|
import { useWorkspaceId } from "@core/hooks";
|
|
import { memberListOptions, agentListOptions } from "@core/workspace/queries";
|
|
|
|
export function useActorName() {
|
|
const wsId = useWorkspaceId();
|
|
const { data: members = [] } = useQuery(memberListOptions(wsId));
|
|
const { data: agents = [] } = useQuery(agentListOptions(wsId));
|
|
|
|
const getMemberName = (userId: string) => {
|
|
const m = members.find((m) => m.user_id === userId);
|
|
return m?.name ?? "Unknown";
|
|
};
|
|
|
|
const getAgentName = (agentId: string) => {
|
|
const a = agents.find((a) => a.id === agentId);
|
|
return a?.name ?? "Unknown Agent";
|
|
};
|
|
|
|
const getActorName = (type: string, id: string) => {
|
|
if (type === "member") return getMemberName(id);
|
|
if (type === "agent") return getAgentName(id);
|
|
return "System";
|
|
};
|
|
|
|
const getActorInitials = (type: string, id: string) => {
|
|
const name = getActorName(type, id);
|
|
return name
|
|
.split(" ")
|
|
.map((w) => w[0])
|
|
.join("")
|
|
.toUpperCase()
|
|
.slice(0, 2);
|
|
};
|
|
|
|
const getActorAvatarUrl = (type: string, id: string): string | null => {
|
|
if (type === "member") return members.find((m) => m.user_id === id)?.avatar_url ?? null;
|
|
if (type === "agent") return agents.find((a) => a.id === id)?.avatar_url ?? null;
|
|
return null;
|
|
};
|
|
|
|
return { getMemberName, getAgentName, getActorName, getActorInitials, getActorAvatarUrl };
|
|
}
|