solve mail backend 7
This commit is contained in:
parent
97068d5f6d
commit
69519dd8d1
@ -2,10 +2,18 @@ import { Mail } from '@/hooks/use-mail';
|
|||||||
|
|
||||||
interface MailListProps {
|
interface MailListProps {
|
||||||
mails: Mail[];
|
mails: Mail[];
|
||||||
onMailClick: (mail: Mail) => void;
|
onMailClick?: (mail: Mail) => void;
|
||||||
}
|
}
|
||||||
|
|
||||||
export const MailList = ({ mails, onMailClick }: MailListProps) => {
|
export const MailList = ({ mails = [], onMailClick }: MailListProps) => {
|
||||||
|
if (!mails || mails.length === 0) {
|
||||||
|
return (
|
||||||
|
<div className="flex items-center justify-center h-64">
|
||||||
|
<p className="text-gray-500">No emails found</p>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className="flex flex-col space-y-2">
|
<div className="flex flex-col space-y-2">
|
||||||
{mails.map((mail) => (
|
{mails.map((mail) => (
|
||||||
@ -14,7 +22,7 @@ export const MailList = ({ mails, onMailClick }: MailListProps) => {
|
|||||||
className={`p-4 border rounded-lg cursor-pointer hover:bg-gray-50 ${
|
className={`p-4 border rounded-lg cursor-pointer hover:bg-gray-50 ${
|
||||||
!mail.read ? 'font-semibold' : ''
|
!mail.read ? 'font-semibold' : ''
|
||||||
}`}
|
}`}
|
||||||
onClick={() => onMailClick(mail)}
|
onClick={() => onMailClick?.(mail)}
|
||||||
>
|
>
|
||||||
<div className="flex justify-between items-start">
|
<div className="flex justify-between items-start">
|
||||||
<div className="flex-1">
|
<div className="flex-1">
|
||||||
|
|||||||
@ -29,9 +29,10 @@ export const useMail = () => {
|
|||||||
throw new Error('Failed to fetch mails');
|
throw new Error('Failed to fetch mails');
|
||||||
}
|
}
|
||||||
const data = await response.json();
|
const data = await response.json();
|
||||||
setMails(data.emails);
|
setMails(data.emails || []);
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
setError(err instanceof Error ? err.message : 'Failed to fetch mails');
|
setError(err instanceof Error ? err.message : 'Failed to fetch mails');
|
||||||
|
setMails([]);
|
||||||
} finally {
|
} finally {
|
||||||
setIsLoading(false);
|
setIsLoading(false);
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user