mirror of
https://github.com/rustmailer/bichon.git
synced 2026-08-03 07:48:34 +02:00
feat: add attachment search view
This commit is contained in:
@@ -0,0 +1,26 @@
|
||||
import { useMemo } from 'react';
|
||||
import { useQuery } from '@tanstack/react-query';
|
||||
import { get_attachment_senders } from '@/api/attachment/api';
|
||||
|
||||
export const userAttachmentSenders = (searchTerm: string = "") => {
|
||||
const { data: senders = [], isLoading, isError } = useQuery({
|
||||
queryKey: ['attachment-senders', 'all'],
|
||||
queryFn: get_attachment_senders,
|
||||
staleTime: 1000 * 60 * 10,
|
||||
gcTime: 1000 * 60 * 30,
|
||||
});
|
||||
|
||||
const filtered = useMemo(() => {
|
||||
if (!searchTerm) return senders;
|
||||
const lower = searchTerm.toLowerCase();
|
||||
return senders.filter(email =>
|
||||
email.toLowerCase().includes(lower)
|
||||
);
|
||||
}, [senders, searchTerm]);
|
||||
|
||||
return {
|
||||
senders: filtered,
|
||||
isLoading,
|
||||
isError
|
||||
};
|
||||
};
|
||||
Reference in New Issue
Block a user