From 8f6310b46326342c9a50321a056357c28d889994 Mon Sep 17 00:00:00 2001 From: James Collins Date: Wed, 19 Jul 2023 15:19:35 +1000 Subject: [PATCH] added delete item button --- resources/js/components/SMAttachments.vue | 60 ++++++++++++++++------- 1 file changed, 42 insertions(+), 18 deletions(-) diff --git a/resources/js/components/SMAttachments.vue b/resources/js/components/SMAttachments.vue index 05a016b..8632f02 100644 --- a/resources/js/components/SMAttachments.vue +++ b/resources/js/components/SMAttachments.vue @@ -41,6 +41,21 @@ + +
+ + Delete + + +
+ ({{ bytesReadable(file.size) }}) @@ -84,26 +99,35 @@ const props = defineProps({ * Handle the user adding a new media item. */ const handleClickAdd = async () => { - let result = await openDialog(SMDialogMedia, { - mime: "", - accepts: "", - allowUpload: true, - multiple: true, - }); - - if (result) { - const mediaResult = result as Media[]; - let newValue = props.modelValue; - let mediaIds = new Set(newValue.map((item) => item.id)); - - mediaResult.forEach((item) => { - if (!mediaIds.has(item.id)) { - newValue.push(item); - mediaIds.add(item.id); - } + if (props.showEditor) { + let result = await openDialog(SMDialogMedia, { + mime: "", + accepts: "", + allowUpload: true, + multiple: true, }); - emits("update:modelValue", newValue); + if (result) { + const mediaResult = result as Media[]; + let newValue = props.modelValue; + let mediaIds = new Set(newValue.map((item) => item.id)); + + mediaResult.forEach((item) => { + if (!mediaIds.has(item.id)) { + newValue.push(item); + mediaIds.add(item.id); + } + }); + + emits("update:modelValue", newValue); + } + } +}; + +const handleClickDelete = (id: string) => { + if (props.showEditor == true) { + const newList = props.modelValue.filter((item) => item.id !== id); + emits("update:modelValue", newList); } };