Email app upgrades WIP

This commit is contained in:
J Francisco Rader committed 2021-03-30 02:07:04 -03:00
1 parent c2510266f8
commit ff4381fa01
12 files changed
+272 -132

No files matched your search

+12 -2
View File
@@ -1,8 +1,18 @@
import { useMemo } from 'react';
import { useRecoilValue } from 'recoil';
import { IEmail } from '../../../common/typings/email';
import { emailState } from './state';
export const useEmail = () => {
const emails = useRecoilValue(emailState.emails);
const inbox = useRecoilValue(emailState.inbox);
const sent = useRecoilValue(emailState.sent);
const myEmail = useRecoilValue(emailState.myEmail);
return { emails };
const allEmails = useMemo(() => [...(sent || []), ...(inbox || [])], [inbox, sent]);
const isMine = (email: IEmail) => email.sender === myEmail;
const getEmailById = (id: number) => allEmails.find((e) => e.id === id) || null;
return { inbox, sent, myEmail, isMine, getEmailById };
};