mirror of
https://github.com/darksaid98/new-phone-who-dis.git
synced 2026-12-04 22:16:40 +00:00
WIP :D
This commit is contained in:
1 parent
ff4381fa01
commit
a97d858f99
21 files changed
+659
-161
No files matched your search
@@ -2,6 +2,14 @@ import { atom } from 'recoil';
|
||||
import { IEmail } from '../../../common/typings/email';
|
||||
|
||||
export const emailState = {
|
||||
search: atom<IEmail[]>({
|
||||
default: null,
|
||||
key: 'EMAIL:search',
|
||||
}),
|
||||
searchTerm: atom<string>({
|
||||
default: null,
|
||||
key: 'EMAIL:searchTerm',
|
||||
}),
|
||||
inbox: atom<IEmail[]>({
|
||||
default: null,
|
||||
key: 'EMAIL:inbox',
|
||||
|
||||
@@ -1,18 +1,32 @@
|
||||
import { useMemo } from 'react';
|
||||
import { useRecoilValue } from 'recoil';
|
||||
import { IEmail } from '../../../common/typings/email';
|
||||
import { useCallback, useMemo } from 'react';
|
||||
import { useRecoilState, useRecoilValue } from 'recoil';
|
||||
import { IEmailMessage } from '../../../common/typings/email';
|
||||
import { useNuiEventCallback } from '../../../os/nui-events/hooks/useNuiEventCallback';
|
||||
import { emailState } from './state';
|
||||
|
||||
export const useEmail = () => {
|
||||
const inbox = useRecoilValue(emailState.inbox);
|
||||
const sent = useRecoilValue(emailState.sent);
|
||||
const [inbox, setInbox] = useRecoilState(emailState.inbox);
|
||||
const [sent, setSent] = useRecoilState(emailState.sent);
|
||||
const myEmail = useRecoilValue(emailState.myEmail);
|
||||
|
||||
const [fetchInbox, { loading: inboxLoading }] = useNuiEventCallback(
|
||||
'EMAIL',
|
||||
'phone:fetchEmails',
|
||||
setInbox,
|
||||
);
|
||||
const [fetchSent, { loading: sentLoading }] = useNuiEventCallback(
|
||||
'EMAIL',
|
||||
'phone:fetchSentEmails',
|
||||
setSent,
|
||||
);
|
||||
|
||||
const loading = inboxLoading || sentLoading;
|
||||
const allEmails = useMemo(() => [...(sent || []), ...(inbox || [])], [inbox, sent]);
|
||||
|
||||
const isMine = (email: IEmail) => email.sender === myEmail;
|
||||
const head = useCallback((arr: IEmailMessage[]): IEmailMessage => arr && arr[0], []);
|
||||
const getEmailById = useCallback((id: number) => allEmails.find((e) => e.id === id) || null, [
|
||||
allEmails,
|
||||
]);
|
||||
|
||||
const getEmailById = (id: number) => allEmails.find((e) => e.id === id) || null;
|
||||
|
||||
return { inbox, sent, myEmail, isMine, getEmailById };
|
||||
return { inbox, sent, myEmail, getEmailById, head, fetchSent, fetchInbox, loading };
|
||||
};
|
||||
@@ -5,13 +5,9 @@ import { useNuiEvent } from '../../../os/nui-events/hooks/useNuiEvent';
|
||||
import { emailState } from './state';
|
||||
|
||||
export const useEmailService = () => {
|
||||
const setInbox = useSetRecoilState(emailState.inbox);
|
||||
const setSent = useSetRecoilState(emailState.sent);
|
||||
const setMyEmail = useSetRecoilState(emailState.myEmail);
|
||||
|
||||
useNuiEvent('EMAIL', 'phone:setMyEmail', setMyEmail);
|
||||
useNuiEvent('EMAIL', 'phone:fetchAllSentEmailsSuccess', setSent);
|
||||
useNuiEvent('EMAIL', 'phone:fetchAllEmailsSuccess', setInbox);
|
||||
};
|
||||
|
||||
InjectDebugData<string>([
|
||||
@@ -26,104 +22,190 @@ InjectDebugData<IEmail[]>(
|
||||
[
|
||||
{
|
||||
app: 'EMAIL',
|
||||
method: 'phone:fetchAllSentEmailsSuccess',
|
||||
method: 'phone:fetchSentEmailsSuccess',
|
||||
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,
|
||||
messages: [
|
||||
{
|
||||
id: 1,
|
||||
emailId: 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,
|
||||
messages: [
|
||||
{
|
||||
id: 2,
|
||||
emailId: 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',
|
||||
method: 'phone:fetchEmailsSuccess',
|
||||
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,
|
||||
messages: [
|
||||
{
|
||||
id: 11,
|
||||
parentId: 12,
|
||||
emailId: 3,
|
||||
subject: 'Try this great app! 1',
|
||||
body: 'Hey did you try this email app? Looking good bruh',
|
||||
receivers: ['[email protected]'],
|
||||
sender: '[email protected]',
|
||||
sendDate: Date.now() / 1000,
|
||||
isRead: false,
|
||||
isMine: true,
|
||||
},
|
||||
{
|
||||
id: 12,
|
||||
parentId: 3,
|
||||
emailId: 3,
|
||||
subject: 'Try this great app! 2',
|
||||
body: 'Hey did you try this email app? Looking good bruh',
|
||||
receivers: ['[email protected]'],
|
||||
sender: '[email protected]',
|
||||
sendDate: Date.now() / 1000,
|
||||
isRead: false,
|
||||
isMine: false,
|
||||
},
|
||||
{
|
||||
id: 3,
|
||||
parentId: null,
|
||||
emailId: 3,
|
||||
subject: 'Try this great app! 3',
|
||||
body: 'Hey did you try this email app? Looking good bruh',
|
||||
receivers: ['[email protected]'],
|
||||
sender: '[email protected]',
|
||||
sendDate: Date.now() / 1000,
|
||||
isRead: false,
|
||||
isMine: 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,
|
||||
messages: [
|
||||
{
|
||||
id: 4,
|
||||
emailId: 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: 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,
|
||||
messages: [
|
||||
{
|
||||
id: 5,
|
||||
emailId: 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,
|
||||
messages: [
|
||||
{
|
||||
id: 6,
|
||||
emailId: 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: true,
|
||||
},
|
||||
],
|
||||
},
|
||||
{
|
||||
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,
|
||||
messages: [
|
||||
{
|
||||
id: 7,
|
||||
emailId: 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: true,
|
||||
},
|
||||
],
|
||||
},
|
||||
{
|
||||
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,
|
||||
messages: [
|
||||
{
|
||||
id: 8,
|
||||
emailId: 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,
|
||||
},
|
||||
],
|
||||
},
|
||||
{
|
||||
id: 9,
|
||||
messages: [
|
||||
{
|
||||
id: 9,
|
||||
emailId: 9,
|
||||
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: 10,
|
||||
messages: [
|
||||
{
|
||||
id: 10,
|
||||
emailId: 10,
|
||||
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,
|
||||
4000,
|
||||
);
|
||||
Reference in new issue
Block a user