( queryClient: QueryClient, child: TypesGen.Chat, parentId: string, )
| 159 | * the child is silently dropped (it will appear when the parent loads). |
| 160 | */ |
| 161 | export 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 |
no test coverage detected