Browse Source

deleteable attachment

ryoji-s 2 years ago
parent
commit
febc9a1b79

+ 11 - 0
apps/app/src/components/ReactMarkdownComponents/RichAttachment.tsx

@@ -38,6 +38,17 @@ export const RichAttachment: React.FC<{
     fileSize,
   } = attachment;
 
+  // Guard here because attachment properties might be deleted in turn when an attachment is removed
+  if (filePathProxied == null
+    || originalName == null
+    || downloadPathProxied == null
+    || creator == null
+    || createdAt == null
+    || fileSize == null
+  ) {
+    return <span className='text-muted'>{t('rich_attachment.attachment_not_be_found')}</span>;
+  }
+
   return (
     <div className={`${styles.attachment} d-inline-block`}>
       <div className="my-2 p-2 card">

+ 1 - 1
apps/app/src/stores/attachment.tsx

@@ -36,7 +36,7 @@ export const useSWRxAttachment = (attachmentId: string): SWRResponseWithUtils<Ut
   const remove = useCallback(async(body: { attachment_id: string }) => {
     try {
       await apiPost('/attachments.remove', body);
-      swrResponse.mutate();
+      swrResponse.mutate(body.attachment_id);
     }
     catch (err) {
       throw err;