diff --git a/phone/src/apps/email/components/EmailApp.tsx b/phone/src/apps/email/components/EmailApp.tsx index 1025282..81ca54d 100644 --- a/phone/src/apps/email/components/EmailApp.tsx +++ b/phone/src/apps/email/components/EmailApp.tsx @@ -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 = () => { + + + + + + diff --git a/phone/src/apps/email/components/EmailAppHeader.tsx b/phone/src/apps/email/components/EmailAppHeader.tsx index 8df0edc..3a7ae62 100644 --- a/phone/src/apps/email/components/EmailAppHeader.tsx +++ b/phone/src/apps/email/components/EmailAppHeader.tsx @@ -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" > - + history.goBack()} className={classes.back}> {icon} - + history.push('/email/?autoSearch=1')} className={classes.search}> diff --git a/phone/src/apps/email/components/EmailDetails.tsx b/phone/src/apps/email/components/EmailDetails.tsx new file mode 100644 index 0000000..92b480b --- /dev/null +++ b/phone/src/apps/email/components/EmailDetails.tsx @@ -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 ( + + 404 + + ); + } + + return ( + + + + {t('GENERIC_FROM')}: {email.sender} + + + {t('GENERIC_TO')}: {email.receivers.join(', ')} + + + + {t('APPS_EMAIL_SUBJECT')}: {email.subject || '( - )'} + + + + + {email.body} + + + + ); +}; diff --git a/phone/src/apps/email/components/EmailList.tsx b/phone/src/apps/email/components/EmailList.tsx index f88f9ca..2fd4d40 100644 --- a/phone/src/apps/email/components/EmailList.tsx +++ b/phone/src/apps/email/components/EmailList.tsx @@ -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 ( - - {emails && - emails.map((email) => ( - - - {email.sender.charAt(0).toUpperCase()} - - {getSendDate(email)} - ) : ( - {getSendDate(email)} - ) - } - > - {email.isRead ? {email.subject} : {email.subject}} - - - - {email.isRead ? : } - - - - ))} - - ); + return {emails && emails.map((email) => )}; }; diff --git a/phone/src/apps/email/components/EmailListItem.tsx b/phone/src/apps/email/components/EmailListItem.tsx new file mode 100644 index 0000000..ee4322a --- /dev/null +++ b/phone/src/apps/email/components/EmailListItem.tsx @@ -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 ( + history.push(`/email/details/${email.id}`)} + > + + {email.sender.charAt(0).toUpperCase()} + + {sendDate} : {sendDate}}> + {highlight ? {email.subject} : {email.subject}} + + + {!mine && ( + + {read ? : } + + )} + + + ); +}; diff --git a/phone/src/apps/email/components/InboxPage.tsx b/phone/src/apps/email/components/InboxPage.tsx index 30aa32f..9ad72c8 100644 --- a/phone/src/apps/email/components/InboxPage.tsx +++ b/phone/src/apps/email/components/InboxPage.tsx @@ -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(''); @@ -37,7 +37,7 @@ export const InboxPage = () => { /> - + ); diff --git a/phone/src/apps/email/components/SentPage.tsx b/phone/src/apps/email/components/SentPage.tsx new file mode 100644 index 0000000..f8ca0f3 --- /dev/null +++ b/phone/src/apps/email/components/SentPage.tsx @@ -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 ( + + + + + + ); +}; diff --git a/phone/src/apps/email/hooks/state.ts b/phone/src/apps/email/hooks/state.ts index c1c5abb..56e73e9 100644 --- a/phone/src/apps/email/hooks/state.ts +++ b/phone/src/apps/email/hooks/state.ts @@ -2,8 +2,16 @@ import { atom } from 'recoil'; import { IEmail } from '../../../common/typings/email'; export const emailState = { - emails: atom({ + inbox: atom({ default: null, - key: 'EMAIL:emails', + key: 'EMAIL:inbox', + }), + sent: atom({ + default: null, + key: 'EMAIL:sent', + }), + myEmail: atom({ + default: null, + key: 'EMAIL:myEmail', }), }; diff --git a/phone/src/apps/email/hooks/useEmail.ts b/phone/src/apps/email/hooks/useEmail.ts index 3e4a2cd..f731f7c 100644 --- a/phone/src/apps/email/hooks/useEmail.ts +++ b/phone/src/apps/email/hooks/useEmail.ts @@ -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 }; }; diff --git a/phone/src/apps/email/hooks/useEmailService.ts b/phone/src/apps/email/hooks/useEmailService.ts index 728a48a..b30ba61 100644 --- a/phone/src/apps/email/hooks/useEmailService.ts +++ b/phone/src/apps/email/hooks/useEmailService.ts @@ -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([ +InjectDebugData([ { 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: ['rocky@projecterror.org'], - sender: 'kidz@projecterror.org', - 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: ['rocky@projecterror.org'], - sender: 'kidz@projecterror.org', - 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: ['rocky@projecterror.org'], - sender: 'kidz@projecterror.org', - 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: ['rocky@projecterror.org'], - sender: 'chip@projecterror.org', - 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: ['rocky@projecterror.org'], - sender: 'taso@projecterror.org', - 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: ['rocky@projecterror.org'], - sender: 'kidz@projecterror.org', - 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: ['rocky@projecterror.org'], - sender: 'kidz@projecterror.org', - 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: ['rocky@projecterror.org'], - sender: 'kidz@projecterror.org', - sendDate: Date.now() / 1000, - isRead: false, - }, - ], + method: 'phone:setMyEmail', + data: 'rocky@projecterror.org', }, ]); + +InjectDebugData( + [ + { + app: 'EMAIL', + method: 'phone:fetchAllSentEmailsSuccess', + data: [ + { + id: 1, + subject: 'Hey!', + body: 'Hey did you try this email app? Looking good bruh', + receivers: ['kidz@projecterror.dev'], + sender: 'rocky@projecterror.org', + sendDate: Date.now() / 1000, + }, + { + id: 2, + subject: 'What is up?', + body: 'Hey did you try this email app? Looking good bruh', + receivers: ['kidz@projecterror.dev'], + sender: 'rocky@projecterror.org', + 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: ['rocky@projecterror.org'], + sender: 'kidz@projecterror.dev', + 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: ['rocky@projecterror.org'], + sender: 'kidz@projecterror.dev', + 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: ['rocky@projecterror.org'], + sender: 'kidz@projecterror.dev', + 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: ['rocky@projecterror.org'], + sender: 'chip@projecterror.dev', + 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: ['rocky@projecterror.org'], + sender: 'taso@projecterror.dev', + 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: ['rocky@projecterror.org'], + sender: 'kidz@projecterror.dev', + 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: ['rocky@projecterror.org'], + sender: 'kidz@projecterror.dev', + 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: ['rocky@projecterror.org'], + sender: 'kidz@projecterror.dev', + sendDate: Date.now() / 1000, + isRead: false, + }, + ], + }, + ], + 2500, +); diff --git a/phone/src/common/typings/email.ts b/phone/src/common/typings/email.ts index 52582d6..34ad095 100644 --- a/phone/src/common/typings/email.ts +++ b/phone/src/common/typings/email.ts @@ -10,7 +10,7 @@ export interface IEmailExternalAction { export interface IEmail { id: number; - isRead: boolean; + isRead?: boolean; receivers: string[]; sender: string; sendDate: number; diff --git a/phone/src/locale/en.json b/phone/src/locale/en.json index 6f816ae..e6683db 100644 --- a/phone/src/locale/en.json +++ b/phone/src/locale/en.json @@ -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",