From e207c3bf9b8a988912f2016c3244554108934da4 Mon Sep 17 00:00:00 2001 From: Aj Wazzan Date: Sun, 4 May 2025 12:34:14 -0700 Subject: [PATCH] feat: enhance useMoveTo hook with focused index and query state management --- apps/mail/hooks/driver/use-move-to.ts | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/apps/mail/hooks/driver/use-move-to.ts b/apps/mail/hooks/driver/use-move-to.ts index 8ef9035a7..1705c5cf1 100644 --- a/apps/mail/hooks/driver/use-move-to.ts +++ b/apps/mail/hooks/driver/use-move-to.ts @@ -1,10 +1,13 @@ import { moveThreadsTo, type MoveThreadOptions } from '@/lib/thread-actions'; import useBackgroundQueue from '@/hooks/ui/use-background-queue'; +import { focusedIndexAtom } from '../use-mail-navigation'; import { useMail } from '@/components/mail/use-mail'; import { useThreads } from '@/hooks/use-threads'; import { useStats } from '@/hooks/use-stats'; import { useTranslations } from 'next-intl'; +import { useQueryState } from 'nuqs'; import { useState } from 'react'; +import { useAtom } from 'jotai'; import { toast } from 'sonner'; const useMoveTo = () => { @@ -14,6 +17,9 @@ const useMoveTo = () => { const { refetch: refetchStats } = useStats(); const [mail, setMail] = useMail(); const { addToQueue, deleteFromQueue } = useBackgroundQueue(); + const [, setFocusedIndex] = useAtom(focusedIndexAtom); + const [, setThreadId] = useQueryState('threadId'); + const [, setActiveReplyId] = useQueryState('activeReplyId'); const getCopyByDestination = (to?: MoveThreadOptions['destination']) => { switch (to) { @@ -59,6 +65,9 @@ const useMoveTo = () => { for (const threadId of threadIds) { addToQueue(threadId); } + setThreadId(null); + setActiveReplyId(null); + setFocusedIndex(null); return toast.promise(promise, { ...getCopyByDestination(destination), error: (error) => { @@ -68,10 +77,10 @@ const useMoveTo = () => { }, finally: async () => { setIsLoading(false); + await Promise.all([refetchThreads(), refetchStats()]); for (const threadId of threadIds) { deleteFromQueue(threadId); } - await Promise.all([refetchThreads(), refetchStats()]); setMail({ ...mail, bulkSelected: [],