( queryClient: QueryClient, updater: (child: TypesGen.Chat) => TypesGen.Chat, childId: string, )
| 182 | * updated, false otherwise. |
| 183 | */ |
| 184 | export const updateChildInParentCache = ( |
| 185 | queryClient: QueryClient, |
| 186 | updater: (child: TypesGen.Chat) => TypesGen.Chat, |
| 187 | childId: string, |
| 188 | ) => { |
| 189 | let found = false; |
| 190 | updateInfiniteChatsCache(queryClient, (chats) => { |
| 191 | let changed = false; |
| 192 | const next = chats.map((c) => { |
| 193 | if (!c.children?.length) return c; |
| 194 | let childChanged = false; |
| 195 | const nextChildren = c.children.map((ch) => { |
| 196 | if (ch.id !== childId) return ch; |
| 197 | const updated = updater(ch); |
| 198 | if (updated !== ch) { |
| 199 | childChanged = true; |
| 200 | found = true; |
| 201 | } |
| 202 | return updated; |
| 203 | }); |
| 204 | if (!childChanged) return c; |
| 205 | changed = true; |
| 206 | return { ...c, children: nextChildren }; |
| 207 | }); |
| 208 | return changed ? next : chats; |
| 209 | }); |
| 210 | return found; |
| 211 | }; |
| 212 | |
| 213 | /** |
| 214 | * Removes a child chat from its parent's `children` array across all |
no test coverage detected