( previous: Search, chunk: Partial<SearchChunk>, )
| 395 | }; |
| 396 | |
| 397 | export const updateSearchData = ( |
| 398 | previous: Search, |
| 399 | chunk: Partial<SearchChunk>, |
| 400 | ): Search => { |
| 401 | const updated = { |
| 402 | ...previous, |
| 403 | chunks: [{ ...previous?.chunks?.[0], ...chunk }], |
| 404 | }; |
| 405 | const currentChunk = updated.chunks[0]; |
| 406 | |
| 407 | if (!currentChunk) { |
| 408 | return updated; |
| 409 | } |
| 410 | |
| 411 | if (chunk.error) { |
| 412 | return updated; |
| 413 | } |
| 414 | |
| 415 | if (chunk.status) { |
| 416 | currentChunk.progress = (currentChunk.progress ?? 0) + 1; |
| 417 | } |
| 418 | |
| 419 | if (chunk.completedAt) { |
| 420 | currentChunk.progress = currentChunk.steps; |
| 421 | } |
| 422 | |
| 423 | if (isNullOrUndefined(chunk.response)) { |
| 424 | return updated; |
| 425 | } |
| 426 | |
| 427 | currentChunk.response = (previous.chunks[0]?.response ?? '') + chunk.response; |
| 428 | |
| 429 | return updated; |
| 430 | }; |
| 431 | |
| 432 | interface SearchUrlParams { |
| 433 | id?: string; |
nothing calls this directly
no test coverage detected