MCPcopy Create free account
hub / github.com/massCodeIO/massCode / patchSnippetInCollections

Function patchSnippetInCollections

src/renderer/composables/useSnippets.ts:418–457  ·  view source on GitHub ↗
(snippetId: number, data: SnippetsUpdate)

Source from the content-addressed store, hash-verified

416}
417
418function 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
459async function updateSnippet(snippetId: number, data: SnippetsUpdate) {
460 markPersistedStorageMutation()

Callers 1

updateSnippetFunction · 0.85

Calls 1

applyFunction · 0.70

Tested by

no test coverage detected