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

Function deleteSelectedSnippets

src/renderer/composables/useSnippets.ts:526–604  ·  view source on GitHub ↗
(fallbackSnippet?: SnippetsResponse[0])

Source from the content-addressed store, hash-verified

524}
525
526async function deleteSelectedSnippets(fallbackSnippet?: SnippetsResponse[0]) {
527 const { confirm } = useDialog()
528 const targetIds = getActionTargetIds(fallbackSnippet?.id)
529
530 if (!targetIds.length) {
531 return
532 }
533
534 const targetSnippets = getActionTargetSnippets(targetIds, fallbackSnippet)
535
536 if (targetIds.length > 1) {
537 const isAllSoftDeleted
538 = targetSnippets.length === targetIds.length
539 && targetSnippets.every(snippet => snippet.isDeleted)
540
541 if (isAllSoftDeleted) {
542 const isConfirmed = await confirm({
543 title: i18n.t('messages:confirm.deleteConfirmMultipleSnippets', {
544 count: targetIds.length,
545 }),
546 content: i18n.t('messages:warning.noUndo'),
547 })
548
549 if (isConfirmed) {
550 await deleteSnippets(targetIds)
551 selectFirstSnippet()
552 }
553 }
554 else {
555 const snippetsData = targetIds.map(() => ({
556 folderId: null,
557 isDeleted: 1,
558 }))
559
560 await updateSnippets(targetIds, snippetsData)
561 selectFirstSnippet()
562 }
563
564 return
565 }
566
567 const targetSnippet = targetSnippets[0]
568
569 if (!targetSnippet) {
570 return
571 }
572
573 if (!targetSnippet.isDeleted) {
574 await updateSnippet(targetSnippet.id, {
575 folderId: null,
576 isDeleted: 1,
577 })
578
579 if (state.snippetId === targetSnippet.id) {
580 selectFirstSnippet()
581 }
582
583 return

Callers

nothing calls this directly

Calls 9

useDialogFunction · 0.85
getActionTargetSnippetsFunction · 0.85
confirmFunction · 0.85
deleteSnippetsFunction · 0.85
selectFirstSnippetFunction · 0.85
updateSnippetsFunction · 0.85
updateSnippetFunction · 0.85
getActionTargetIdsFunction · 0.70
deleteSnippetFunction · 0.70

Tested by

no test coverage detected