Files
Zero/apps/mail/hooks/ui/use-background-queue.ts
Dak Washbrook af669b403a Add reusable hooks for email deletion and movement logic
Introduced `useDelete` and `useMoveTo` hooks to centralize deletion and movement logic for emails and threads. These hooks improve code reusability, streamline background queue handling, and enhance folder-specific actions like moving to bin or spam.
2025-05-01 00:20:47 -07:00

24 lines
723 B
TypeScript

import { backgroundQueueAtom } from '@/store/backgroundQueue';
import { useAtom } from 'jotai';
const useBackgroundQueue = () => {
const [backgroundQueue, setBackgroundQueue] = useAtom(backgroundQueueAtom);
return {
addToQueue: (threadId: string) =>
setBackgroundQueue({
type: 'add',
threadId: threadId.startsWith('thread:') ? threadId : `thread:${threadId}`,
}),
deleteFromQueue: (threadId: string) =>
setBackgroundQueue({
type: 'delete',
threadId: threadId.startsWith('thread:') ? threadId : `thread:${threadId}`,
}),
clearQueue: () => setBackgroundQueue({ type: 'clear' }),
queue: backgroundQueue,
};
};
export default useBackgroundQueue;