From e6a345e4287b7a8c28e8b70751961afd6bf13659 Mon Sep 17 00:00:00 2001 From: gitkeniwo Date: Tue, 18 Nov 2025 15:08:17 +0100 Subject: [PATCH] fix: address Copilot review. Add error handling and remove unnecessary memo preloading - Add error handling with toast notifications for attachment loading failures - Remove unnecessary memo preloading that caused errors with invalid UTF-8 data - Improve performance by eliminating unneeded API calls - Remove unused memoStore import --- web/src/pages/Attachments.tsx | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/web/src/pages/Attachments.tsx b/web/src/pages/Attachments.tsx index 3dc5c8b3e..325ff64a0 100644 --- a/web/src/pages/Attachments.tsx +++ b/web/src/pages/Attachments.tsx @@ -3,6 +3,7 @@ import { includes } from "lodash-es"; import { PaperclipIcon, SearchIcon } from "lucide-react"; import { observer } from "mobx-react-lite"; import { useEffect, useState } from "react"; +import { toast } from "react-hot-toast"; import AttachmentIcon from "@/components/AttachmentIcon"; import Empty from "@/components/Empty"; import MobileHeader from "@/components/MobileHeader"; @@ -13,7 +14,6 @@ import { attachmentServiceClient } from "@/grpcweb"; import useLoading from "@/hooks/useLoading"; import useResponsiveWidth from "@/hooks/useResponsiveWidth"; import i18n from "@/i18n"; -import { memoStore } from "@/store"; import { Attachment } from "@/types/proto/api/v1/attachment_service"; import { useTranslate } from "@/utils/i18n"; @@ -57,9 +57,9 @@ const Attachments = observer(() => { }); setAttachments(fetchedAttachments); setNextPageToken(nextPageToken ?? ""); - await Promise.all( - fetchedAttachments.map((attachment) => (attachment.memo ? memoStore.getOrFetchMemoByName(attachment.memo) : null)), - ); + } catch (error) { + console.error("Failed to fetch attachments:", error); + toast.error("Failed to load attachments. Please try again."); } finally { loadingState.setFinish(); } @@ -80,7 +80,9 @@ const Attachments = observer(() => { }); setAttachments((prevAttachments) => [...prevAttachments, ...fetchedAttachments]); setNextPageToken(newPageToken ?? ""); - await Promise.all(fetchedAttachments.map((attachment) => (attachment.memo ? memoStore.getOrFetchMemoByName(attachment.memo) : null))); + } catch (error) { + console.error("Failed to load more attachments:", error); + toast.error("Failed to load more attachments. Please try again."); } finally { setIsLoadingMore(false); }