mirror of
https://github.com/Mail-0/Zero.git
synced 2026-07-01 08:16:28 +00:00
feat: enhance useMoveTo hook with focused index and query state management
This commit is contained in:
@@ -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: [],
|
||||
|
||||
Reference in New Issue
Block a user