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

+10 -2
View File
@@ -2,8 +2,16 @@ import { atom } from 'recoil';
import { IEmail } from '../../../common/typings/email';
export const emailState = {
emails: atom<IEmail[]>({
inbox: atom<IEmail[]>({
default: null,
key: 'EMAIL:emails',
key: 'EMAIL:inbox',
}),
sent: atom<IEmail[]>({
default: null,
key: 'EMAIL:sent',
}),
myEmail: atom<string>({
default: null,
key: 'EMAIL:myEmail',
}),
};
+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 };
};
+115 -78
View File
@@ -5,88 +5,125 @@ import { useNuiEvent } from '../../../os/nui-events/hooks/useNuiEvent';
import { emailState } from './state';
export const useEmailService = () => {
const setEmails = useSetRecoilState(emailState.emails);
const setInbox = useSetRecoilState(emailState.inbox);
const setSent = useSetRecoilState(emailState.sent);
const setMyEmail = useSetRecoilState(emailState.myEmail);
useNuiEvent('EMAIL', 'phone:fetchAllEmailsSuccess', setEmails);
useNuiEvent('EMAIL', 'phone:setMyEmail', setMyEmail);
useNuiEvent('EMAIL', 'phone:fetchAllSentEmailsSuccess', setSent);
useNuiEvent('EMAIL', 'phone:fetchAllEmailsSuccess', setInbox);
};
InjectDebugData<IEmail[]>([
InjectDebugData<string>([
{
app: 'EMAIL',
method: 'phone:fetchAllEmailsSuccess',
data: [
{
id: 1,
subject: 'Try this great app!',
body: 'Hey did you try this email app? Looking good bruh',
receivers: ['[email protected]'],
sender: '[email protected]',
sendDate: Date.now() / 1000,
isRead: false,
},
{
id: 2,
subject: 'Try this great app!',
body: 'Hey did you try this email app? Looking good bruh',
receivers: ['[email protected]'],
sender: '[email protected]',
sendDate: Date.now() / 1000,
isRead: false,
},
{
id: 3,
subject: 'Try this great app!',
body: 'Hey did you try this email app? Looking good bruh',
receivers: ['[email protected]'],
sender: '[email protected]',
sendDate: Date.now() / 1000,
isRead: true,
},
{
id: 4,
subject: 'Try this great app!',
body: 'Hey did you try this email app? Looking good bruh',
receivers: ['[email protected]'],
sender: '[email protected]',
sendDate: Date.now() / 1000,
isRead: true,
},
{
id: 5,
subject: 'Try this great app!',
body: 'Hey did you try this email app? Looking good bruh',
receivers: ['[email protected]'],
sender: '[email protected]',
sendDate: Date.now() / 1000,
isRead: true,
},
{
id: 6,
subject: 'Try this great app!',
body: 'Hey did you try this email app? Looking good bruh',
receivers: ['[email protected]'],
sender: '[email protected]',
sendDate: Date.now() / 1000,
isRead: false,
},
{
id: 7,
subject: 'Try this great app!',
body: 'Hey did you try this email app? Looking good bruh',
receivers: ['[email protected]'],
sender: '[email protected]',
sendDate: Date.now() / 1000,
isRead: false,
},
{
id: 8,
subject: 'Try this great app!',
body: 'Hey did you try this email app? Looking good bruh',
receivers: ['[email protected]'],
sender: '[email protected]',
sendDate: Date.now() / 1000,
isRead: false,
},
],
method: 'phone:setMyEmail',
data: '[email protected]',
},
]);
InjectDebugData<IEmail[]>(
[
{
app: 'EMAIL',
method: 'phone:fetchAllSentEmailsSuccess',
data: [
{
id: 1,
subject: 'Hey!',
body: 'Hey did you try this email app? Looking good bruh',
receivers: ['[email protected]'],
sender: '[email protected]',
sendDate: Date.now() / 1000,
},
{
id: 2,
subject: 'What is up?',
body: 'Hey did you try this email app? Looking good bruh',
receivers: ['[email protected]'],
sender: '[email protected]',
sendDate: Date.now() / 1000,
},
],
},
{
app: 'EMAIL',
method: 'phone:fetchAllEmailsSuccess',
data: [
{
id: 1,
subject: 'Try this great app!',
body: 'Hey did you try this email app? Looking good bruh',
receivers: ['[email protected]'],
sender: '[email protected]',
sendDate: Date.now() / 1000,
isRead: false,
},
{
id: 2,
subject: 'Try this great app!',
body: 'Hey did you try this email app? Looking good bruh',
receivers: ['[email protected]'],
sender: '[email protected]',
sendDate: Date.now() / 1000,
isRead: false,
},
{
id: 3,
subject: 'Try this great app!',
body: 'Hey did you try this email app? Looking good bruh',
receivers: ['[email protected]'],
sender: '[email protected]',
sendDate: Date.now() / 1000,
isRead: true,
},
{
id: 4,
subject: 'Try this great app!',
body: 'Hey did you try this email app? Looking good bruh',
receivers: ['[email protected]'],
sender: '[email protected]',
sendDate: Date.now() / 1000,
isRead: true,
},
{
id: 5,
subject: 'Try this great app!',
body: 'Hey did you try this email app? Looking good bruh',
receivers: ['[email protected]'],
sender: '[email protected]',
sendDate: Date.now() / 1000,
isRead: true,
},
{
id: 6,
subject: 'Try this great app!',
body: 'Hey did you try this email app? Looking good bruh',
receivers: ['[email protected]'],
sender: '[email protected]',
sendDate: Date.now() / 1000,
isRead: false,
},
{
id: 7,
subject: 'Try this great app!',
body: 'Hey did you try this email app? Looking good bruh',
receivers: ['[email protected]'],
sender: '[email protected]',
sendDate: Date.now() / 1000,
isRead: false,
},
{
id: 8,
subject: 'Try this great app!',
body: 'Hey did you try this email app? Looking good bruh',
receivers: ['[email protected]'],
sender: '[email protected]',
sendDate: Date.now() / 1000,
isRead: false,
},
],
},
],
2500,
);