From 18951cf9b0091fd8c7c8a67e904ef2fa1e1e24de Mon Sep 17 00:00:00 2001 From: Brandon Fancher Date: Thu, 10 Oct 2024 16:15:30 +0000 Subject: [PATCH] Refresh inbox messages onArchive. --- services/user/Chainmail/ui/src/components/mail-display.tsx | 7 +++++++ services/user/Chainmail/ui/src/lib/utils.ts | 2 ++ 2 files changed, 9 insertions(+) diff --git a/services/user/Chainmail/ui/src/components/mail-display.tsx b/services/user/Chainmail/ui/src/components/mail-display.tsx index f6812aa04..5fec63bf3 100644 --- a/services/user/Chainmail/ui/src/components/mail-display.tsx +++ b/services/user/Chainmail/ui/src/components/mail-display.tsx @@ -7,6 +7,7 @@ import { format } from "date-fns"; import { Archive, ArchiveRestore, Pin, Trash2 } from "lucide-react"; import { replaceAll } from "@milkdown/utils"; import { toast } from "sonner"; +import { useQueryClient } from "@tanstack/react-query"; import { Avatar, AvatarFallback, AvatarImage } from "@shadcn/avatar"; import { Button } from "@shadcn/button"; @@ -24,6 +25,7 @@ import { } from "@components"; import { Message, useDraftMessages, useIncomingMessages } from "@hooks"; import { getSupervisor } from "@lib/supervisor"; +import { wait } from "@lib/utils"; export function MailDisplay({ message, @@ -85,6 +87,7 @@ const ActionBar = ({ mailbox: Mailbox; message: Message; }) => { + const queryClient = useQueryClient(); const { setSelectedMessageId: setInboxMessageId } = useIncomingMessages(); const { selectedMessage: selectedDraftMessage, @@ -111,6 +114,10 @@ const ActionBar = ({ }); setInboxMessageId(""); toast.success("Your message has been archived"); + await wait(3000); + queryClient.invalidateQueries({ + queryKey: ["incoming"], + }); }; const onUnArchive = (itemId: string) => { diff --git a/services/user/Chainmail/ui/src/lib/utils.ts b/services/user/Chainmail/ui/src/lib/utils.ts index c8b5b8dab..3c73df14b 100644 --- a/services/user/Chainmail/ui/src/lib/utils.ts +++ b/services/user/Chainmail/ui/src/lib/utils.ts @@ -25,3 +25,5 @@ export function debounce any>( }; return (callable); } + +export const wait = (ms: number) => new Promise((res) => setTimeout(res, ms));