diff --git a/phone/src/Phone.tsx b/phone/src/Phone.tsx index 781e876..1c5c41b 100644 --- a/phone/src/Phone.tsx +++ b/phone/src/Phone.tsx @@ -2,10 +2,10 @@ import React from 'react'; import './Phone.css'; import './i18n'; import { Route } from 'react-router-dom'; -import { CallModal } from './modal/components/CallModal'; +import { CallModal } from './os/call/components/CallModal'; import { HomeApp } from './apps/home/components/Home'; -import { ThemeProvider, Slide } from '@material-ui/core'; -import { useInitKeyboard } from './os/keyboard/hooks/useKeyboard'; +import { Slide } from '@material-ui/core'; +import { useKeyboardService } from './os/keyboard/hooks/useKeyboardService'; import { NotificationBar } from './os/notifications/components/NotificationBar'; import { Navigation } from './os/navigation-bar/components/Navigation'; import { useNuiService } from './os/nui-events/hooks/useNuiService'; @@ -21,33 +21,25 @@ import { useMessagesService } from './apps/messages/hooks/useMessageService'; import { useNotesService } from './apps/notes/hooks/useNotesService'; import { usePhotoService } from './apps/camera/hooks/usePhotoService'; import { useSettings } from './apps/settings/hooks/useSettings'; -import { useCallService } from './modal/hooks/useCallService'; -import { useModal } from './modal/hooks/useModal'; +import { useCallService } from './os/call/hooks/useCallService'; import { useDialService } from './apps/dialer/hooks/useDialService'; import InjectDebugData from './os/debug/InjectDebugData'; import { usePhoneVisibility } from './os/phone/hooks/usePhoneVisibility'; -import { usePhoneTheme } from './os/phone/hooks/usePhoneTheme'; import { Snackbar } from './ui/components/Snackbar'; +import { NotificationAlert } from './os/notifications/components/NotificationAlert'; +import { useCallModal } from './os/call/hooks/useCallModal'; function Phone() { - const { modal } = useModal(); const { apps } = useApps(); const [settings] = useSettings(); - const { - bottom, - visibility, - uncollapseNotifications, - clickEventOverride, - } = usePhoneVisibility(); - useNuiService(); + useKeyboardService(); usePhoneService(); useSimcardService(); useContactsService(); useTwitterService(); - useInitKeyboard(); useSelloutService(); useBankService(); useMessagesService(); @@ -56,58 +48,56 @@ function Phone() { useCallService(); useDialService(); - const currentTheme = usePhoneTheme(); + const { modal: callModal } = useCallModal(); + const { bottom, visibility } = usePhoneVisibility(); return ( - - -
-
+ +
+
+
+
-
-
- <> - -
- {modal ? ( - - ) : ( - <> - - {apps.map((App) => ( - - ))} - + <> + +
+ <> + + {callModal && ( + )} - -
- - -
+ {apps.map((App) => ( + + ))} + + + +
+ +
- - +
+ ); } diff --git a/phone/src/PhoneContainer.tsx b/phone/src/PhoneContainer.tsx new file mode 100644 index 0000000..80a6111 --- /dev/null +++ b/phone/src/PhoneContainer.tsx @@ -0,0 +1,21 @@ +import React from 'react'; +import { ThemeProvider } from '@material-ui/core'; +import { BankNotification } from './apps/bank/components/notification/BankNotification'; +import { NotificationsProvider } from './os/notifications/providers/NotificationsProvider'; +import { usePhoneTheme } from './os/phone/hooks/usePhoneTheme'; +import SnackbarProvider from './ui/providers/SnackbarProvider'; +import Phone from './Phone'; + +export const PhoneContainer = () => { + const currentTheme = usePhoneTheme(); + return ( + + + + + + + + + ); +}; diff --git a/phone/src/apps/calculator/components/CalculatorIcon.tsx b/phone/src/apps/calculator/components/CalculatorIcon.tsx index 41b0710..0db3dd3 100644 --- a/phone/src/apps/calculator/components/CalculatorIcon.tsx +++ b/phone/src/apps/calculator/components/CalculatorIcon.tsx @@ -1,7 +1,7 @@ import React from 'react'; -import { SvgIcon } from '@material-ui/core'; +import { SvgIcon, SvgIconProps } from '@material-ui/core'; -export const CalculatorIcon = ({ ...props }) => { +export const CalculatorIcon = ({ ...props}: SvgIconProps) => { return ( { history.push(referal); }; - const handleDeletePhoto = useCallback(() => { + const handleDeletePhoto = () => { Nui.send('photo:deletePhoto', { - id: meta.id, + image: meta.image, }); history.push(referal); - }, [history, meta.id, referal]); + }; const handleSharePhoto = useCallback(() => { setShareOpen(meta); @@ -42,7 +42,11 @@ export const GalleryModal = () => { return ( <> - setShareOpen(null)} /> + setShareOpen(null)} + />
{/* Here we are using the value in a h3 tag */}

{exampleString}

+ (playing ? stop() : play())}> + {playing ? : } + + diff --git a/phone/src/apps/home/components/Home.tsx b/phone/src/apps/home/components/Home.tsx index e1513fb..da22aa0 100644 --- a/phone/src/apps/home/components/Home.tsx +++ b/phone/src/apps/home/components/Home.tsx @@ -8,8 +8,8 @@ export const HomeApp = () => { const { apps } = useApps(); return ( - - {apps && } + + {apps && } ); diff --git a/phone/src/apps/messages/components/modal/MessageBubble.tsx b/phone/src/apps/messages/components/modal/MessageBubble.tsx index de52d8a..a4ebebd 100644 --- a/phone/src/apps/messages/components/modal/MessageBubble.tsx +++ b/phone/src/apps/messages/components/modal/MessageBubble.tsx @@ -12,9 +12,11 @@ const useStyles = makeStyles((theme) => ({ mySms: { float: 'right', margin: theme.spacing(1), - padding: '6px 12px', + padding: '6px 16px', height: 'auto', - width: '80%', + width: 'auto', + minWidth: '60%', + maxWidth: '85%', background: theme.palette.background.default, color: theme.palette.text.primary, borderRadius: '20px', @@ -24,7 +26,9 @@ const useStyles = makeStyles((theme) => ({ float: 'left', margin: theme.spacing(1), padding: '6px 12px', - width: '80%', + width: 'auto', + minWidth: '60%', + maxWidth: '85%', height: 'auto', background: theme.palette.primary.light, color: theme.palette.getContrastText(theme.palette.primary.light), @@ -62,7 +66,7 @@ export const MessageBubble = ({
{message.message}
)} - + {isGroupChat && !message.isMine ? message.display || message.phone_number diff --git a/phone/src/apps/notes/NotesApp.css b/phone/src/apps/notes/NotesApp.css deleted file mode 100644 index 6728c0e..0000000 --- a/phone/src/apps/notes/NotesApp.css +++ /dev/null @@ -1,7 +0,0 @@ -#notes-app .Mui-focused::after { - border-bottom: 3px solid #f9a825; -} - -#notes-app .MuiOutlinedInput-root { - border: 2px soild #f9a825; -} diff --git a/phone/src/apps/notes/NotesApp.tsx b/phone/src/apps/notes/NotesApp.tsx index face916..9b9d223 100644 --- a/phone/src/apps/notes/NotesApp.tsx +++ b/phone/src/apps/notes/NotesApp.tsx @@ -4,17 +4,45 @@ import { AppContent } from '../../ui/components/AppContent'; import { AppTitle } from '../../ui/components/AppTitle'; import { useApp } from '../../os/apps/hooks/useApps'; import NoteList from './list/NoteList'; - -import { useNotes } from './hooks/useNotes'; import { NoteModal } from './modal/NoteModal'; import { Fab } from '@material-ui/core'; import AddIcon from '@material-ui/icons/Add'; - -import { useNoteModal } from './hooks/useNoteModal'; import { useNoteDetail } from './hooks/useNoteDetail'; - import useStyles from './notes.styles'; import InjectDebugData from '../../os/debug/InjectDebugData'; +import { NotesThemeProvider } from './providers/NotesThemeProvider'; +import { Route, useHistory } from 'react-router-dom'; + +export const NotesApp = () => { + const classes = useStyles(); + const history = useHistory(); + const notesApp = useApp('NOTES'); + const { setDetail } = useNoteDetail(); + + const onClickCreate = () => { + setDetail({ title: '', content: '' }); + history.push('/notes/detail'); + }; + + return ( + + + + + + + + + + + + + ); +}; InjectDebugData([ { @@ -34,37 +62,3 @@ InjectDebugData([ ], }, ]); - -export const NotesApp = () => { - const { setNoteModal } = useNoteModal(); - const { detail, setDetail } = useNoteDetail(); - const { notes } = useNotes(); - const notesApp = useApp('NOTES'); - - const classes = useStyles(); - - const handleModal = () => { - setNoteModal(true); - setDetail(null); - }; - - return ( - - - - - - - - - - - ); -}; diff --git a/phone/src/apps/notes/NotesTitle.tsx b/phone/src/apps/notes/NotesTitle.tsx index 9d4404a..d3c2171 100644 --- a/phone/src/apps/notes/NotesTitle.tsx +++ b/phone/src/apps/notes/NotesTitle.tsx @@ -1,18 +1,30 @@ import React from 'react'; -import { yellow } from '@material-ui/core/colors'; - -import useStyles from './notes.styles'; - -import { Paper } from '@material-ui/core'; +import { makeStyles, Paper } from '@material-ui/core'; import { FontAwesomeIcon } from '@fortawesome/react-fontawesome'; import { faStickyNote } from '@fortawesome/free-solid-svg-icons'; +const useStyles = makeStyles((theme) => ({ + header: { + width: '100%', + display: 'flex', + flexFlow: 'row nowrap', + justifyContent: 'center', + alignItems: 'center', + textAlign: 'center', + height: '60px', + }, + icon: { + color: theme.palette.primary.main, + fontSize: 40, + }, +})); + const NotesTitle = () => { const classes = useStyles(); return ( - + ); }; diff --git a/phone/src/apps/notes/hooks/useNoteModal.ts b/phone/src/apps/notes/hooks/useNoteModal.ts deleted file mode 100644 index f946540..0000000 --- a/phone/src/apps/notes/hooks/useNoteModal.ts +++ /dev/null @@ -1,12 +0,0 @@ -import { useRecoilState } from 'recoil'; -import { noteStates } from './state'; - -interface NoteModalProps { - noteModal: boolean; - setNoteModal: (show: boolean) => void; -} - -export const useNoteModal = (): NoteModalProps => { - const [noteModal, setNoteModal] = useRecoilState(noteStates.noteModal); - return { noteModal, setNoteModal }; -}; diff --git a/phone/src/apps/notes/list/NoteList.tsx b/phone/src/apps/notes/list/NoteList.tsx index 0e569c0..9b5634f 100644 --- a/phone/src/apps/notes/list/NoteList.tsx +++ b/phone/src/apps/notes/list/NoteList.tsx @@ -1,18 +1,19 @@ -import { List, ListItem, ListItemText } from '@material-ui/core'; import React from 'react'; - -import { useNoteModal } from '../hooks/useNoteModal'; +import { List, ListItem, ListItemText } from '@material-ui/core'; import { useNoteDetail } from '../hooks/useNoteDetail'; +import { useNotes } from '../hooks/useNotes'; +import { useHistory } from 'react-router-dom'; // add search bar later // TODO: Add interface for note -const NoteList = ({ notes }) => { - const { setNoteModal } = useNoteModal(); +const NoteList = () => { + const history = useHistory(); + const { notes } = useNotes(); const { setDetail } = useNoteDetail(); const handleNoteModal = (note) => { - setNoteModal(true); setDetail(note); + history.push('/notes/detail'); }; return ( diff --git a/phone/src/apps/notes/modal/NoteModal.tsx b/phone/src/apps/notes/modal/NoteModal.tsx index 08d099e..2b3b110 100644 --- a/phone/src/apps/notes/modal/NoteModal.tsx +++ b/phone/src/apps/notes/modal/NoteModal.tsx @@ -1,41 +1,39 @@ -import { Button, TextField, Slide } from '@material-ui/core'; -import React, { useState } from 'react'; +import { + Button, + TextField, + Slide, + Paper, + Typography, + Container, + CircularProgress, + Box, +} from '@material-ui/core'; +import React from 'react'; import ArrowBackIcon from '@material-ui/icons/ArrowBack'; - -import { useNoteModal } from '../hooks/useNoteModal'; import { useNoteDetail } from '../hooks/useNoteDetail'; - import useStyles from './modal.styles'; - -import '../NotesApp.css'; import Nui from '../../../os/nui-events/utils/Nui'; +import { useTranslation } from 'react-i18next'; +import { useHistory } from 'react-router-dom'; +import { StatusButton } from '../../../ui/components/StatusButton'; -// TODO: Fix input focus color export const NoteModal = () => { - const { noteModal, setNoteModal } = useNoteModal(); + const classes = useStyles(); + const history = useHistory(); + const { t } = useTranslation(); const { detail, setDetail } = useNoteDetail(); - const [title, setTitle] = useState(detail ? detail.title : ''); - const [content, setContent] = useState(detail ? detail.content : ''); - const classes = useStyles() - - + const onClose = () => history.goBack(); const _handleClose = () => { setDetail(null); - setNoteModal(false); + onClose(); }; const handleNoteSave = () => { - Nui.send('phone:addNote', { - title, - content, - }); + Nui.send('phone:addNote', detail); setDetail(null); - setNoteModal(false); - - setTitle('') - setContent('') + onClose(); }; const handleDeleteNote = () => { @@ -44,78 +42,112 @@ export const NoteModal = () => { id, }); setDetail(null); - setNoteModal(false); + onClose(); }; const handleUpdateNote = () => { - Nui.send('phone:updateNote', { - id: detail.id, - title, - content, - }); + Nui.send('phone:updateNote', detail); setDetail(null); - setNoteModal(false); + onClose(); }; return ( -
- -
- -
- setTitle(e.target.value)} - /> - setContent(e.target.value)} - /> -

{content.length}/250

- {!detail &&( - - )} - {detail && ( - - )} - {detail && ( - - )} -
-
-
-
+ + + {!detail ? ( + + ) : ( + + + + + + + setDetail((d) => ({ ...d, title: e.target.value })) + } + /> + + setDetail((d) => ({ ...d, content: e.target.value })) + } + /> + {detail.content.length}/250 + {!detail.id ? ( + <> + + + + + + {t('GENERIC_CANCEL')} + + + + ) : ( + <> + + + + + + {t('GENERIC_DELETE')} + + + + )} + + + )} + + ); }; diff --git a/phone/src/apps/notes/modal/modal.styles.ts b/phone/src/apps/notes/modal/modal.styles.ts index 44d1f40..f706446 100644 --- a/phone/src/apps/notes/modal/modal.styles.ts +++ b/phone/src/apps/notes/modal/modal.styles.ts @@ -4,23 +4,9 @@ const useStyles = makeStyles((theme) => ({ modalRoot: { zIndex: 20, position: 'absolute', - height: '100%', + height: '99%', width: '100%', - background: '#232323', - }, - modalHide: { - display: 'none', - }, - closeButton: { - width: '10%', - position: 'absolute', - top: 10, - left: 0, - }, - noteContainer: { - width: '90%', - marginTop: 80, - margin: '0 auto', + background: theme.palette.background.default, }, input: { marginBottom: 20, @@ -30,19 +16,7 @@ const useStyles = makeStyles((theme) => ({ }, inputPropsContent: { fontSize: 20, - }, - saveButton: { - background: '#f9a825', - padding: '10px 30px', - }, - updateButton: { - background: '#f9a825', - padding: '10px 30px', - marginRight: '8px', - }, - deleteButton: { - background: '#c62828', - padding: '10px 30px', + lineHeight: 1.2, }, })); diff --git a/phone/src/apps/notes/notes.styles.ts b/phone/src/apps/notes/notes.styles.ts index c1b1cc5..71b03e3 100644 --- a/phone/src/apps/notes/notes.styles.ts +++ b/phone/src/apps/notes/notes.styles.ts @@ -1,15 +1,6 @@ import { makeStyles } from '@material-ui/core'; const useStyles = makeStyles((theme) => ({ - header: { - width: '100%', - display: 'flex', - flexFlow: 'row nowrap', - justifyContent: 'center', - alignItems: 'center', - textAlign: 'center', - height: '60px', - }, backgroundModal: { background: 'black', opacity: '0.6', diff --git a/phone/src/apps/notes/notes.theme.ts b/phone/src/apps/notes/notes.theme.ts new file mode 100644 index 0000000..dddda36 --- /dev/null +++ b/phone/src/apps/notes/notes.theme.ts @@ -0,0 +1,18 @@ +import { common, yellow } from "@material-ui/core/colors"; + +export const NOTES_APP_PRIMARY_COLOR = yellow[800]; +export const NOTES_APP_ICON_COLOR = common.white; +export const NOTES_APP_TEXT_COLOR = common.black; + +const theme = { + palette: { + primary: { + main: NOTES_APP_PRIMARY_COLOR, + dark: yellow[900], + light: yellow[500], + contrastText: NOTES_APP_TEXT_COLOR + } + } +} + +export default theme; diff --git a/phone/src/apps/notes/providers/NotesThemeProvider.tsx b/phone/src/apps/notes/providers/NotesThemeProvider.tsx new file mode 100644 index 0000000..d336e03 --- /dev/null +++ b/phone/src/apps/notes/providers/NotesThemeProvider.tsx @@ -0,0 +1,4 @@ +import { createAppThemeProvider } from "../../../os/apps/utils/createAppThemeProvider"; +import notesTheme from '../notes.theme'; + +export const NotesThemeProvider = createAppThemeProvider(notesTheme); diff --git a/phone/src/apps/sellout/sellout.theme.ts b/phone/src/apps/sellout/sellout.theme.ts index b1b511a..92e3f23 100644 --- a/phone/src/apps/sellout/sellout.theme.ts +++ b/phone/src/apps/sellout/sellout.theme.ts @@ -1,12 +1,16 @@ -import { common } from "@material-ui/core/colors"; +import { common, red } from "@material-ui/core/colors"; + +export const SELLOUT_APP_PRIMARY_COLOR = red[500]; +export const SELLOUT_APP_ICON_COLOR = common.white; +export const SELLOUT_APP_TEXT_COLOR = common.black; const theme = { palette: { primary: { - main: '#f44336', - dark: '#b3251b', - light: 'f87f76', - contrastText: common.black + main: SELLOUT_APP_PRIMARY_COLOR, + dark: red[700], + light: red[200], + contrastText: SELLOUT_APP_TEXT_COLOR } } } diff --git a/phone/src/apps/twitter/components/TwitterApp.tsx b/phone/src/apps/twitter/components/TwitterApp.tsx index 7b0239b..d86a8cd 100644 --- a/phone/src/apps/twitter/components/TwitterApp.tsx +++ b/phone/src/apps/twitter/components/TwitterApp.tsx @@ -20,100 +20,6 @@ import { useProfile } from '../hooks/useProfile'; import ProfilePrompt from './profile/ProfilePrompt'; import InjectDebugData from '../../../os/debug/InjectDebugData'; -InjectDebugData([ - { - app: 'TWITTER', - method: 'getOrCreateTwitterProfile', - data: { - profile_name: 'Angular_Dev', - bio: 'Angular FTW', - job: 'Googler @ Google', - location: '1600 Amphitheatre Parkway, CA, USA', - avatar_url: 'https://i.tasoagc.dev/i9Ig', - }, - }, - { - app: 'TWITTER', - method: 'createTweetBroadcast', - data: { - id: 111, - profile_id: 111, - profile_name: 'Kidz', - isMine: false, - isReported: false, - message: 'I have tweeted this because Im badass' - } - }, - { - app: 'TWITTER', - method: 'createTweetBroadcast', - data: { - id: 111, - profile_id: 111, - profile_name: 'ItsChip', - isMine: false, - isReported: false, - message: 'I have tweeted this because Im even more badass' - } - }, - { - app: 'TWITTER', - method: 'fetchTweets', - data: [ - { - id: 59, - message: 'XSS\n\nBro', - avatar_url: 'http://i.tasoagc.dev/jtKL', - seconds_since_tweet: 500, - isMine: false, - updateAt: '2021-02-08 14:37:46', - visible: 1, - likes: 50000, - profile_name: 'jQuery Main', - images: 'http://i.tasoagc.dev/0xdp', - }, - { - id: 2, - message: 'GCPhone will never die', - avatar_url: 'http://i.tasoagc.dev/jtKL', - seconds_since_tweet: 500, - isMine: false, - updateAt: '2021-02-08 14:37:46', - visible: 1, - likes: 50000, - profile_name: 'GCPhone_v9999', - images: 'http://i.tasoagc.dev/0xdp', - }, - { - id: 1, - message: 'I love angular', - avatar_url: 'https://i.tasoagc.dev/i9Ig', - seconds_since_tweet: 800, - isMine: true, - updateAt: '2021-02-08 14:37:46', - visible: 1, - likes: 50000, - profile_name: 'Angular_Dev', - images: 'http://i.tasoagc.dev/i9Ig', - }, - { - id: 3, - message: - 'Anyways uhm... I bought a whole bunch of shungite, rocks, ' + - 'do you know what shungite is? Anybody know what shungite is. No, no ' + - 'Suge Knight, I think hes locked up in prison.', - avatar_url: 'http://i.tasoagc.dev/0v64', - seconds_since_tweet: 800, - isMine: true, - updateAt: '2021-02-08 14:37:46', - visible: 1, - likes: 50000, - profile_name: 'The_Doc', - }, - ], - }, -]); - const useStyles = makeStyles(() => ({ backgroundModal: { background: 'black', @@ -186,3 +92,103 @@ export const TwitterApp = () => { ); }; + +InjectDebugData([ + { + app: 'TWITTER', + method: 'getOrCreateTwitterProfile', + data: { + profile_name: 'Angular_Dev', + bio: 'Angular FTW', + job: 'Googler @ Google', + location: '1600 Amphitheatre Parkway, CA, USA', + avatar_url: 'https://i.tasoagc.dev/i9Ig', + }, + }, + { + app: 'TWITTER', + method: 'fetchTweets', + data: [ + { + id: 59, + message: 'XSS\n\nBro', + avatar_url: 'http://i.tasoagc.dev/jtKL', + seconds_since_tweet: 500, + isMine: false, + updateAt: '2021-02-08 14:37:46', + visible: 1, + likes: 50000, + profile_name: 'jQuery Main', + images: 'http://i.tasoagc.dev/0xdp', + }, + { + id: 2, + message: 'GCPhone will never die', + avatar_url: 'http://i.tasoagc.dev/jtKL', + seconds_since_tweet: 500, + isMine: false, + updateAt: '2021-02-08 14:37:46', + visible: 1, + likes: 50000, + profile_name: 'GCPhone_v9999', + images: 'http://i.tasoagc.dev/0xdp', + }, + { + id: 1, + message: 'I love angular', + avatar_url: 'https://i.tasoagc.dev/i9Ig', + seconds_since_tweet: 800, + isMine: true, + updateAt: '2021-02-08 14:37:46', + visible: 1, + likes: 50000, + profile_name: 'Angular_Dev', + images: 'http://i.tasoagc.dev/i9Ig', + }, + { + id: 3, + message: + 'Anyways uhm... I bought a whole bunch of shungite, rocks, ' + + 'do you know what shungite is? Anybody know what shungite is. No, no ' + + 'Suge Knight, I think hes locked up in prison.', + avatar_url: 'http://i.tasoagc.dev/0v64', + seconds_since_tweet: 800, + isMine: true, + updateAt: '2021-02-08 14:37:46', + visible: 1, + likes: 50000, + profile_name: 'The_Doc', + }, + ], + }, +]); + +InjectDebugData( + [ + { + app: 'TWITTER', + method: 'createTweetBroadcast', + data: { + id: 111, + profile_id: 111, + profile_name: 'Kidz', + isMine: false, + isReported: false, + message: 'I have tweeted this because Im badass', + }, + }, + { + app: 'TWITTER', + method: 'createTweetBroadcast', + data: { + id: 111, + profile_id: 111, + profile_name: 'ItsChip', + isMine: false, + isReported: false, + message: 'I have tweeted this because Im even more badass... And I need this to be longer so I will continue to write', + }, + }, + ], + 2000 +); diff --git a/phone/src/apps/twitter/components/tweet/TweetListContainer.tsx b/phone/src/apps/twitter/components/tweet/TweetListContainer.tsx index a5a74c2..d90d7b5 100644 --- a/phone/src/apps/twitter/components/tweet/TweetListContainer.tsx +++ b/phone/src/apps/twitter/components/tweet/TweetListContainer.tsx @@ -2,15 +2,23 @@ import React, { useEffect } from 'react'; import Nui from '../../../../os/nui-events/utils/Nui'; import { useTweets } from '../../hooks/useTweets'; +import { useTwitterNotifications } from '../../hooks/useTwitterNotifications'; import TweetList from './TweetList'; export function TweetListContainer() { const { tweets } = useTweets(); + const { setUnreadCount } = useTwitterNotifications(); useEffect(() => { Nui.send('phone:fetchTweets', {}); }, []); + useEffect(() => { + if (tweets?.length) { + setUnreadCount(0); + } + }, [setUnreadCount, tweets]); + return ; } diff --git a/phone/src/apps/twitter/hooks/state.ts b/phone/src/apps/twitter/hooks/state.ts index f541623..cd3aa07 100644 --- a/phone/src/apps/twitter/hooks/state.ts +++ b/phone/src/apps/twitter/hooks/state.ts @@ -37,8 +37,8 @@ export const twitterState = { key: 'updateProfileSuccess', default: null, }), - notification: atom({ - key: 'notification', - default: null, + unreadTweetsCount: atom({ + key: 'unreadTweetsCount', + default: 0, }), }; diff --git a/phone/src/apps/twitter/hooks/useTwitterNotification.ts b/phone/src/apps/twitter/hooks/useTwitterNotification.ts deleted file mode 100644 index d01a9ca..0000000 --- a/phone/src/apps/twitter/hooks/useTwitterNotification.ts +++ /dev/null @@ -1,13 +0,0 @@ -import { useRecoilValue } from 'recoil'; - -import { Tweet } from '../../../common/typings/twitter'; -import { twitterState } from './state'; - -interface ITwitterNotification { - notification: Tweet | null; -} - -export const useTwitterNotification = (): ITwitterNotification => { - const notification = useRecoilValue(twitterState.notification); - return { notification }; -}; diff --git a/phone/src/apps/twitter/hooks/useTwitterNotifications.ts b/phone/src/apps/twitter/hooks/useTwitterNotifications.ts new file mode 100644 index 0000000..d6cb625 --- /dev/null +++ b/phone/src/apps/twitter/hooks/useTwitterNotifications.ts @@ -0,0 +1,43 @@ +import { useCallback } from "react"; +import { useTranslation } from "react-i18next"; +import { useHistory } from "react-router-dom"; +import { useRecoilState } from "recoil"; +import { useApp } from "../../../os/apps/hooks/useApps"; +import { useNotifications } from "../../../os/notifications/hooks/useNotifications"; +import { twitterState } from "./state"; + +export const useTwitterNotifications = () => { + const { t } = useTranslation(); + const history = useHistory(); + const { addNotificationAlert } = useNotifications(); + const { icon, notificationIcon } = useApp('TWITTER'); + const [unreadCount, setUnreadCount] = useRecoilState(twitterState.unreadTweetsCount); + const setNotification = useCallback( + ({ profile_name, message }) => { + setUnreadCount((curr) => { + const unread = curr + 1; + addNotificationAlert( + { + app: 'TWITTER', + title: t('APPS_TWITTER_NEW_BROADCAST', { profile_name }), + onClick: () => history.push('/twitter'), + content: message, + icon, + notificationIcon, + }, + true, + { + title: t('APPS_TWITTER_UNREAD_MESSAGES', { + count: unread, + }), + content: null, + } + ); + return unread; + }); + }, + [setUnreadCount, addNotificationAlert, t, icon, notificationIcon, history] + ); + + return { setNotification, setUnreadCount, unreadCount } +}; diff --git a/phone/src/apps/twitter/hooks/useTwitterService.ts b/phone/src/apps/twitter/hooks/useTwitterService.ts index 0921f4f..410e4d1 100644 --- a/phone/src/apps/twitter/hooks/useTwitterService.ts +++ b/phone/src/apps/twitter/hooks/useTwitterService.ts @@ -5,11 +5,8 @@ import { useNuiEvent } from '../../../os/nui-events/hooks/useNuiEvent'; import { IMAGE_DELIMITER } from '../utils/images'; import { APP_TWITTER } from '../utils/constants'; import { twitterState } from './state'; -import { useNotifications } from '../../../os/notifications/hooks/useNotifications'; -import { useApp } from '../../../os/apps/hooks/useApps'; -import { useTranslation } from 'react-i18next'; -import { useCallback } from 'react'; import { useSnackbar } from '../../../ui/hooks/useSnackbar'; +import { useTwitterNotifications } from './useTwitterNotifications'; /** * Perform all necessary processing/transforms from the raw database @@ -33,23 +30,8 @@ function processTweet(tweet) { * there and have moved that logic here instead. */ export const useTwitterService = () => { - const { t } = useTranslation(); - const { addNotification } = useNotifications(); const { addAlert } = useSnackbar() - const { icon, notificationIcon } = useApp('TWITTER'); - - const setNotification = useCallback( - ({ profile_name, message }) => - addNotification({ - app: 'TWITTER', - title: t('APPS_TWITTER_NEW_BROADCAST', { profile_name }), - href: '/twitter', - content: message, - icon, - notificationIcon, - }), - [addNotification, icon, notificationIcon, t] - ); + const { setNotification } = useTwitterNotifications(); const setProfile = useSetRecoilState(twitterState.profile); const setUpdateProfileLoading = useSetRecoilState( diff --git a/phone/src/common/hooks/useQueryParams.ts b/phone/src/common/hooks/useQueryParams.ts index 7512025..105984e 100644 --- a/phone/src/common/hooks/useQueryParams.ts +++ b/phone/src/common/hooks/useQueryParams.ts @@ -10,7 +10,12 @@ import { useLocation } from 'react-router-dom'; * * const { id, title } = useQueryParams<{ id: string, title: string }>(); */ -export function useQueryParams>() { - return qs.parse(useLocation().search, { ignoreQueryPrefix: true }) as T & - Partial; +export function useQueryParams>( + defaultValues: T = null +) { + const query = qs.parse(useLocation().search, { ignoreQueryPrefix: true }); + if (!defaultValues) { + return query as T & Partial; + } + return { ...defaultValues, ...query } as T & Partial; } diff --git a/phone/src/common/typings/call.ts b/phone/src/common/typings/call.ts index 58cc8db..78c195f 100644 --- a/phone/src/common/typings/call.ts +++ b/phone/src/common/typings/call.ts @@ -1,4 +1,5 @@ export interface CallProps { + active: boolean; accepted: boolean; isTransmitter: boolean; transmitter: string; diff --git a/phone/src/config/default.json b/phone/src/config/default.json index c748c01..17eb8bb 100644 --- a/phone/src/config/default.json +++ b/phone/src/config/default.json @@ -44,7 +44,7 @@ "palette": { "type": "dark", "primary": { - "main": "#a6d4fa" + "main": "#a6d4fa" }, "background": { "paper": "#1c1c1c", diff --git a/phone/src/index.tsx b/phone/src/index.tsx index b771a77..bd22b27 100644 --- a/phone/src/index.tsx +++ b/phone/src/index.tsx @@ -6,10 +6,8 @@ import { RecoilRoot } from 'recoil'; import * as Sentry from '@sentry/react'; import { Integrations } from '@sentry/tracing'; import './main.css'; -import Phone from './Phone'; import PhoneConfig from './config/default.json'; -import SnackbarProvider from './ui/providers/SnackbarProvider'; -import { NotificationsProvider } from './os/notifications/providers/NotificationsProvider'; +import { PhoneContainer } from './PhoneContainer'; // Enable Sentry when config setting is true if (PhoneConfig.SentryErrorMetrics) { @@ -27,11 +25,7 @@ if (PhoneConfig.SentryErrorMetrics) { ReactDOM.render( - - - - - + , document.getElementById('root') diff --git a/phone/src/locale/en.json b/phone/src/locale/en.json index c7f0966..21b1735 100644 --- a/phone/src/locale/en.json +++ b/phone/src/locale/en.json @@ -17,6 +17,14 @@ "APPS_SELLOUT": "Market", "APPS_CAMERA": "Camera", + "APPS_DIALER_CURRENT_CALL_TITLE": "Current Phone Call", + "APPS_DIALER_INCOMING_CALL_TITLE": "Incoming Phone Call", + "APPS_DIALER_CURRENT_CALL_WITH": "In call with {{ transmitter }}", + "APPS_DIALER_TRANSMITTER_IS_CALLING": "{{ transmitter }} is calling you!", + "APPS_DIALER_ACCEPT_CALL": "Accept", + "APPS_DIALER_REJECT_CALL": "Reject", + "APPS_DIALER_END_CALL": "End", + "APPS_BANK_TRANSFER": "Transfer", "APPS_SETTINGS_OPTIONS_WALLPAPER": "Wallpaper", "APPS_SETTINGS_OPTIONS_FRAME": "Frame", @@ -48,6 +56,7 @@ "APPS_TWITTER_TIME_HOURS": "h", "APPS_TWITTER_TIME_DAYS": "d", "APPS_TWITTER_NEW_BROADCAST": "New tweet from @{{ profile_name }}!", + "APPS_TWITTER_UNREAD_MESSAGES": "You have {{ count }} new tweets in your timeline!", "APPS_BANK_HOME_TITLE": "Welcome", "APPS_BANK_ACCOUNT_LINK": "Account", @@ -110,6 +119,9 @@ "GENERIC_SAVE": "Save", "GENERIC_UPDATE": "Update", "GENERIC_DELETE": "Delete", - "GENERIC_CLOSE": "Close" + "GENERIC_CLOSE": "Close", + "GENERIC_CANCEL": "Cancel", + "GENERIC_TITLE": "Title", + "GENERIC_CONTENT": "Content" } } diff --git a/phone/src/modal/components/CallModal.tsx b/phone/src/modal/components/CallModal.tsx deleted file mode 100644 index 6603f33..0000000 --- a/phone/src/modal/components/CallModal.tsx +++ /dev/null @@ -1,110 +0,0 @@ -import React from 'react'; -import { Fab } from '@material-ui/core'; -import { AppWrapper } from '../../ui/components/AppWrapper'; -import { AppContent } from '../../ui/components/AppContent'; -import { useCall } from '../hooks/useCall'; -import CallIcon from '@material-ui/icons/Call'; -import CallEndIcon from '@material-ui/icons/CallEnd'; -import useStyles from './modal.styles'; -import { useModal } from '../hooks/useModal'; -import Nui from '../../os/nui-events/utils/Nui'; -import CallTimer from './CallTimer'; -import InjectDebugData from '../../os/debug/InjectDebugData'; - -InjectDebugData([ - { - app: 'CALL', - method: 'setCaller', - data: { - accepted: true, - isTransmitter: true, - transmitter: 'Chip', - receiver: 'Taso', - phone_number: '860-4504', - }, - }, -]); - -export const CallModal = () => { - const { call } = useCall(); - const { setModal } = useModal(); - - const classes = useStyles(); - - const handleAcceptCall = () => { - Nui.send('phone:acceptCall', { - transmitterNumber: call.transmitter, - }); - }; - - const handleRejectCall = () => { - setModal(false); - Nui.send('phone:rejectCall', { - phoneNumber: call.transmitter, - }); - }; - - const handleEndCall = () => { - setModal(false); - Nui.send('phone:endCall', { - transmitterNumber: call.transmitter, - }); - }; - - if (call.isTransmitter) { - return ( - - -

{call.receiver}

- -
- - - -
-
-
- ); - } - - return ( - - -

{call.transmitter}

- -
- {!call.accepted ? ( - <> - - - - - - - - ) : ( - - - - )} -
-
-
- ); -}; diff --git a/phone/src/modal/hooks/useCall.ts b/phone/src/modal/hooks/useCall.ts deleted file mode 100644 index 6adc8ea..0000000 --- a/phone/src/modal/hooks/useCall.ts +++ /dev/null @@ -1,13 +0,0 @@ -import { useRecoilState } from 'recoil'; -import { CallProps } from '../../common/typings/call'; -import { callerState } from './state'; - -interface CallHook { - call: CallProps; - setCall: (details: any) => void; -} - -export const useCall = (): CallHook => { - const [call, setCall] = useRecoilState(callerState.currentCall); - return { call, setCall }; -}; diff --git a/phone/src/modal/hooks/useCallService.ts b/phone/src/modal/hooks/useCallService.ts deleted file mode 100644 index 74dbb13..0000000 --- a/phone/src/modal/hooks/useCallService.ts +++ /dev/null @@ -1,11 +0,0 @@ -import { useNuiEvent } from '../../os/nui-events/hooks/useNuiEvent'; -import { useRecoilState, useSetRecoilState } from 'recoil'; -import { callerState } from './state'; - -export const useCallService = () => { - const [caller, setCaller] = useRecoilState(callerState.currentCall); - const setModal = useSetRecoilState(callerState.callModal); - - useNuiEvent('CALL', 'setCaller', setCaller, {}, caller); - useNuiEvent('CALL', 'callModal', setModal); -}; diff --git a/phone/src/os/apps/config/apps.tsx b/phone/src/os/apps/config/apps.tsx index 98320de..4a08f50 100644 --- a/phone/src/os/apps/config/apps.tsx +++ b/phone/src/os/apps/config/apps.tsx @@ -3,10 +3,7 @@ import { blue, common, grey, - green, purple, - yellow, - red, } from '@material-ui/core/colors'; import { FontAwesomeIcon } from '@fortawesome/react-fontawesome'; import { @@ -35,6 +32,7 @@ import { SelloutApp } from '../../../apps/sellout/components/SelloutApp'; import { NotesApp } from '../../../apps/notes/NotesApp'; import CameraApp from '../../../apps/camera/components/CameraApp'; import { AppRoute } from '../components/AppRoute'; + import { MESSAGES_APP_PRIMARY_COLOR, MESSAGES_APP_TEXT_COLOR, @@ -43,6 +41,9 @@ import { CONTACTS_APP_PRIMARY_COLOR, CONTACTS_APP_TEXT_COLOR, } from '../../../apps/contacts/contacts.theme'; +import { SELLOUT_APP_PRIMARY_COLOR, SELLOUT_APP_ICON_COLOR } from '../../../apps/sellout/sellout.theme'; +import { NOTES_APP_ICON_COLOR, NOTES_APP_PRIMARY_COLOR } from '../../../apps/notes/notes.theme'; +import { DIALER_APP_PRIMARY_COLOR, DIALER_APP_TEXT_COLOR } from '../../../apps/dialer/dialer.theme'; export interface IAppConfig { id: string; @@ -59,17 +60,17 @@ export const APPS: IAppConfig[] = [ { id: 'DIALER', nameLocale: 'APPS_DIALER', - icon: , + icon: , notificationIcon: , - backgroundColor: green[600], - color: common.white, + backgroundColor: DIALER_APP_PRIMARY_COLOR, + color: DIALER_APP_TEXT_COLOR, path: '/phone', Route: () => , }, { id: 'MESSAGES', nameLocale: 'APPS_MESSAGES', - icon: , + icon: , notificationIcon: , backgroundColor: MESSAGES_APP_PRIMARY_COLOR, color: MESSAGES_APP_TEXT_COLOR, @@ -81,7 +82,7 @@ export const APPS: IAppConfig[] = [ { id: 'CONTACTS', nameLocale: 'APPS_CONTACTS', - icon: , + icon: , notificationIcon: , backgroundColor: CONTACTS_APP_PRIMARY_COLOR, color: CONTACTS_APP_TEXT_COLOR, @@ -93,7 +94,7 @@ export const APPS: IAppConfig[] = [ { id: 'CALCULATOR', nameLocale: 'APPS_CALCULATOR', - icon: , + icon: , notificationIcon: , backgroundColor: purple[500], color: grey[50], @@ -105,7 +106,7 @@ export const APPS: IAppConfig[] = [ { id: 'SETTINGS', nameLocale: 'APPS_SETTINGS', - icon: , + icon: , notificationIcon: , backgroundColor: '#383838', color: grey[50], @@ -117,7 +118,7 @@ export const APPS: IAppConfig[] = [ { id: 'BANK', nameLocale: 'APPS_BANK', - icon: , + icon: , notificationIcon: , backgroundColor: blue[900], color: common.white, @@ -127,7 +128,7 @@ export const APPS: IAppConfig[] = [ { id: 'TWITTER', nameLocale: 'APPS_TWITTER', - icon: , + icon: , notificationIcon: , backgroundColor: blue[600], color: common.white, @@ -141,8 +142,8 @@ export const APPS: IAppConfig[] = [ nameLocale: 'APPS_SELLOUT', icon: , notificationIcon: , - backgroundColor: red[500], - color: common.white, + backgroundColor: SELLOUT_APP_PRIMARY_COLOR, + color: SELLOUT_APP_ICON_COLOR, path: '/sellout', Route: () => ( @@ -155,8 +156,8 @@ export const APPS: IAppConfig[] = [ notificationIcon: ( ), - backgroundColor: yellow[800], - color: common.white, + backgroundColor: NOTES_APP_PRIMARY_COLOR, + color: NOTES_APP_ICON_COLOR, path: '/notes', Route: () => , }, diff --git a/phone/src/os/call/components/CallControls.tsx b/phone/src/os/call/components/CallControls.tsx new file mode 100644 index 0000000..b766229 --- /dev/null +++ b/phone/src/os/call/components/CallControls.tsx @@ -0,0 +1,76 @@ +import React from 'react'; +import CallIcon from '@material-ui/icons/Call'; +import CallEndIcon from '@material-ui/icons/CallEnd'; +import { useCall } from '../hooks/useCall'; +import { useCallModal } from '../hooks/useCallModal'; +import { StatusIconButton } from '../../../ui/components/StatusIconButton'; +import { Box, makeStyles } from '@material-ui/core'; +import { useHistory } from 'react-router-dom'; + +const useStyles = makeStyles((theme) => ({ + icon: { + color: theme.palette.secondary.contrastText, + }, +})); + +const SIZES_SPACING = { + small: 1, + medium: 3, +}; + +export const CallControls = ({ size }: { size?: 'small' | 'medium' }) => { + const classes = useStyles(); + const history = useHistory(); + const { setModal } = useCallModal(); + const { call, endCall, acceptCall, rejectCall } = useCall(); + + if (!call) { + return null; + } + + const handleAcceptCall = (e) => { + e.stopPropagation(); + history.push('/call'); + acceptCall(); + }; + + const handleRejectCall = (e) => { + e.stopPropagation(); + setModal(false); + rejectCall(); + }; + + const handleEndCall = (e) => { + e.stopPropagation(); + setModal(false); + endCall(); + }; + + const { accepted, isTransmitter } = call; + + if (accepted || isTransmitter) { + return ( + + + + ); + } + return ( + <> + + + + + + + + + + + + ); +}; diff --git a/phone/src/os/call/components/CallModal.tsx b/phone/src/os/call/components/CallModal.tsx new file mode 100644 index 0000000..4a3e390 --- /dev/null +++ b/phone/src/os/call/components/CallModal.tsx @@ -0,0 +1,27 @@ +import React from 'react'; +import { AppWrapper } from '../../../ui/components/AppWrapper'; +import { AppContent } from '../../../ui/components/AppContent'; +import { useCall } from '../hooks/useCall'; +import useStyles from './modal.styles'; +import CallTimer from './CallTimer'; +import { CallControls } from './CallControls'; +import { Box } from '@material-ui/core'; + +export const CallModal = () => { + const classes = useStyles(); + const { call } = useCall(); + + return ( + + + +

{call?.transmitter}

+ +
+
+ +
+
+
+ ); +}; diff --git a/phone/src/os/call/components/CallNotification.tsx b/phone/src/os/call/components/CallNotification.tsx new file mode 100644 index 0000000..e5bca99 --- /dev/null +++ b/phone/src/os/call/components/CallNotification.tsx @@ -0,0 +1,35 @@ +import React from 'react'; +import { Box, makeStyles } from '@material-ui/core'; +import { CallControls } from './CallControls'; + +interface ICallNotificationProps { + onAccept(): void; + onReject(): void; +} + +const useStyles = makeStyles((theme) => ({ + root: { + paddingBottom: '48px', + }, + controls: { + position: 'absolute', + bottom: theme.spacing(1), + right: '4px', + }, +})); + +export const CallNotification = ({ + children, +}: { + children: React.ReactNode; +}) => { + const classes = useStyles(); + return ( +
+ {children} + + + +
+ ); +}; diff --git a/phone/src/modal/components/CallTimer.tsx b/phone/src/os/call/components/CallTimer.tsx similarity index 100% rename from phone/src/modal/components/CallTimer.tsx rename to phone/src/os/call/components/CallTimer.tsx diff --git a/phone/src/modal/components/modal.styles.ts b/phone/src/os/call/components/modal.styles.ts similarity index 95% rename from phone/src/modal/components/modal.styles.ts rename to phone/src/os/call/components/modal.styles.ts index a8482dc..f4da695 100644 --- a/phone/src/modal/components/modal.styles.ts +++ b/phone/src/os/call/components/modal.styles.ts @@ -11,7 +11,7 @@ const useStyles = makeStyles((theme: Theme) => ({ bottom: '10%', }, actionButton: { - margin: 20, + margin: 10, }, })); diff --git a/phone/src/modal/hooks/state.ts b/phone/src/os/call/hooks/state.ts similarity index 100% rename from phone/src/modal/hooks/state.ts rename to phone/src/os/call/hooks/state.ts diff --git a/phone/src/os/call/hooks/useCall.ts b/phone/src/os/call/hooks/useCall.ts new file mode 100644 index 0000000..a09766b --- /dev/null +++ b/phone/src/os/call/hooks/useCall.ts @@ -0,0 +1,36 @@ +import { useRecoilState } from 'recoil'; +import { CallProps } from '../../../common/typings/call'; +import Nui from '../../nui-events/utils/Nui'; +import { callerState } from './state'; + +interface CallHook { + call: CallProps; + setCall: (details: any) => void; + acceptCall(): void; + rejectCall(): void; + endCall(): void; +} + +export const useCall = (): CallHook => { + const [call, setCall] = useRecoilState(callerState.currentCall); + + const acceptCall = () => { + Nui.send('phone:acceptCall', { + transmitterNumber: call.transmitter, + }); + }; + + const rejectCall = () => { + Nui.send('phone:rejectCall', { + phoneNumber: call.transmitter, + }); + }; + + const endCall = () => { + Nui.send('phone:endCall', { + transmitterNumber: call.transmitter, + }); + }; + + return { call, setCall, acceptCall, rejectCall, endCall }; +}; diff --git a/phone/src/modal/hooks/useModal.ts b/phone/src/os/call/hooks/useCallModal.ts similarity index 84% rename from phone/src/modal/hooks/useModal.ts rename to phone/src/os/call/hooks/useCallModal.ts index 3ac7069..89e2624 100644 --- a/phone/src/modal/hooks/useModal.ts +++ b/phone/src/os/call/hooks/useCallModal.ts @@ -6,7 +6,7 @@ interface ModalProps { setModal: (show: boolean) => void; } -export const useModal = (): ModalProps => { +export const useCallModal = (): ModalProps => { const [modal, setModal] = useRecoilState(callerState.callModal); return { modal, setModal } } \ No newline at end of file diff --git a/phone/src/os/call/hooks/useCallService.tsx b/phone/src/os/call/hooks/useCallService.tsx new file mode 100644 index 0000000..65edc18 --- /dev/null +++ b/phone/src/os/call/hooks/useCallService.tsx @@ -0,0 +1,121 @@ +import React, { useEffect, useState } from 'react'; +import { useNuiEvent } from '../../nui-events/hooks/useNuiEvent'; +import { useSetRecoilState } from 'recoil'; +import { callerState } from './state'; +import { useNotifications } from '../../notifications/hooks/useNotifications'; +import { useTranslation } from 'react-i18next'; +import { CallNotification } from '../components/CallNotification'; +import { useCall } from './useCall'; +import { CallProps } from '../../../common/typings/call'; +import { useApp } from '../../apps/hooks/useApps'; +import InjectDebugData from '../../debug/InjectDebugData'; +import { useCallModal } from './useCallModal'; +import { useHistory, useLocation } from 'react-router-dom'; + +const NOTIFICATION_ID = 'call:current'; + +/* InjectDebugData([ + { + app: 'CALL', + method: 'setCaller', + data: { + accepted: false, + isTransmitter: false, + transmitter: 'Chip', + receiver: 'Taso', + active: true, + }, + }, + { + app: 'CALL', + method: 'callModal', + data: true, + }, +]); */ + +export const useCallService = () => { + const { t } = useTranslation(); + const { modal } = useCallModal(); + const history = useHistory(); + const { pathname } = useLocation(); + const { + addNotificationAlert, + removeId, + addNotification, + } = useNotifications(); + + const { call, setCall } = useCall(); + + const { icon, notificationIcon } = useApp('DIALER'); + + const setModal = useSetRecoilState(callerState.callModal); + + const [modalHasBeenOpenedThisCall, setModalOpened] = useState(false); + + const callNotificationBase = { + app: 'CALL', + id: NOTIFICATION_ID, + cantClose: true, + icon, + onClick: () => history.push('/call'), + notificationIcon, + }; + + useEffect(() => { + setModalOpened(!!modal); + }, [modal]); + + useEffect(() => { + if (!modal && pathname === '/call') { + history.replace('/'); + } + if (modal && !modalHasBeenOpenedThisCall && pathname !== '/call') { + history.push('/call'); + } + }, [history, modal, pathname, modalHasBeenOpenedThisCall]); + + const _setCall = (_call: CallProps) => { + setCall(_call); + if (!_call || !_call.active) { + removeId(NOTIFICATION_ID); + return; + } + if (_call.accepted) { + removeId(NOTIFICATION_ID); + addNotification({ + ...callNotificationBase, + content: ( + + {t('APPS_DIALER_CURRENT_CALL_WITH', { + transmitter: _call.transmitter, + })} + + ), + title: t('APPS_DIALER_CURRENT_CALL_TITLE'), + }); + } + if (!_call.isTransmitter && !_call.accepted) { + removeId(NOTIFICATION_ID); + addNotificationAlert( + { + ...callNotificationBase, + title: t('APPS_DIALER_INCOMING_CALL_TITLE', { + transmitter: _call.transmitter, + }), + keepWhenPhoneClosed: true, + content: ( + + {t('APPS_DIALER_TRANSMITTER_IS_CALLING', { + transmitter: _call.transmitter, + })} + + ), + }, + true + ); + } + }; + + useNuiEvent('CALL', 'setCaller', _setCall, call); + useNuiEvent('CALL', 'callModal', setModal); +}; diff --git a/phone/src/modal/hooks/useDuration.ts b/phone/src/os/call/hooks/useDuration.ts similarity index 100% rename from phone/src/modal/hooks/useDuration.ts rename to phone/src/os/call/hooks/useDuration.ts diff --git a/phone/src/os/debug/InjectDebugData.ts b/phone/src/os/debug/InjectDebugData.ts index 87ac94f..ad63348 100644 --- a/phone/src/os/debug/InjectDebugData.ts +++ b/phone/src/os/debug/InjectDebugData.ts @@ -1,7 +1,7 @@ -interface DebugEvent { +interface DebugEvent

{ app: string; method: string; - data: any; + data: P; } // TODO: This should be unit tested @@ -27,7 +27,7 @@ interface DebugEvent { * } * ]) **/ -const InjectDebugData = (events: DebugEvent[], timer = 1000) => { +const InjectDebugData =

(events: DebugEvent

[], timer = 1000) => { if (process.env.NODE_ENV === 'development') { for (const event of events) { setTimeout(() => { diff --git a/phone/src/os/keyboard/hooks/useKeyboard.ts b/phone/src/os/keyboard/hooks/useKeyboardService.ts similarity index 57% rename from phone/src/os/keyboard/hooks/useKeyboard.ts rename to phone/src/os/keyboard/hooks/useKeyboardService.ts index 73c93c7..db45bf9 100644 --- a/phone/src/os/keyboard/hooks/useKeyboard.ts +++ b/phone/src/os/keyboard/hooks/useKeyboardService.ts @@ -1,7 +1,7 @@ -import { useCallback, useEffect } from 'react'; +import { useCallback, useEffect, useRef } from 'react'; import { useHistory } from 'react-router-dom'; import { atom, useSetRecoilState, useRecoilValue } from 'recoil'; -import Nui from '../../nui-events/utils/Nui'; +import { usePhone } from '../../phone/hooks/usePhone'; const keyboardState = { ArrowRight: atom({ @@ -46,8 +46,9 @@ const validKeys = [ const isKeyValid = (key) => validKeys.indexOf(key) !== -1; -export const useInitKeyboard = () => { +export const useKeyboardService = () => { const history = useHistory(); + const { closePhone } = usePhone(); const getters = { ArrowRight: useRecoilValue(keyboardState.ArrowRight), ArrowLeft: useRecoilValue(keyboardState.ArrowLeft), @@ -58,21 +59,26 @@ export const useInitKeyboard = () => { Escape: useRecoilValue(keyboardState.Escape), }; + const handlers = useRef(new Map()); const setEscape = useSetRecoilState(keyboardState.Escape); const setBackspace = useSetRecoilState(keyboardState.Backspace); + useEffect( + function registerCustomKeys() { + Object.keys(getters).forEach((g) => { + handlers.current.set(g, getters[g]); + }); + }, + [getters] + ); + useEffect( function handleNUIKeyboardMessage() { function onKeyUp(event) { const { key } = event; - const callback = getters[key]; - if ( - isKeyValid(key) && - callback && - callback.handler && - callback.handler.call - ) { - return callback.handler(event); + const callback = handlers.current.get(key); + if (isKeyValid(key) && callback && callback.call) { + return callback(event); } } @@ -82,35 +88,22 @@ export const useInitKeyboard = () => { [getters] ); - const escapeHandler = useCallback(() => Nui.send('phone:close'), []); - - const backspaceHandler = useCallback((event) => { - if (['input', 'textarea'].includes(event.target.nodeName.toLowerCase())) { - // Dont anything if we are typing something :) - return; - } - history.goBack(); - }, [history]); + const backspaceHandler = useCallback( + (event) => { + if (['input', 'textarea'].includes(event.target.nodeName.toLowerCase())) { + // Dont anything if we are typing something :) + return; + } + history.goBack(); + }, + [history] + ); useEffect( function registerDefaultHandlers() { - setEscape({ handler: escapeHandler }); - setBackspace({ handler: backspaceHandler }); + handlers.current.set('Escape', () => closePhone()); + handlers.current.set('Backspace', backspaceHandler); }, - [setEscape, setBackspace, history, escapeHandler, backspaceHandler] + [setEscape, setBackspace, history, backspaceHandler, closePhone] ); }; - -export const useKeyboard = () => { - const setters = { - ArrowRight: useSetRecoilState(keyboardState.ArrowRight), - ArrowLeft: useSetRecoilState(keyboardState.ArrowLeft), - ArrowUp: useSetRecoilState(keyboardState.ArrowUp), - ArrowDown: useSetRecoilState(keyboardState.ArrowDown), - Enter: useSetRecoilState(keyboardState.Enter), - }; - - return (key, handler) => { - setters[key]({ handler }); - }; -}; diff --git a/phone/src/os/navigation-bar/components/Navigation.tsx b/phone/src/os/navigation-bar/components/Navigation.tsx index 2fc7ef9..6e9918a 100644 --- a/phone/src/os/navigation-bar/components/Navigation.tsx +++ b/phone/src/os/navigation-bar/components/Navigation.tsx @@ -7,9 +7,9 @@ import { import KeyboardArrowLeftIcon from '@material-ui/icons/KeyboardArrowLeft'; import AppsIcon from '@material-ui/icons/Apps'; import RadioButtonUncheckedIcon from '@material-ui/icons/RadioButtonUnchecked'; -import { useHistory } from 'react-router-dom'; - -import Nui from '../../nui-events/utils/Nui'; +import { useHistory, useRouteMatch } from 'react-router-dom'; +import { usePhone } from '../../phone/hooks/usePhone'; +import { useNotifications } from '../../notifications/hooks/useNotifications'; const useStyles = makeStyles((theme) => ({ root: { @@ -19,17 +19,18 @@ const useStyles = makeStyles((theme) => ({ })); export const Navigation = () => { - const closePhone = () => { - console.log('Phone closed'); - Nui.send('phone:close'); - }; - const classes = useStyles(); const history = useHistory(); + const { isExact } = useRouteMatch('/'); + const { closePhone } = usePhone(); + const { setBarUncollapsed } = useNotifications(); return ( value()} + onChange={(_e, value) => { + setBarUncollapsed(false); + value(); + }} > { /> closePhone()} + value={closePhone} icon={} /> history.goBack()} + value={() => !isExact && history.goBack()} icon={} /> diff --git a/phone/src/os/notifications/components/NotificationAlert.tsx b/phone/src/os/notifications/components/NotificationAlert.tsx new file mode 100644 index 0000000..c7d3044 --- /dev/null +++ b/phone/src/os/notifications/components/NotificationAlert.tsx @@ -0,0 +1,82 @@ +import React from 'react'; +import CloseIcon from '@material-ui/icons/Close'; +import { Box, IconButton, makeStyles, Slide } from '@material-ui/core'; +import { useNotifications } from '../hooks/useNotifications'; +import { Alert, AlertTitle } from '@material-ui/lab'; + +const useStyles = makeStyles((theme) => ({ + snackbar: { + marginTop: '-710px', + display: 'flex', + justifyContent: 'center', + alignItems: 'center', + }, + alert: { + '& .MuiAlert-action': { + top: theme.spacing(1), + right: theme.spacing(2), + position: 'absolute', + }, + position: 'relative', + cursor: 'pointer', + width: '370px', + height: '120px', + zIndex: 50, + backgroundColor: theme.palette.background.paper, + color: theme.palette.text.primary, + '& .MuiAlert-icon': { + color: theme.palette.text.primary, + }, + }, + alertContent: { + display: '-webkit-box', + maxWidth: '360px', + height: '60px', + margin: '0 auto', + '-webkit-line-clamp': 3, + '-webkit-box-orient': 'vertical', + overflow: 'hidden', + textOverflow: 'ellipsis', + }, +})); + +export const NotificationAlert = () => { + const classes = useStyles(); + const { currentAlert } = useNotifications(); + + return ( +

+ + { + e.stopPropagation(); + currentAlert?.onCloseAlert(e); + }} + > + + + } + onClick={(e) => currentAlert?.onClickAlert(e)} + icon={currentAlert?.icon || false} + className={classes.alert} + elevation={6} + > + + + + {currentAlert?.title} + + + + + {currentAlert?.content} + + + +
+ ); +}; diff --git a/phone/src/os/notifications/components/NotificationBar.tsx b/phone/src/os/notifications/components/NotificationBar.tsx index cf4a57d..ec15c8d 100644 --- a/phone/src/os/notifications/components/NotificationBar.tsx +++ b/phone/src/os/notifications/components/NotificationBar.tsx @@ -1,4 +1,4 @@ -import React, { useState } from 'react'; +import React from 'react'; import { makeStyles, Typography, @@ -8,18 +8,14 @@ import { Paper, Box, List, - ListItem, - ListItemText, Divider, - ListItemAvatar, } from '@material-ui/core'; import SignalIcon from '@material-ui/icons/SignalCellular3Bar'; -import CloseIcon from '@material-ui/icons/Close'; import Battery90Icon from '@material-ui/icons/Battery90'; import ArrowDropUpIcon from '@material-ui/icons/ArrowDropUp'; import Default from '../../../config/default.json'; import { useNotifications } from '../hooks/useNotifications'; -import { useHistory } from 'react-router-dom'; +import { NotificationItem } from './NotificationItem'; const useStyles = makeStyles((theme) => ({ root: { @@ -67,13 +63,16 @@ const useStyles = makeStyles((theme) => ({ }, })); -export const NotificationBar = ({ forceUncollapse }: { forceUncollapse: boolean }) => { +export const NotificationBar = () => { const classes = useStyles(); - const history = useHistory(); - const { icons, notifications, removeNotification } = useNotifications(); - - const [uncollapsed, setUncollapsed] = useState(false); + const { + icons, + notifications, + removeNotification, + barUncollapsed, + setBarUncollapsed, + } = useNotifications(); return ( <> @@ -83,7 +82,7 @@ export const NotificationBar = ({ forceUncollapse }: { forceUncollapse: boolean justify='space-between' wrap='nowrap' onClick={() => { - setUncollapsed(!uncollapsed); + setBarUncollapsed((curr) => !curr); }} > @@ -120,41 +119,30 @@ export const NotificationBar = ({ forceUncollapse }: { forceUncollapse: boolean - + - + - {notifications.map(({ href, title, content, icon }, idx) => ( - { - if (href) { - history.push(href); - setUncollapsed(false); + {notifications.map((notification, idx) => ( + { + e.stopPropagation(); + notification.onClose?.(notification); + if (notifications.length === 1) { + setBarUncollapsed(false); + } + removeNotification(idx); + }} + onClickClose={() => { + setBarUncollapsed(false); + if (!notification.cantClose) { removeNotification(idx); } }} - className={classes.notificationItem} - key={idx} - > - {icon && {icon}} - {title} - { - e.stopPropagation(); - if (notifications.length === 1) { - setUncollapsed(false); - } - removeNotification(idx); - }} - > - - - + /> ))} @@ -162,7 +150,7 @@ export const NotificationBar = ({ forceUncollapse }: { forceUncollapse: boolean setUncollapsed(false)} + onClick={() => setBarUncollapsed(false)} > diff --git a/phone/src/os/notifications/components/NotificationItem.tsx b/phone/src/os/notifications/components/NotificationItem.tsx new file mode 100644 index 0000000..602c50e --- /dev/null +++ b/phone/src/os/notifications/components/NotificationItem.tsx @@ -0,0 +1,60 @@ +import React from 'react'; +import CloseIcon from '@material-ui/icons/Close'; +import { + IconButton, + ListItem, + ListItemAvatar, + ListItemText, + makeStyles, + Theme, +} from '@material-ui/core'; +import { INotification } from '../providers/NotificationsProvider'; + +const useStyles = makeStyles((theme) => ({ + closeNotifBtn: { + position: 'absolute', + right: '8px', + top: '8px', + }, + notificationItem: { + paddingRight: ({ cantClose }) => (cantClose ? '8px' : '28px'), + position: 'relative', + }, +})); + +export const NotificationItem = ({ + onClose, + onClickClose, + ...notification +}: INotification & { + onClose: (e: any) => void; + onClickClose: (e: any) => void; +}) => { + const { title, icon, content, cantClose, onClick } = notification; + const classes = useStyles({ cantClose }); + return ( + { + if (onClick) { + onClick(notification); + onClickClose(e); + } + }} + className={classes.notificationItem} + > + {icon && {icon}} + {title} + {!cantClose && ( + + + + )} + + ); +}; diff --git a/phone/src/os/notifications/notifications.constants.ts b/phone/src/os/notifications/notifications.constants.ts new file mode 100644 index 0000000..eaf1909 --- /dev/null +++ b/phone/src/os/notifications/notifications.constants.ts @@ -0,0 +1 @@ +export const DEFAULT_ALERT_HIDE_TIME = 3000; diff --git a/phone/src/os/notifications/providers/NotificationsProvider.tsx b/phone/src/os/notifications/providers/NotificationsProvider.tsx index dacd9c5..05ee812 100644 --- a/phone/src/os/notifications/providers/NotificationsProvider.tsx +++ b/phone/src/os/notifications/providers/NotificationsProvider.tsx @@ -1,14 +1,34 @@ -import React, { createContext, useState, useCallback, useMemo } from 'react'; +import React, { + createContext, + useState, + useCallback, + useMemo, + useRef, + useEffect, +} from 'react'; +import { useRecoilValue } from 'recoil'; +import { phoneState } from '../../phone/hooks/state'; +import { DEFAULT_ALERT_HIDE_TIME } from '../notifications.constants'; export interface INotification { app: string; + id?: string; title: string; content?: React.ReactNode; icon?: JSX.Element; notificationIcon?: JSX.Element; - href?: string; + cantClose?: boolean; + keepWhenPhoneClosed?: boolean; + onClose?: (notification: INotification) => void; + onClick?: (notification: INotification) => void; } +type INotificationAlert = INotification & { + onClickAlert(e?: any): void; + onCloseAlert(e?: any): void; + resolve(): void; +}; + interface INotificationIcon { key: string; icon: JSX.Element; @@ -16,40 +36,164 @@ interface INotificationIcon { } export const NotificationsContext = createContext<{ + barUncollapsed: boolean; + setBarUncollapsed: (v: boolean | ((c: boolean) => boolean)) => void; notifications: INotification[]; + currentAlert: INotificationAlert; icons: INotificationIcon[]; count: number; + removeAlerts(): void; + addOrUpdateNotification(add: INotification, update?: INotification): void; addNotification(value: INotification): void; - updateNotification(idx: number, value: INotification): void; removeNotification(idx: number): void; + updateId(id: string, value: Partial): void; + removeId(id: string): void; + hasNotification(app: string): number; + addNotificationAlert( + n: INotification, + persist: boolean, + update?: Partial + ); }>(null); export function NotificationsProvider({ children }) { + const isPhoneOpen = useRecoilValue(phoneState.visibility); + + const [barUncollapsed, setBarUncollapsed] = useState(false); + const [notifications, setNotifications] = useState([]); + const alertTimeout = useRef(); + const [alerts, setAlerts] = useState< + Array<[INotification, boolean, Partial]> + >([]); + const [currentAlert, setCurrentAlert] = useState(); + + useEffect(() => { + if (isPhoneOpen && currentAlert && currentAlert.keepWhenPhoneClosed) { + currentAlert.resolve(); + } + }, [isPhoneOpen, currentAlert]); + const updateNotification = useCallback( (idx: number, value: INotification) => { setNotifications((all) => { const updated = [...all]; - updated.splice(idx, 0, value); + updated.splice(idx, 1, value); return updated; }); }, [] ); - const removeNotification = useCallback((idx) => { + const removeNotification = (idx) => { setNotifications((all) => { - const updated = [...all]; + const updated = all; updated.splice(idx, 1); - return updated; + return [...updated]; }); - }, []); + }; const addNotification = useCallback((value: INotification) => { setNotifications((all) => [value, ...all]); }, []); + /** + * Checks if a notification exists for current app + * and returns its index or -1 if not found. + */ + const hasNotification = useCallback( + (appId: string): number => { + return notifications.findIndex((n) => n.app === appId); + }, + [notifications] + ); + + const addOrUpdateNotification = useCallback( + (add: INotification, update?: INotification) => { + const exists = hasNotification(add.app); + if (update && exists !== -1) { + updateNotification(exists, update); + return; + } + addNotification(add); + }, + [addNotification, hasNotification, updateNotification] + ); + + const _showAlert = useCallback( + (n: INotification, persist: boolean, update: Partial) => { + return new Promise((res) => { + const resolve = () => { + if (persist) { + addOrUpdateNotification(n, update ? { ...n, ...update } : null); + } + res(); + }; + + const onExit = (cb) => () => { + cb?.(n); + clearTimeout(alertTimeout.current); + resolve(); + }; + + setCurrentAlert({ + ...n, + resolve, + onClickAlert: onExit(n.onClick), + onCloseAlert: onExit(n.onClose), + }); + + if (n.keepWhenPhoneClosed) { + return; + } + + alertTimeout.current = setTimeout(() => { + resolve(); + // If you change or remove the 300 i'll kill your pet - Kidz /s + // Really, this makes it work nicely with usePhoneVisibility :) + }, DEFAULT_ALERT_HIDE_TIME + 300); + }); + }, + [addOrUpdateNotification] + ); + + const addNotificationAlert = ( + n: INotification, + persist?: boolean, + update?: Partial + ) => { + setAlerts((curr) => [...curr, [n, persist, update]]); + }; + + const removeId = (id: string) => { + const idx = notifications.findIndex((n) => n.id === id); + if (idx !== -1) { + removeNotification(idx); + } + }; + + const updateId = (id: string, value: Partial) => { + const idx = notifications.findIndex((n) => n.id === id); + if (idx !== -1) { + const curr = { ...notifications[idx], ...value }; + updateNotification(idx, curr); + } + }; + + useEffect(() => { + if (!currentAlert && alerts.length) { + _showAlert(...alerts[0]).then(() => { + setAlerts((curr) => { + const newQueue = curr; + curr.shift(); + return newQueue; + }); + setCurrentAlert(null); + }); + } + }, [_showAlert, alerts, currentAlert]); + const icons: INotificationIcon[] = useMemo( () => notifications.reduce((icons, curr) => { @@ -64,13 +208,26 @@ export function NotificationsProvider({ children }) { [notifications] ); + const removeAlerts = () => { + setAlerts([]); + setCurrentAlert(null); + }; + return ( >( app: string, method: string, handler: Function, - options: IOptions = {}, - currentState?: Record + currentState?: S, + options: IOptions = defaultOptions ) => { - const savedHandler: MutableRefObject = useRef(); - // Destructure passed options - const { capture, passive, once } = options; // When handler value changes set mutable ref to handler val useEffect(() => { @@ -44,15 +43,13 @@ export const useNuiEvent = ( data: event.data, level: 1, }); - const newData = currentState ? { ...currentState, ...data } : data - savedHandler.current(newData) + const newData = currentState ? { ...currentState, ...data } : data; + savedHandler.current(newData); } }; - // Why are destructing then restructuring option data? - const opts = { capture, passive, once }; - window.addEventListener(eventName, eventListener, opts); + window.addEventListener(eventName, eventListener, options); // Remove Event Listener on component cleanup - return () => window.removeEventListener(eventName, eventListener, opts); - }, [app, method, capture, passive, once, currentState]); + return () => window.removeEventListener(eventName, eventListener, options); + }, [app, method, currentState, options]); }; diff --git a/phone/src/os/phone/hooks/usePhone.ts b/phone/src/os/phone/hooks/usePhone.ts index fee582e..b511a69 100644 --- a/phone/src/os/phone/hooks/usePhone.ts +++ b/phone/src/os/phone/hooks/usePhone.ts @@ -1,15 +1,29 @@ -import { useRecoilState } from 'recoil'; -import { phoneState } from './state'; +import { useRecoilValue } from 'recoil'; import { IServerConfig } from '../../../common/typings/config'; import ServerConfig from '../../../config.autogen.json'; +import { useNotifications } from '../../notifications/hooks/useNotifications'; +import Nui from '../../nui-events/utils/Nui'; +import { phoneState } from './state'; interface IUsePhone { - visibility: boolean; - setVisibility(v: boolean): void; config?: IServerConfig; + openPhone(): void; + closePhone(): void; + isPhoneOpen: boolean; } export const usePhone = (): IUsePhone => { - const [visibility, setVisibility] = useRecoilState(phoneState.visibility); - return { visibility, setVisibility, config: ServerConfig as any }; + const isPhoneOpen = useRecoilValue(phoneState.visibility); + + const { removeAlerts } = useNotifications(); + + const closePhone = () => { + removeAlerts(); + Nui.send('phone:close'); + }; + const openPhone = () => { + Nui.send('phone:open'); + }; + + return { config: ServerConfig as any, closePhone, openPhone, isPhoneOpen }; }; diff --git a/phone/src/os/phone/hooks/usePhoneVisibility.ts b/phone/src/os/phone/hooks/usePhoneVisibility.ts index 6d73edb..e279dfa 100644 --- a/phone/src/os/phone/hooks/usePhoneVisibility.ts +++ b/phone/src/os/phone/hooks/usePhoneVisibility.ts @@ -1,56 +1,50 @@ -import { useCallback, useEffect, useMemo, useRef, useState } from 'react'; +import { useEffect, useMemo, useRef, useState } from 'react'; +import { useRecoilState } from 'recoil'; import { useSettings } from '../../../apps/settings/hooks/useSettings'; import { useNotifications } from '../../notifications/hooks/useNotifications'; -import { usePhone } from './usePhone'; +import { DEFAULT_ALERT_HIDE_TIME } from '../../notifications/notifications.constants'; +import { phoneState } from './state'; export const usePhoneVisibility = () => { - const { setVisibility, visibility } = usePhone(); - const { count } = useNotifications(); + const [visibility, setVisibility] = useRecoilState(phoneState.visibility); + const { currentAlert } = useNotifications(); const [{ zoom }] = useSettings(); const [notifVisibility, setNotifVisibility] = useState(false); - const isNotificationVisibleOnly = useMemo( - () => !!(!visibility && count > 0), - [visibility, count] - ); - const notificationTimer = useRef(); useEffect(() => { - if (isNotificationVisibleOnly) { - setNotifVisibility(true); - clearTimeout(notificationTimer.current); - notificationTimer.current = setTimeout(() => { - setVisibility(false); - setNotifVisibility(false); - }, 5000); + if (visibility) { + setNotifVisibility(false); } - return () => clearTimeout(notificationTimer.current); - }, [isNotificationVisibleOnly, setVisibility]); + }, [visibility]); + + useEffect(() => { + if (!visibility && currentAlert) { + setNotifVisibility(true); + if (notificationTimer.current) { + clearTimeout(notificationTimer.current); + notificationTimer.current = undefined; + } + if (currentAlert?.keepWhenPhoneClosed) { + return; + } + notificationTimer.current = setTimeout(() => { + setNotifVisibility(false); + }, DEFAULT_ALERT_HIDE_TIME); + } + }, [currentAlert, visibility, setVisibility]); const bottom = useMemo(() => { - if (isNotificationVisibleOnly) { - return `calc(-60% * ${zoom})`; + if (!visibility) { + return `calc(-70% * ${zoom})`; } return 0; - }, [isNotificationVisibleOnly, zoom]); - - const clickEventOverride = useCallback( - (e) => { - if (isNotificationVisibleOnly) { - e.preventDefault(); - e.stopPropagation(); - setVisibility(true); - } - }, - [setVisibility, isNotificationVisibleOnly] - ); + }, [visibility, zoom]); return { bottom, visibility: notifVisibility || visibility, - uncollapseNotifications: isNotificationVisibleOnly, - clickEventOverride, }; }; diff --git a/phone/src/os/phone/hooks/useSound.ts b/phone/src/os/phone/hooks/useSound.ts index 27efa1c..e1cf491 100644 --- a/phone/src/os/phone/hooks/useSound.ts +++ b/phone/src/os/phone/hooks/useSound.ts @@ -13,70 +13,75 @@ interface ISoundOptions { * * @param { volume, interrupt, loop} Additional options **/ - const useSound = ( url: string, { volume = 1, interrupt = false, loop = false }: ISoundOptions = {} ) => { - const isMounted = useRef(false); + const [isMounted, setMounted] = useState(false); + const soundRef = useRef(null); const [playing, setPlaying] = useState(false); - const [sound, setSound] = useState(null); - // Mount & Dismount handling useEffect(() => { - isMounted.current = true; - const sound = new Howl({ + soundRef.current?.unload(); + setPlaying(false); + setMounted(false); + + soundRef.current = new Howl({ src: url, - volume, - loop, + volume: 1, + loop: false, }); - setSound(sound); + + setMounted(true); return () => { - isMounted.current = false; + soundRef.current?.unload(); + soundRef.current = undefined; }; - // eslint-disable-next-line react-hooks/exhaustive-deps - }, []); + }, [url]); useEffect(() => { - if (sound) { - sound.volume(volume); + if (isMounted) { + soundRef.current.volume(volume); } - // Shouldnt need to rerun if sound changes - // eslint-disable-next-line react-hooks/exhaustive-deps - }, [volume]); + }, [volume, isMounted]); + + useEffect(() => { + if (isMounted) { + soundRef.current.loop(loop); + } + }, [loop, isMounted]); const play = useCallback(() => { - if (!sound) return; + if (!soundRef.current) return; - if (interrupt) return sound.stop(); - - sound.play(); - - if (isMounted.current) { - sound.once('end', () => { - if (!sound.playing()) { + if (isMounted) { + soundRef.current.play(); + soundRef.current.once('end', () => { + if (!soundRef.current.playing()) { setPlaying(false); } }); - } - - if (isMounted.current) { setPlaying(true); } - }, [interrupt, sound]); + }, [isMounted]); const stop = useCallback(() => { - if (!sound) return; + if (!soundRef.current) return; - sound.stop(); - - if (isMounted.current) { + if (isMounted) { + soundRef.current.stop(); setPlaying(false); } - }, [sound]); + }, [isMounted]); + + useEffect(() => { + if (interrupt && isMounted) { + stop(); + } + }, [interrupt, isMounted, stop]); return { play, playing, stop }; }; diff --git a/phone/src/ui/components/Alert.tsx b/phone/src/ui/components/Alert.tsx index 697fb4c..edfd7f7 100644 --- a/phone/src/ui/components/Alert.tsx +++ b/phone/src/ui/components/Alert.tsx @@ -1,8 +1,30 @@ import React from 'react'; import MuiAlert from '@material-ui/lab/Alert'; +import { makeStyles, Typography } from '@material-ui/core'; -export function Alert(props) { - return ; +const useStyles = makeStyles({ + root: { + zIndex: 10000, + }, + msg: { + maxWidth: '300px', + wordWrap: 'break-word', + fontSize: '1em' + }, +}); + +export function Alert({ children, ...props }) { + const classes = useStyles(); + return ( + + {children} + + ); } export default Alert; diff --git a/phone/src/ui/components/AppContent.tsx b/phone/src/ui/components/AppContent.tsx index 5fb88af..579c2f3 100644 --- a/phone/src/ui/components/AppContent.tsx +++ b/phone/src/ui/components/AppContent.tsx @@ -1,5 +1,5 @@ import React from 'react'; -import { Box, makeStyles, Backdrop, Paper } from '@material-ui/core'; +import { Box, makeStyles, Backdrop, Paper, BoxProps } from '@material-ui/core'; import { AppContentTypes } from '../interface/InterfaceUI'; const useStyles = makeStyles(() => ({ @@ -29,7 +29,7 @@ export const AppContent = ({ backdrop, onClickBackdrop, ...props -}: AppContentTypes) => { +}: AppContentTypes & BoxProps) => { const classes = useStyles(); return ( diff --git a/phone/src/ui/components/AppIcon.tsx b/phone/src/ui/components/AppIcon.tsx index e1b9b7d..1bfd94d 100644 --- a/phone/src/ui/components/AppIcon.tsx +++ b/phone/src/ui/components/AppIcon.tsx @@ -1,56 +1,68 @@ import React from 'react'; -import { makeStyles } from '@material-ui/core/styles'; +import { fade, makeStyles, Theme } from '@material-ui/core/styles'; import Avatar from '@material-ui/core/Avatar'; import { green } from '@material-ui/core/colors'; -import { Badge, Button } from '@material-ui/core'; +import { Badge, Button, Tooltip, Zoom } from '@material-ui/core'; +import { useTranslation } from 'react-i18next'; -interface IStyles { - root: any; - avatar: any; -} - -const useStyles = makeStyles( - (theme): IStyles => ({ +const useStyles = makeStyles( + (theme) => ({ root: { - display: 'flex', - '& > *': { - margin: theme.spacing(1), - }, padding: 0, + marginTop: theme.spacing(3), }, avatar: { + '&:hover': { + backgroundColor: ({ backgroundColor }) => fade(backgroundColor, 0.6), + }, backgroundColor: ({ backgroundColor }) => backgroundColor, color: ({ color }) => color, - width: theme.spacing(7), - height: theme.spacing(7), + boxShadow: theme.shadows[2], + width: theme.spacing(8), + height: theme.spacing(8), fontSize: theme.typography.h4.fontSize, }, + tooltip: { + fontSize: 12, + }, }) ); export const AppIcon = ({ + id, + nameLocale, name, icon, backgroundColor, color, notification, }) => { + const { t } = useTranslation(); const classes = useStyles({ backgroundColor: backgroundColor || green[50], color: color || green[400], }); return ( - + + + ); }; diff --git a/phone/src/ui/components/GridMenu.tsx b/phone/src/ui/components/GridMenu.tsx index df9610c..f18c5c9 100644 --- a/phone/src/ui/components/GridMenu.tsx +++ b/phone/src/ui/components/GridMenu.tsx @@ -1,61 +1,32 @@ -import React, { useEffect } from 'react'; +import React from 'react'; import { AppIcon } from './AppIcon'; -import { useTranslation } from 'react-i18next'; -import { Grid, makeStyles, Tooltip, Zoom } from '@material-ui/core'; +import { Box, Grid } from '@material-ui/core'; import { Link } from 'react-router-dom'; -import { useKeyboard } from '../../os/keyboard/hooks/useKeyboard'; -const useStyles = makeStyles((theme) => ({ - root: { - marginTop: theme.spacing(3), - }, - item: { - marginTop: theme.spacing(3), - width: '20%', - }, - tooltip: { - fontSize: 12, - }, -})); - -export const GridMenu = ({ items, Component = AppIcon }) => { - const setKey = useKeyboard(); - const classes = useStyles(); - const { t } = useTranslation(); - - useEffect(function registerKeyHandlers() { - setKey('ArrowLeft', () => { - console.log(':v'); - }); - // eslint-disable-next-line - }, []); - // TODO: Fix tooltip position to be closer to app icon +export const GridMenu = ({ + items, + Component = AppIcon, + xs = undefined, +}) => { return ( - - - {items && - items.length && - items.map((item) => ( - - + + {items && + items.length && + items.map((item) => ( + + + - - - ))} - + + + + ))} ); }; diff --git a/phone/src/ui/components/StatusButton.tsx b/phone/src/ui/components/StatusButton.tsx new file mode 100644 index 0000000..01e11f9 --- /dev/null +++ b/phone/src/ui/components/StatusButton.tsx @@ -0,0 +1,58 @@ +import { Button, ButtonProps, fade, makeStyles } from '@material-ui/core'; +import React from 'react'; + +type StatusButtonStyleColor = 'success' | 'error' | 'warning' | 'info'; + +interface IStatusButtonStyleProps { + color: StatusButtonStyleColor; +} + +const useStyles = makeStyles( + (theme) => ({ + root: { + color: ({ color }: IStatusButtonStyleProps) => theme.palette[color].main, + '&:hover': { + backgroundColor: ({ color }: IStatusButtonStyleProps) => + fade(theme.palette[color].light, theme.palette.action.hoverOpacity), + }, + }, + outlined: { + border: ({ color }: IStatusButtonStyleProps) => + `1px solid ${fade(theme.palette[color].main, 0.5)}`, + '&:hover': { + border: ({ color }: IStatusButtonStyleProps) => + `1px solid ${theme.palette[color].main}`, + }, + '&$disabled': { + border: `1px solid ${theme.palette.action.disabled}`, + }, + }, + contained: { + color: ({ color }: IStatusButtonStyleProps) => + theme.palette[color].contrastText, + backgroundColor: ({ color }: IStatusButtonStyleProps) => + theme.palette[color].main, + '&:hover': { + backgroundColor: ({ color }: IStatusButtonStyleProps) => + theme.palette[color].dark, + }, + }, + }), + { name: 'MuiButton' } +); + +export const StatusButton = ({ + color = 'info', + variant, + className, + ...props +}: Omit & { color: StatusButtonStyleColor }) => { + const classes = useStyles({ color }); + return ( +