mirror of
https://github.com/darksaid98/new-phone-who-dis.git
synced 2026-12-04 06:28:51 +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,13 +2,13 @@ import React from 'react';
|
||||
import { AppWrapper } from '../../../ui/components';
|
||||
import { AppContent } from '../../../ui/components/AppContent';
|
||||
import { EmailThemeProvider } from '../providers/EmailThemeProvider';
|
||||
import EmailNavBar from './EmailNavBar';
|
||||
import { EmailAppNav } from './EmailAppNav';
|
||||
import { Route, Switch } from 'react-router-dom';
|
||||
import { InboxPage } from './InboxPage';
|
||||
import { InboxPage } from './pages/InboxPage';
|
||||
import { EmailAppHeader } from './EmailAppHeader';
|
||||
import { NewEmailPage } from './NewEmailPage';
|
||||
import { SentPage } from './SentPage';
|
||||
import { EmailDetails } from './EmailDetails';
|
||||
import { NewEmailPage } from './pages/NewEmailPage';
|
||||
import { SentPage } from './pages/SentPage';
|
||||
import { EmailDetailsPage } from './pages/EmailDetailsPage';
|
||||
|
||||
export const EmailApp = () => {
|
||||
return (
|
||||
@@ -27,11 +27,11 @@ export const EmailApp = () => {
|
||||
<NewEmailPage />
|
||||
</Route>
|
||||
<Route path="/email/details/:id">
|
||||
<EmailDetails />
|
||||
<EmailDetailsPage />
|
||||
</Route>
|
||||
</Switch>
|
||||
</AppContent>
|
||||
<EmailNavBar />
|
||||
<EmailAppNav />
|
||||
</AppWrapper>
|
||||
</EmailThemeProvider>
|
||||
);
|
||||
|
||||
+1
-3
@@ -19,7 +19,7 @@ const useStyles = makeStyles((theme: Theme) => ({
|
||||
},
|
||||
}));
|
||||
|
||||
const EmailNavBar = () => {
|
||||
export const EmailAppNav = () => {
|
||||
const classes = useStyles();
|
||||
const { pathname } = useLocation();
|
||||
const [page, setPage] = useState(pathname);
|
||||
@@ -58,5 +58,3 @@ const EmailNavBar = () => {
|
||||
</BottomNavigation>
|
||||
);
|
||||
};
|
||||
|
||||
export default EmailNavBar;
|
||||
@@ -1,43 +0,0 @@
|
||||
import { Box, Card, CardContent, CardHeader, Container } from '@material-ui/core';
|
||||
import React from 'react';
|
||||
import { useTranslation } from 'react-i18next';
|
||||
import { useParams } from 'react-router';
|
||||
import { useEmail } from '../hooks/useEmail';
|
||||
|
||||
export const EmailDetails = () => {
|
||||
const { t } = useTranslation();
|
||||
const { id } = useParams<{ id: string }>();
|
||||
const { getEmailById } = useEmail();
|
||||
|
||||
const email = getEmailById(Number(id));
|
||||
|
||||
if (!email) {
|
||||
return (
|
||||
<Box width="100%" textAlign="center">
|
||||
404
|
||||
</Box>
|
||||
);
|
||||
}
|
||||
|
||||
return (
|
||||
<Container>
|
||||
<Card>
|
||||
<CardContent>
|
||||
{t('GENERIC_FROM')}: <i>{email.sender}</i>
|
||||
</CardContent>
|
||||
<CardContent>
|
||||
{t('GENERIC_TO')}: <i>{email.receivers.join(', ')}</i>
|
||||
</CardContent>
|
||||
|
||||
<CardContent>
|
||||
{t('APPS_EMAIL_SUBJECT')}: <i>{email.subject || '( - )'}</i>
|
||||
</CardContent>
|
||||
</Card>
|
||||
<Box mt={2}>
|
||||
<Card>
|
||||
<CardContent>{email.body}</CardContent>
|
||||
</Card>
|
||||
</Box>
|
||||
</Container>
|
||||
);
|
||||
};
|
||||
@@ -0,0 +1,78 @@
|
||||
import { Box, Button, CircularProgress, makeStyles } from '@material-ui/core';
|
||||
import LeftIcon from '@material-ui/icons/ChevronLeft';
|
||||
import RightIcon from '@material-ui/icons/ChevronRight';
|
||||
import React, { useEffect, useState } from 'react';
|
||||
import { useParams } from 'react-router';
|
||||
import { IEmailMessage } from '../../../../common/typings/email';
|
||||
import { useEmail } from '../../hooks/useEmail';
|
||||
import { EmailMessage } from '../shared/EmailMessage';
|
||||
|
||||
const useStyles = makeStyles((theme) => ({
|
||||
search: {
|
||||
zIndex: 5,
|
||||
position: 'absolute',
|
||||
backgroundColor: theme.palette.primary.light,
|
||||
top: 0,
|
||||
},
|
||||
}));
|
||||
|
||||
export const EmailDetailsPage = () => {
|
||||
const classes = useStyles();
|
||||
const { id } = useParams<{ id: string }>();
|
||||
const { getEmailById, head } = useEmail();
|
||||
const email = getEmailById(Number(id));
|
||||
const [currMessage, setCurrMessage] = useState<number>(0);
|
||||
const [message, setMessage] = useState<IEmailMessage>(null);
|
||||
|
||||
useEffect(() => {
|
||||
if (!message && email) {
|
||||
if (head(email.messages)) {
|
||||
return;
|
||||
}
|
||||
setCurrMessage(0);
|
||||
}
|
||||
}, [email, head, message]);
|
||||
|
||||
useEffect(() => {
|
||||
if (email) {
|
||||
setMessage(email.messages[currMessage]);
|
||||
}
|
||||
}, [currMessage, email, message]);
|
||||
|
||||
const disableNextPage = currMessage === email?.messages.length - 1;
|
||||
const disablePrevPage = currMessage === 0;
|
||||
|
||||
return (
|
||||
<Box height="100%" pt="80px" position="relative">
|
||||
<Box width="100%" p={2} className={classes.search}>
|
||||
<Box width="100%" display="flex" justifyContent="space-between">
|
||||
<Button
|
||||
fullWidth
|
||||
startIcon={<LeftIcon />}
|
||||
color="primary"
|
||||
onClick={() => setCurrMessage((curr) => curr + 1)}
|
||||
disabled={disableNextPage}
|
||||
>
|
||||
Previous
|
||||
</Button>
|
||||
<Button
|
||||
fullWidth
|
||||
endIcon={<RightIcon />}
|
||||
color="primary"
|
||||
onClick={() => setCurrMessage((curr) => curr - 1)}
|
||||
disabled={disablePrevPage}
|
||||
>
|
||||
Newest
|
||||
</Button>
|
||||
</Box>
|
||||
</Box>
|
||||
{!message || !email ? (
|
||||
<Box width="100%" height="100%" display="flex" alignItems="center" justifyContent="center">
|
||||
<CircularProgress color="primary" />
|
||||
</Box>
|
||||
) : (
|
||||
<EmailMessage message={message} />
|
||||
)}
|
||||
</Box>
|
||||
);
|
||||
};
|
||||
+20
-9
@@ -1,8 +1,8 @@
|
||||
import React, { useState } from 'react';
|
||||
import { Box, makeStyles, TextField } from '@material-ui/core';
|
||||
import { useQueryParams } from '../../../common/hooks/useQueryParams';
|
||||
import { useEmail } from '../hooks/useEmail';
|
||||
import { EmailList } from './EmailList';
|
||||
import React, { useEffect, useState } from 'react';
|
||||
import { Box, CircularProgress, makeStyles, TextField } from '@material-ui/core';
|
||||
import { useQueryParams } from '../../../../common/hooks/useQueryParams';
|
||||
import { useEmail } from '../../hooks/useEmail';
|
||||
import { EmailList } from '../shared/EmailList';
|
||||
|
||||
const useStyles = makeStyles((theme) => ({
|
||||
search: {
|
||||
@@ -16,14 +16,19 @@ const useStyles = makeStyles((theme) => ({
|
||||
export const InboxPage = () => {
|
||||
const classes = useStyles();
|
||||
|
||||
const { inbox } = useEmail();
|
||||
const { inbox, fetchInbox, loading } = useEmail();
|
||||
const { autoSearch } = useQueryParams<{ autoSearch }>();
|
||||
|
||||
const [search, setSearch] = useState<string>('');
|
||||
|
||||
useEffect(() => {
|
||||
fetchInbox();
|
||||
}, [fetchInbox]);
|
||||
|
||||
const handleSearch = (e) => {
|
||||
setSearch(e.target.value);
|
||||
};
|
||||
|
||||
return (
|
||||
<Box height="100%" pt="80px" position="relative">
|
||||
<Box width="100%" p={2} className={classes.search}>
|
||||
@@ -36,9 +41,15 @@ export const InboxPage = () => {
|
||||
value={search}
|
||||
/>
|
||||
</Box>
|
||||
<Box overflow="auto" maxHeight="100%">
|
||||
<EmailList emails={inbox} />
|
||||
</Box>
|
||||
{!inbox && loading ? (
|
||||
<Box width="100%" height="100%" display="flex" alignItems="center" justifyContent="center">
|
||||
<CircularProgress color="primary" />
|
||||
</Box>
|
||||
) : (
|
||||
<Box overflow="auto" maxHeight="100%">
|
||||
<EmailList emails={inbox} />
|
||||
</Box>
|
||||
)}
|
||||
</Box>
|
||||
);
|
||||
};
|
||||
File renamed without changes.
+2
-2
@@ -1,7 +1,7 @@
|
||||
import React from 'react';
|
||||
import { Box } from '@material-ui/core';
|
||||
import { useEmail } from '../hooks/useEmail';
|
||||
import { EmailList } from './EmailList';
|
||||
import { useEmail } from '../../hooks/useEmail';
|
||||
import { EmailList } from '../shared/EmailList';
|
||||
|
||||
export const SentPage = () => {
|
||||
const { sent } = useEmail();
|
||||
+4
-2
@@ -1,5 +1,5 @@
|
||||
import React from 'react';
|
||||
import { IEmail } from '../../../common/typings/email';
|
||||
import { IEmail } from '../../../../common/typings/email';
|
||||
import { EmailListItem } from './EmailListItem';
|
||||
import { List } from '@material-ui/core';
|
||||
|
||||
@@ -8,5 +8,7 @@ interface IProps {
|
||||
}
|
||||
|
||||
export const EmailList = ({ emails }: IProps) => {
|
||||
return <List>{emails && emails.map((email) => <EmailListItem email={email} />)}</List>;
|
||||
return (
|
||||
<List>{emails && emails.map((email) => <EmailListItem key={email.id} email={email} />)}</List>
|
||||
);
|
||||
};
|
||||
+15
-10
@@ -11,32 +11,37 @@ import dayjs from 'dayjs';
|
||||
import { useTranslation } from 'react-i18next';
|
||||
import MarkRead from '@material-ui/icons/Markunread';
|
||||
import MarkUnread from '@material-ui/icons/MarkunreadMailbox';
|
||||
import { useEmail } from '../hooks/useEmail';
|
||||
import { IEmail } from '../../../common/typings/email';
|
||||
import { IEmail } from '../../../../common/typings/email';
|
||||
import { useHistory } from 'react-router';
|
||||
import { useEmail } from '../../hooks/useEmail';
|
||||
|
||||
export const EmailListItem = ({ email }: { email: IEmail }) => {
|
||||
const { t } = useTranslation();
|
||||
const { isMine } = useEmail();
|
||||
const { head } = useEmail();
|
||||
const history = useHistory();
|
||||
|
||||
const sendDate = dayjs.unix(email.sendDate).format(t('DATE_FORMAT'));
|
||||
const read = email.isRead === true;
|
||||
const mine = isMine(email);
|
||||
const highlight = !mine && !read;
|
||||
const latestMessage = head(email.messages);
|
||||
|
||||
const sendDate = dayjs.unix(latestMessage.sendDate).format(t('DATE_FORMAT'));
|
||||
const read = latestMessage.isRead === true;
|
||||
const mine = latestMessage.isMine === true;
|
||||
const highlight = !mine && !read;
|
||||
return (
|
||||
<ListItem
|
||||
button
|
||||
divider
|
||||
key={email.id}
|
||||
key={latestMessage.id}
|
||||
onClick={() => history.push(`/email/details/${email.id}`)}
|
||||
>
|
||||
<ListItemAvatar>
|
||||
<Avatar>{email.sender.charAt(0).toUpperCase()}</Avatar>
|
||||
<Avatar>{latestMessage.sender.charAt(0).toUpperCase()}</Avatar>
|
||||
</ListItemAvatar>
|
||||
<ListItemText secondary={highlight ? <strong>{sendDate}</strong> : <span>{sendDate}</span>}>
|
||||
{highlight ? <strong>{email.subject}</strong> : <span>{email.subject}</span>}
|
||||
{highlight ? (
|
||||
<strong>{latestMessage.subject}</strong>
|
||||
) : (
|
||||
<span>{latestMessage.subject}</span>
|
||||
)}
|
||||
</ListItemText>
|
||||
<ListItemSecondaryAction>
|
||||
{!mine && (
|
||||
@@ -0,0 +1,29 @@
|
||||
import { Box, Card, CardContent } from '@material-ui/core';
|
||||
import React from 'react';
|
||||
import { useTranslation } from 'react-i18next';
|
||||
import { IEmailMessage } from '../../../../common/typings/email';
|
||||
|
||||
export const EmailMessage = ({ message }: { message: IEmailMessage }) => {
|
||||
const { t } = useTranslation();
|
||||
return (
|
||||
<Box px={2}>
|
||||
<Card>
|
||||
<CardContent>
|
||||
{t('GENERIC_FROM')}: <i>{message.sender}</i>
|
||||
</CardContent>
|
||||
<CardContent>
|
||||
{t('GENERIC_TO')}: <i>{message.receivers.join(', ')}</i>
|
||||
</CardContent>
|
||||
|
||||
<CardContent>
|
||||
{t('APPS_EMAIL_SUBJECT')}: <i>{message.subject || '( - )'}</i>
|
||||
</CardContent>
|
||||
</Card>
|
||||
<Box mt={2}>
|
||||
<Card>
|
||||
<CardContent>{message.body}</CardContent>
|
||||
</Card>
|
||||
</Box>
|
||||
</Box>
|
||||
);
|
||||
};
|
||||
@@ -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,
|
||||
);
|
||||
@@ -8,14 +8,22 @@ export interface IEmailExternalAction {
|
||||
closePhone?: boolean;
|
||||
}
|
||||
|
||||
export interface IEmail {
|
||||
export interface IEmailMessage {
|
||||
id: number;
|
||||
parentId?: number | null;
|
||||
emailId: number;
|
||||
isRead?: boolean;
|
||||
isMine?: boolean;
|
||||
receivers: string[];
|
||||
sender: string;
|
||||
sendDate: number;
|
||||
subject: string;
|
||||
body: string;
|
||||
}
|
||||
|
||||
export interface IEmail {
|
||||
id: number;
|
||||
messages: IEmailMessage[];
|
||||
phoneActions?: Array<IEmailPhoneAction>;
|
||||
externalActions?: Array<IEmailExternalAction>;
|
||||
}
|
||||
@@ -0,0 +1,85 @@
|
||||
import { useCallback, useRef, useState } from 'react';
|
||||
|
||||
interface IAbortableFetch {
|
||||
abort: () => void;
|
||||
ready: Promise<Response>;
|
||||
}
|
||||
|
||||
function abortableFetch(request, opts): IAbortableFetch {
|
||||
const controller = new AbortController();
|
||||
const signal = controller.signal;
|
||||
|
||||
return {
|
||||
abort: () => controller.abort(),
|
||||
ready: fetch(request, { ...opts, signal }),
|
||||
};
|
||||
}
|
||||
|
||||
export type FetchData = Record<string, any> | boolean | null | undefined | string | number;
|
||||
|
||||
type UseNuiFetchResponse<I, R> = [
|
||||
(data?: I) => void,
|
||||
{ response: R; error: Error | unknown; loading: boolean },
|
||||
];
|
||||
|
||||
const DEFAULT_HANDLER = () => {};
|
||||
|
||||
export function useNuiFetch<I = FetchData, R = FetchData>(
|
||||
event: string,
|
||||
handler: (d?: R) => void = DEFAULT_HANDLER,
|
||||
): UseNuiFetchResponse<I, R> {
|
||||
const [loading, setLoading] = useState<boolean>(false);
|
||||
const [error, setError] = useState<Error | unknown>(null);
|
||||
const [response, setResponse] = useState<R>(null);
|
||||
const fetching = useRef<IAbortableFetch>();
|
||||
|
||||
const onFetch = useCallback(
|
||||
(input?: I): Promise<R> => {
|
||||
return new Promise((resolve, reject) => {
|
||||
setLoading(true);
|
||||
try {
|
||||
if (fetching.current && fetching.current.abort) {
|
||||
fetching.current.abort();
|
||||
fetching.current = undefined;
|
||||
setError(null);
|
||||
setResponse(null);
|
||||
}
|
||||
const body = JSON.stringify(input);
|
||||
const opt = {
|
||||
method: 'post',
|
||||
headers: {
|
||||
'Content-Type': 'application/json; charset=UTF-8',
|
||||
},
|
||||
body,
|
||||
};
|
||||
const req = abortableFetch(`https://new-phone-who-dis/${event}`, opt);
|
||||
fetching.current = req;
|
||||
req.ready
|
||||
.then((r) => {
|
||||
const res = r.json() as unknown;
|
||||
setResponse(res as R);
|
||||
handler?.(res as R);
|
||||
resolve(res as R);
|
||||
setError(null);
|
||||
})
|
||||
.catch((e) => {
|
||||
setError(e);
|
||||
setResponse(null);
|
||||
reject(e);
|
||||
})
|
||||
.finally(() => {
|
||||
setLoading(false);
|
||||
});
|
||||
} catch (e) {
|
||||
setLoading(false);
|
||||
setError(e);
|
||||
setResponse(null);
|
||||
reject(e);
|
||||
}
|
||||
});
|
||||
},
|
||||
[event, handler],
|
||||
);
|
||||
|
||||
return [onFetch, { error, response, loading }];
|
||||
}
|
||||
@@ -17,11 +17,11 @@ export const getSoundSettings = (
|
||||
try {
|
||||
return app
|
||||
? {
|
||||
sound: getPath[type](settings[`${app}_${type}`]?.value || settings[type].value),
|
||||
sound: getPath[type](settings[`${app}_${type}`]?.value || settings[type]?.value),
|
||||
volume: (settings[`${app}_${type}Vol`] || settings[`${type}Vol`]) / 100,
|
||||
}
|
||||
: {
|
||||
sound: getPath[type](settings[type as string].value),
|
||||
sound: getPath[type](settings[type as string]?.value),
|
||||
volume: settings[`${type}Vol`] / 100,
|
||||
};
|
||||
} catch (e) {
|
||||
|
||||
@@ -0,0 +1,4 @@
|
||||
import { ClUtils } from './client';
|
||||
import events from '../utils/events';
|
||||
|
||||
ClUtils.registerNuiServerCallback(events.EMAIL_FETCH_INBOX);
|
||||
@@ -8,7 +8,14 @@ interface ISettingsParams {
|
||||
promiseTimeout?: number;
|
||||
}
|
||||
|
||||
interface ICallback {
|
||||
cb: (err: any, data?: unknown) => void;
|
||||
timeout: NodeJS.Timeout;
|
||||
}
|
||||
|
||||
export default class ClientUtils {
|
||||
private readonly _callbacks = new Map<string, ICallback>();
|
||||
|
||||
private _settings: ISettings;
|
||||
private _defaultSettings: ISettings = {
|
||||
promiseTimeout: 5000,
|
||||
@@ -51,6 +58,55 @@ export default class ClientUtils {
|
||||
onNet(listenEventName, handleListenEvent);
|
||||
});
|
||||
}
|
||||
|
||||
public registerNuiServerCallback<I = any, R = any>(event: string) {
|
||||
RegisterNuiCallbackType(event);
|
||||
|
||||
const uid = uuidv4();
|
||||
const callbackId = `${event}:${uid}`;
|
||||
|
||||
on(`__cfx_nui:${event}`, (data: I, cb: (err: any, data?: R) => void) => {
|
||||
if (this._callbacks.has(callbackId)) {
|
||||
cb(new Error(`Nui Server Callback with name "${event}" is already waiting for server!`));
|
||||
return;
|
||||
}
|
||||
emitNet(event, data);
|
||||
|
||||
this._callbacks.set(callbackId, {
|
||||
cb,
|
||||
timeout: setTimeout(() => {
|
||||
if (this._callbacks.has(callbackId)) {
|
||||
this._callbacks
|
||||
.get(callbackId)
|
||||
.cb(
|
||||
new Error(
|
||||
`Nui Server Callback with name "${event}" timed out after ${this._settings.promiseTimeout}ms`,
|
||||
),
|
||||
);
|
||||
this._callbacks.delete(callbackId);
|
||||
}
|
||||
}, this._settings.promiseTimeout),
|
||||
});
|
||||
});
|
||||
|
||||
onNet(`${event}Success`, (response: R) => {
|
||||
if (this._callbacks.has(callbackId)) {
|
||||
const callback = this._callbacks.get(callbackId);
|
||||
clearTimeout(callback.timeout);
|
||||
callback.cb(null, response);
|
||||
this._callbacks.delete(callbackId);
|
||||
}
|
||||
});
|
||||
|
||||
onNet(`${event}Error`, (err: any) => {
|
||||
if (this._callbacks.has(callbackId)) {
|
||||
const callback = this._callbacks.get(callbackId);
|
||||
clearTimeout(callback.timeout);
|
||||
callback.cb(err);
|
||||
this._callbacks.delete(callbackId);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
export const NuiCallback = (event: string, callback: Function) => {
|
||||
|
||||
@@ -3,8 +3,6 @@ import { getIdentifier, getSource } from './functions';
|
||||
import { mainLogger } from './sv_logger';
|
||||
import { ContactEvents } from '../../typings/contact';
|
||||
|
||||
const contactsLogger = mainLogger.child({ module: 'contact' });
|
||||
|
||||
interface Contacts {
|
||||
id?: number;
|
||||
display: string;
|
||||
|
||||
@@ -0,0 +1,28 @@
|
||||
import events from '../utils/events';
|
||||
import { mainLogger } from './sv_logger';
|
||||
import { getSource } from './functions';
|
||||
import { pool } from './db';
|
||||
|
||||
const emailLogger = mainLogger.child({ module: 'contact' });
|
||||
|
||||
async function fetchInbox(email: string): Promise<any> {
|
||||
const query = `
|
||||
SELECT * FROM npwd_emails WHERE id = ?
|
||||
`;
|
||||
const result = await pool.query(query, [email]);
|
||||
return result[0];
|
||||
}
|
||||
|
||||
onNet(events.EMAIL_FETCH_INBOX, async () => {
|
||||
const _source = getSource();
|
||||
try {
|
||||
const email = '[email protected]';
|
||||
const inbox = await fetchInbox(email);
|
||||
emitNet(events.EMAIL_FETCH_INBOX_SUCCESS, inbox);
|
||||
} catch (e) {
|
||||
emailLogger.error(`Failed to fetch email inbox, ${e.message}`, {
|
||||
source: _source,
|
||||
});
|
||||
emitNet(events.EMAIL_FETCH_INBOX_ERROR, e);
|
||||
}
|
||||
});
|
||||
@@ -0,0 +1,135 @@
|
||||
export default {
|
||||
// Twitter
|
||||
TWITTER_FETCH_TWEETS: 'phone:fetchTweets',
|
||||
TWITTER_FETCH_TWEETS_SUCCESS: 'fetchTweets',
|
||||
TWITTER_FETCH_TWEETS_FAILURE: 'fetchTweetsFailed',
|
||||
TWITTER_FETCH_TWEETS_FILTERED: 'phone:fetchTweetsFiltered',
|
||||
TWITTER_FETCH_TWEETS_FILTERED_SUCCESS: 'fetchTweetsFiltered',
|
||||
TWITTER_FETCH_TWEETS_FILTERED_FAILURE: 'fetchTweetsFilteredFailed',
|
||||
TWITTER_GET_OR_CREATE_PROFILE: 'phone:getOrCreateTwitterProfile',
|
||||
TWITTER_GET_OR_CREATE_PROFILE_SUCCESS: 'getOrCreateTwitterProfile',
|
||||
TWITTER_GET_OR_CREATE_PROFILE_FAILURE: 'getOrCreateTwitterProfileFailed',
|
||||
TWITTER_UPDATE_PROFILE: 'phone:updateTwitterProfile',
|
||||
TWITTER_UPDATE_PROFILE_LOADING: 'updateProfileLoading',
|
||||
TWITTER_UPDATE_PROFILE_RESULT: 'updateProfileResult',
|
||||
TWITTER_CREATE_TWEET: 'phone:createTweet',
|
||||
TWITTER_CREATE_TWEET_LOADING: 'createTweetLoading',
|
||||
TWITTER_CREATE_TWEET_RESULT: 'createTweetResult',
|
||||
TWITTER_CREATE_TWEET_BROADCAST: 'createTweetBroadcast',
|
||||
TWITTER_CREATE_TWEET_FAILURE: 'createTweetResultFailed',
|
||||
TWITTER_DELETE_TWEET: 'phone:deleteTweet',
|
||||
TWITTER_DELETE_TWEET_SUCCESS: 'deleteTweetSuccess',
|
||||
TWITTER_DELETE_TWEET_FAILURE: 'deleteTweetFailed',
|
||||
TWITTER_TOGGLE_LIKE: 'phone:toggleLike',
|
||||
TWITTER_TOGGLE_LIKE_SUCCESS: 'toggleLikeSuccess',
|
||||
TWITTER_TOGGLE_LIKE_FAILURE: 'toggleLikeFailed',
|
||||
TWITTER_RETWEET: 'phone:retweet',
|
||||
TWITTER_RETWEET_SUCCESS: 'phone:retweetSuccess',
|
||||
TWITTER_RETWEET_EXISTS: 'phone:retweetExists',
|
||||
TWITTER_RETWEET_FAILURE: 'phone:retweetFailed',
|
||||
TWITTER_REPORT: 'phone:reportTweet',
|
||||
TWITTER_REPORT_SUCCESS: 'reportTweetSuccess',
|
||||
TWITTER_REPORT_FAILURE: 'reportTweetFailed',
|
||||
|
||||
// Contacts
|
||||
CONTACTS_SEND_CONTACTS: 'phone:sendContacts',
|
||||
CONTACTS_GET_CONTACTS: 'phone:getContacts',
|
||||
CONTACTS_ADD_CONTACT_NUI: 'contacts:add',
|
||||
CONTACTS_ADD_CONTACT: 'phone:addContacts',
|
||||
CONTACTS_ADD_CONTACT_SUCCESS: 'contacts:addSuccess',
|
||||
CONTACTS_UPDATE_CONTACT: 'phone:updateContact',
|
||||
CONTACTS_DELETE_CONTACT: 'phone:deleteContact',
|
||||
CONTACTS_DELETE_CONTACT_SUCCESS: 'contacts:deleteSuccess',
|
||||
CONTACTS_UPDATE_CONTACT_SUCCESS: 'phone:updateContactSuccess',
|
||||
CONTACTS_ACTION_RESULT: 'phone:contactActionResult',
|
||||
|
||||
// Sellout
|
||||
// these event keys needs to be changed to 'MARKETPLACE'
|
||||
SELLOUT_ADD_LISTING: 'phone:addListing',
|
||||
SELLOUT_ADD_LISTING_SUCCESS: 'phone:addListingSuccess',
|
||||
SELLOUT_FETCH_LISTING: 'phone:fetchAllListings',
|
||||
SELLOUT_SEND_LISTING: 'phone:sendAllListings',
|
||||
SELLOUT_ACTION_RESULT: 'phone:selloutActionResult',
|
||||
SELLOUT_DELETE_LISTING: 'phone:marketplaceDeleteListing',
|
||||
SELLOUT_DELETE_LISTING_SUCCESS: 'phone:marketplaceDeleteListingSuccess',
|
||||
SELLOUT_REPORT_LISTING: 'phone:reportListing',
|
||||
SELLOUT_REPORT_LISTING_SUCCESS: 'phone:reportListingSuccess',
|
||||
SELLOUT_REPORT_LISTING_SUCESS: 'phone:reportListingFailed',
|
||||
|
||||
//
|
||||
BANK_ADD_TRANSFER: 'phone:addTransfer',
|
||||
BANK_ADD_TRANSFER_SUCCESS: 'phone:addTransferSuccess',
|
||||
BANK_FETCH_TRANSACTIONS: 'phone:fetchAllTransactions',
|
||||
BANK_SEND_TRANSFERS: 'phone:sendTransfers',
|
||||
BANK_TRANSACTION_ALERT: 'phone:bankTransactionAlert',
|
||||
BANK_TRANSACTION_NOTIFICATION: 'phone:bankTransactionNotification',
|
||||
BANK_SEND_CREDENTIALS: 'phone:sendBankCredentials',
|
||||
BANK_GET_CREDENTIALS: 'phone:getBankCredentials',
|
||||
|
||||
//messages
|
||||
MESSAGES_FETCH_MESSAGE_GROUPS: 'phone:fetchMessageGroups',
|
||||
MESSAGES_FETCH_MESSAGE_GROUPS_SUCCESS: 'phone:fetchMessageGroupsSuccess',
|
||||
MESSAGES_FETCH_MESSAGE_GROUPS_FAILED: 'phone:fetchMessageGroupsFailed',
|
||||
MESSAGES_CREATE_MESSAGE_GROUP: 'phone:createMessageGroup',
|
||||
MESSAGES_CREATE_MESSAGE_GROUP_SUCCESS: 'phone:createMessageGroupSuccess',
|
||||
MESSAGES_CREATE_MESSAGE_GROUP_FAILED: 'phone:createMessageGroupFailed',
|
||||
MESSAGES_SEND_MESSAGE: 'phone:sendMessage',
|
||||
MESSAGES_SEND_MESSAGE_SUCCESS: 'phone:sendMessageSuccess',
|
||||
MESSAGES_SEND_MESSAGE_FAILED: 'phone:sendMessageFailed',
|
||||
MESSAGES_FETCH_MESSAGES: 'phone:fetchMessages',
|
||||
MESSAGES_FETCH_MESSAGES_SUCCESS: 'phone:fetchMessagesSuccess',
|
||||
MESSAGES_FETCH_MESSAGES_FAILED: 'phone:fetchMessagesFailed',
|
||||
MESSAGES_ACTION_RESULT: 'phone:setMessagesAlert',
|
||||
MESSAGES_CREATE_MESSAGE_BROADCAST: 'createMessagesBroadcast',
|
||||
MESSAGES_SET_MESSAGE_READ: 'phone:setReadMessages',
|
||||
|
||||
// Notes
|
||||
NOTE_ADD_NOTE: 'phone:addNote',
|
||||
NOTE_FETCH_ALL_NOTES: 'phone:fetchAllNotes',
|
||||
NOTE_SEND_NOTE: 'phone:sendNote',
|
||||
NOTE_SEND_NOTE_SUCCESS: 'phone:sendNoteSuccess',
|
||||
NOTE_DELETE_NOTE: 'phone:deleteNote',
|
||||
NOTE_DELETE_NOTE_SUCCESS: 'phone:deleteNoteSuccess',
|
||||
NOTE_UPDATE_NOTE: 'phone:updateNote',
|
||||
NOTE_UPDATE_NOTE_SUCCESS: 'phone:updateNoteSuccess',
|
||||
NOTE_UPDATE_NOTE_FAILURE: 'phone:updateNoteFailure',
|
||||
NOTE_ACTION_RESULT: 'phone:notesActionResult',
|
||||
|
||||
// DO NOT CHANGE WHATS BELOW, PLEASE - CHIP
|
||||
PLAYER_IS_READY: 'phone:playerIsReady',
|
||||
OPEN_APP_CONTACTS: 'phone:app:CONTACTS',
|
||||
OPEN_APP_BANK: 'phone:app:BANK',
|
||||
OPEN_APP_NOTES: 'phone:app:NOTES',
|
||||
OPEN_APP_LISTINGS: 'phone:app:SELLOUT',
|
||||
OPEN_APP_CAMERA: 'phone:app:CAMERA',
|
||||
OPEN_APP_DAILER: 'phone:app:DIALER',
|
||||
|
||||
// camera
|
||||
CAMERA_TAKE_PHOTO: 'phone:TakePhoto',
|
||||
CAMERA_UPLOAD_PHOTO: 'phone:UploadPhoto',
|
||||
CAMERA_UPLOAD_PHOTO_SUCCESS: 'phone:UploadPhotoSuccess',
|
||||
CAMERA_FETCH_PHOTOS: 'phone:FetchPhotos',
|
||||
CAMERA_SEND_PHOTOS: 'phone:SendPhotos',
|
||||
CAMERA_DELETE_PHOTO: 'photo:deletePhoto',
|
||||
CAMERA_DELETE_PHOTO_SUCCESS: 'phone:deletePhotoSuccess',
|
||||
// copy
|
||||
PHONE_USE_CLIPBOARD: 'phone:useClipboard',
|
||||
|
||||
// calling
|
||||
PHONE_INITIALIZE_CALL: 'phone:beginCall',
|
||||
PHONE_START_CALL: 'phone:startCall',
|
||||
PHONE_ACCEPT_CALL: 'phone:acceptCall',
|
||||
PHONE_END_CALL: 'phone:endCall',
|
||||
PHONE_CALL_WAS_ENDED: 'phone:callEnded',
|
||||
PHONE_CALL_WAS_ACCEPTED: 'phone:callAccepted',
|
||||
PHONE_CALL_REJECTED: 'phone:rejectCall',
|
||||
PHONE_CALL_WAS_REJECTED: 'phone:callRejected',
|
||||
PHONE_CALL_FETCH_CALLS: 'phone:fetchCalls',
|
||||
PHONE_CALL_SEND_HISTORY: 'phone:sendCallHistory',
|
||||
PHONE_CALL_SEND_HANGUP_ANIM: 'phone:sendHangupAnim',
|
||||
|
||||
// email
|
||||
EMAIL_FETCH_INBOX: 'phone:fetchInbox',
|
||||
EMAIL_FETCH_INBOX_SUCCESS: 'phone:fetchInboxSuccess',
|
||||
EMAIL_FETCH_INBOX_ERROR: 'phone:fetchInboxError',
|
||||
};
|
||||
Reference in new issue
Block a user