From 0e1f4c527ef82e7877020bdd16ab10176bcd27ed Mon Sep 17 00:00:00 2001 From: Lim Chee Aun Date: Wed, 14 Dec 2022 00:20:24 +0800 Subject: [PATCH] This close window check is getting on my nerves --- src/components/compose.jsx | 24 +++++++++++++++++++----- 1 file changed, 19 insertions(+), 5 deletions(-) diff --git a/src/components/compose.jsx b/src/components/compose.jsx index eda2d3fa..aef824c 100644 --- a/src/components/compose.jsx +++ b/src/components/compose.jsx @@ -208,15 +208,20 @@ export default ({ const canClose = () => { const { value, dataset } = textareaRef.current; - // check for status and media attachments with IDs - const hasIDMediaAttachments = - mediaAttachments.length > 0 && - mediaAttachments.every((media) => media.id); - if (!value && hasIDMediaAttachments) { + // check for status and media attachments + const hasMediaAttachments = mediaAttachments.length > 0; + if (!value && !hasMediaAttachments) { console.log('canClose', { value, mediaAttachments }); return true; } + // check if all media attachments have IDs + const hasIDMediaAttachments = mediaAttachments.every((media) => media.id); + if (hasIDMediaAttachments) { + console.log('canClose', { hasIDMediaAttachments }); + return true; + } + // check if status contains only "@acct", if replying const isSelf = replyToStatus?.account.id === currentAccount; const hasOnlyAcct = @@ -233,6 +238,15 @@ export default ({ return true; } + console.log('canClose', { + value, + hasMediaAttachments, + hasIDMediaAttachments, + isSelf, + hasOnlyAcct, + sameWithSource, + }); + return false; };