Files
Zero/apps/mail/hooks/driver/use-delete.ts
Adam 277f476575 cleanup on isle zero (#1699)
Ran oxc (https://oxc.rs/docs/guide/usage/linter.html#vscode-extension) and fixed all the issues that came up, set it up to run as a PR check and added steps to the README.md asking users to use it.

<!-- This is an auto-generated comment: release notes by coderabbit.ai -->
## Summary by CodeRabbit

* **New Features**
  * Introduced JavaScript linting using oxlint in development guidelines and CI workflow for improved code quality.
  * Added oxlint configuration and dependencies to the project.

* **Bug Fixes**
  * Improved error logging in various components and utilities for better debugging.
  * Enhanced React list rendering by updating keys to use unique values instead of array indices, reducing rendering issues.
  * Replaced browser alerts with toast notifications for a smoother user experience.

* **Refactor**
  * Simplified component logic and state management by removing unused code, imports, props, and components across multiple files.
  * Updated function and component signatures for clarity and maintainability.
  * Improved efficiency of certain operations by switching from arrays to sets for membership checks.

* **Chores**
  * Cleaned up and reorganized import statements throughout the codebase.
  * Removed deprecated files, components, and middleware to streamline the codebase.

* **Documentation**
  * Updated contribution guidelines to include linting requirements for code submissions.

* **Style**
  * Minor formatting and readability improvements in JSX and code structure.
<!-- end of auto-generated comment: release notes by coderabbit.ai -->
2025-07-10 10:59:40 -07:00

52 lines
1.6 KiB
TypeScript

import useBackgroundQueue from '@/hooks/ui/use-background-queue';
import { useMail } from '@/components/mail/use-mail';
import { useTRPC } from '@/providers/query-provider';
import { useMutation } from '@tanstack/react-query';
import { useThreads } from '@/hooks/use-threads';
import { useStats } from '@/hooks/use-stats';
import { m } from '@/paraglide/messages';
import { useState } from 'react';
import { toast } from 'sonner';
const useDelete = () => {
const [isLoading, setIsLoading] = useState(false);
const [mail, setMail] = useMail();
const [{ refetch: refetchThreads }] = useThreads();
const { refetch: refetchStats } = useStats();
const { addToQueue, } = useBackgroundQueue();
const trpc = useTRPC();
const { mutateAsync: deleteThread } = useMutation(trpc.mail.delete.mutationOptions());
return {
mutate: (id: string, type: 'thread' | 'email' = 'thread') => {
setIsLoading(true);
addToQueue(id);
return toast.promise(
deleteThread({
id,
}),
{
loading: m['common.actions.deletingMail'](),
success: m['common.actions.deletedMail'](),
error: (error) => {
console.error(`Error deleting ${type}:`, error);
return m['common.actions.failedToDeleteMail']();
},
finally: async () => {
setMail({
...mail,
bulkSelected: [],
});
setIsLoading(false);
await Promise.all([refetchThreads(), refetchStats()]);
},
},
);
},
isLoading,
};
};
export default useDelete;