(snippetId: number, data: SnippetsUpdate)
| 416 | } |
| 417 | |
| 418 | function patchSnippetInCollections(snippetId: number, data: SnippetsUpdate) { |
| 419 | const now = Date.now() |
| 420 | |
| 421 | function apply(collection?: SnippetsResponse) { |
| 422 | if (!collection) { |
| 423 | return collection |
| 424 | } |
| 425 | |
| 426 | const index = collection.findIndex(s => s.id === snippetId) |
| 427 | if (index === -1) { |
| 428 | return collection |
| 429 | } |
| 430 | |
| 431 | const next = [...collection] |
| 432 | next[index] = { |
| 433 | ...next[index], |
| 434 | ...(data.name !== undefined ? { name: data.name } : {}), |
| 435 | ...(data.description !== undefined |
| 436 | ? { description: data.description } |
| 437 | : {}), |
| 438 | updatedAt: now, |
| 439 | } |
| 440 | return next |
| 441 | } |
| 442 | |
| 443 | snippets.value = apply(snippets.value) |
| 444 | snippetsBySearch.value = apply(snippetsBySearch.value) |
| 445 | |
| 446 | const record = selectedSnippetRecord.value |
| 447 | if (record?.id === snippetId) { |
| 448 | selectedSnippetRecord.value = { |
| 449 | ...record, |
| 450 | ...(data.name !== undefined ? { name: data.name } : {}), |
| 451 | ...(data.description !== undefined |
| 452 | ? { description: data.description } |
| 453 | : {}), |
| 454 | updatedAt: now, |
| 455 | } |
| 456 | } |
| 457 | } |
| 458 | |
| 459 | async function updateSnippet(snippetId: number, data: SnippetsUpdate) { |
| 460 | markPersistedStorageMutation() |
no test coverage detected