MCPcopy Index your code
hub / github.com/coder/coder / addChildToParentInCache

Function addChildToParentInCache

site/src/api/queries/chats.ts:161–177  ·  view source on GitHub ↗
(
	queryClient: QueryClient,
	child: TypesGen.Chat,
	parentId: string,
)

Source from the content-addressed store, hash-verified

159 * the child is silently dropped (it will appear when the parent loads).
160 */
161export const addChildToParentInCache = (
162 queryClient: QueryClient,
163 child: TypesGen.Chat,
164 parentId: string,
165) => {
166 updateInfiniteChatsCache(queryClient, (chats) => {
167 let changed = false;
168 const next = chats.map((c) => {
169 if (c.id !== parentId) return c;
170 // Avoid duplicates.
171 if (c.children?.some((ch) => ch.id === child.id)) return c;
172 changed = true;
173 return { ...c, children: [child, ...(c.children ?? [])] };
174 });
175 return changed ? next : chats;
176 });
177};
178
179/**
180 * Updates a child chat within its parent's `children` array across all

Callers 2

connectFunction · 0.90
chats.test.tsFile · 0.90

Calls 1

updateInfiniteChatsCacheFunction · 0.85

Tested by

no test coverage detected