mirror of
https://github.com/darksaid98/new-phone-who-dis.git
synced 2026-12-03 06:28:51 +00:00
Email app upgrades WIP
This commit is contained in:
1 parent
c2510266f8
commit
ff4381fa01
12 files changed
+272
-132
No files matched your search
@@ -7,6 +7,8 @@ import { Route, Switch } from 'react-router-dom';
|
||||
import { InboxPage } from './InboxPage';
|
||||
import { EmailAppHeader } from './EmailAppHeader';
|
||||
import { NewEmailPage } from './NewEmailPage';
|
||||
import { SentPage } from './SentPage';
|
||||
import { EmailDetails } from './EmailDetails';
|
||||
|
||||
export const EmailApp = () => {
|
||||
return (
|
||||
@@ -18,9 +20,15 @@ export const EmailApp = () => {
|
||||
<Route path="/email" exact>
|
||||
<InboxPage />
|
||||
</Route>
|
||||
<Route path="/email/sent" exact>
|
||||
<SentPage />
|
||||
</Route>
|
||||
<Route path="/email/new" exact>
|
||||
<NewEmailPage />
|
||||
</Route>
|
||||
<Route path="/email/details/:id">
|
||||
<EmailDetails />
|
||||
</Route>
|
||||
</Switch>
|
||||
</AppContent>
|
||||
<EmailNavBar />
|
||||
|
||||
@@ -3,6 +3,7 @@ import { Box, IconButton, makeStyles } from '@material-ui/core';
|
||||
import ArrowBackIcon from '@material-ui/icons/ArrowBack';
|
||||
import SearchIcon from '@material-ui/icons/Search';
|
||||
import { useApp } from '../../../os/apps/hooks/useApps';
|
||||
import { useHistory } from 'react-router';
|
||||
|
||||
const useStyles = makeStyles((theme) => ({
|
||||
root: {
|
||||
@@ -11,10 +12,12 @@ const useStyles = makeStyles((theme) => ({
|
||||
color: theme.palette.primary.contrastText,
|
||||
},
|
||||
back: {
|
||||
color: theme.palette.primary.contrastText,
|
||||
position: 'absolute',
|
||||
left: '12px',
|
||||
},
|
||||
search: {
|
||||
color: theme.palette.primary.contrastText,
|
||||
position: 'absolute',
|
||||
right: '12px',
|
||||
},
|
||||
@@ -22,6 +25,7 @@ const useStyles = makeStyles((theme) => ({
|
||||
|
||||
export const EmailAppHeader = () => {
|
||||
const classes = useStyles();
|
||||
const history = useHistory();
|
||||
const { icon } = useApp('EMAIL');
|
||||
|
||||
return (
|
||||
@@ -32,11 +36,11 @@ export const EmailAppHeader = () => {
|
||||
alignItems="center"
|
||||
justifyContent="center"
|
||||
>
|
||||
<IconButton className={classes.back}>
|
||||
<IconButton onClick={() => history.goBack()} className={classes.back}>
|
||||
<ArrowBackIcon />
|
||||
</IconButton>
|
||||
{icon}
|
||||
<IconButton className={classes.search}>
|
||||
<IconButton onClick={() => history.push('/email/?autoSearch=1')} className={classes.search}>
|
||||
<SearchIcon />
|
||||
</IconButton>
|
||||
</Box>
|
||||
|
||||
@@ -0,0 +1,43 @@
|
||||
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>
|
||||
);
|
||||
};
|
||||
@@ -1,54 +1,12 @@
|
||||
import {
|
||||
Avatar,
|
||||
IconButton,
|
||||
List,
|
||||
ListItem,
|
||||
ListItemAvatar,
|
||||
ListItemSecondaryAction,
|
||||
ListItemText,
|
||||
} from '@material-ui/core';
|
||||
import React from 'react';
|
||||
import { IEmail } from '../../../common/typings/email';
|
||||
import MarkRead from '@material-ui/icons/Markunread';
|
||||
import MarkUnread from '@material-ui/icons/MarkunreadMailbox';
|
||||
import dayjs from 'dayjs';
|
||||
import { useTranslation } from 'react-i18next';
|
||||
import { EmailListItem } from './EmailListItem';
|
||||
import { List } from '@material-ui/core';
|
||||
|
||||
interface IProps {
|
||||
emails: IEmail[];
|
||||
}
|
||||
|
||||
export const EmailList = ({ emails }: IProps) => {
|
||||
const { t } = useTranslation();
|
||||
|
||||
const getSendDate = (email) => dayjs.unix(email.sendDate).format(t('DATE_FORMAT'));
|
||||
|
||||
return (
|
||||
<List>
|
||||
{emails &&
|
||||
emails.map((email) => (
|
||||
<ListItem button divider key={email.id}>
|
||||
<ListItemAvatar>
|
||||
<Avatar>{email.sender.charAt(0).toUpperCase()}</Avatar>
|
||||
</ListItemAvatar>
|
||||
<ListItemText
|
||||
secondary={
|
||||
email.isRead ? (
|
||||
<span>{getSendDate(email)}</span>
|
||||
) : (
|
||||
<strong>{getSendDate(email)}</strong>
|
||||
)
|
||||
}
|
||||
>
|
||||
{email.isRead ? <span>{email.subject}</span> : <strong>{email.subject}</strong>}
|
||||
</ListItemText>
|
||||
<ListItemSecondaryAction>
|
||||
<IconButton>
|
||||
{email.isRead ? <MarkUnread color="primary" /> : <MarkRead color="primary" />}
|
||||
</IconButton>
|
||||
</ListItemSecondaryAction>
|
||||
</ListItem>
|
||||
))}
|
||||
</List>
|
||||
);
|
||||
return <List>{emails && emails.map((email) => <EmailListItem email={email} />)}</List>;
|
||||
};
|
||||
@@ -0,0 +1,50 @@
|
||||
import React from 'react';
|
||||
import {
|
||||
Avatar,
|
||||
IconButton,
|
||||
ListItem,
|
||||
ListItemAvatar,
|
||||
ListItemSecondaryAction,
|
||||
ListItemText,
|
||||
} from '@material-ui/core';
|
||||
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 { useHistory } from 'react-router';
|
||||
|
||||
export const EmailListItem = ({ email }: { email: IEmail }) => {
|
||||
const { t } = useTranslation();
|
||||
const { isMine } = 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;
|
||||
|
||||
return (
|
||||
<ListItem
|
||||
button
|
||||
divider
|
||||
key={email.id}
|
||||
onClick={() => history.push(`/email/details/${email.id}`)}
|
||||
>
|
||||
<ListItemAvatar>
|
||||
<Avatar>{email.sender.charAt(0).toUpperCase()}</Avatar>
|
||||
</ListItemAvatar>
|
||||
<ListItemText secondary={highlight ? <strong>{sendDate}</strong> : <span>{sendDate}</span>}>
|
||||
{highlight ? <strong>{email.subject}</strong> : <span>{email.subject}</span>}
|
||||
</ListItemText>
|
||||
<ListItemSecondaryAction>
|
||||
{!mine && (
|
||||
<IconButton>
|
||||
{read ? <MarkUnread color="primary" /> : <MarkRead color="primary" />}
|
||||
</IconButton>
|
||||
)}
|
||||
</ListItemSecondaryAction>
|
||||
</ListItem>
|
||||
);
|
||||
};
|
||||
@@ -16,7 +16,7 @@ const useStyles = makeStyles((theme) => ({
|
||||
export const InboxPage = () => {
|
||||
const classes = useStyles();
|
||||
|
||||
const { emails } = useEmail();
|
||||
const { inbox } = useEmail();
|
||||
const { autoSearch } = useQueryParams<{ autoSearch }>();
|
||||
|
||||
const [search, setSearch] = useState<string>('');
|
||||
@@ -37,7 +37,7 @@ export const InboxPage = () => {
|
||||
/>
|
||||
</Box>
|
||||
<Box overflow="auto" maxHeight="100%">
|
||||
<EmailList emails={emails} />
|
||||
<EmailList emails={inbox} />
|
||||
</Box>
|
||||
</Box>
|
||||
);
|
||||
|
||||
@@ -0,0 +1,15 @@
|
||||
import React from 'react';
|
||||
import { Box } from '@material-ui/core';
|
||||
import { useEmail } from '../hooks/useEmail';
|
||||
import { EmailList } from './EmailList';
|
||||
|
||||
export const SentPage = () => {
|
||||
const { sent } = useEmail();
|
||||
return (
|
||||
<Box height="100%">
|
||||
<Box overflow="auto" maxHeight="100%">
|
||||
<EmailList emails={sent} />
|
||||
</Box>
|
||||
</Box>
|
||||
);
|
||||
};
|
||||
@@ -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',
|
||||
}),
|
||||
};
|
||||
@@ -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 };
|
||||
};
|
||||
@@ -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,
|
||||
);
|
||||
@@ -10,7 +10,7 @@ export interface IEmailExternalAction {
|
||||
|
||||
export interface IEmail {
|
||||
id: number;
|
||||
isRead: boolean;
|
||||
isRead?: boolean;
|
||||
receivers: string[];
|
||||
sender: string;
|
||||
sendDate: number;
|
||||
|
||||
@@ -203,7 +203,14 @@
|
||||
"APPS_MARKETPLACE_FORM_IMAGE": "Image or URL",
|
||||
"APPS_MARKETPLACE_FORM_DESCRIPTION": "Description",
|
||||
|
||||
"APPS_EMAIL_INBOX": "Inbox",
|
||||
"APPS_EMAIL_SENT": "Sent",
|
||||
"APPS_EMAIL_SUBJECT": "Subject",
|
||||
|
||||
"GENERIC_CLICK_TO_REVEAL": "Click to reveal",
|
||||
"GENERIC_NEW": "New",
|
||||
"GENERIC_FROM": "From",
|
||||
"GENERIC_TO": "To",
|
||||
"GENERIC_WAIT": "Please wait...",
|
||||
"GENERIC_SAVE": "Save",
|
||||
"GENERIC_UPDATE": "Update",
|
||||
|
||||
Reference in new issue
Block a user