diff --git a/phone/src/Phone.tsx b/phone/src/Phone.tsx
index ebcbf47..1b395fa 100644
--- a/phone/src/Phone.tsx
+++ b/phone/src/Phone.tsx
@@ -3,6 +3,7 @@ import './Phone.css';
import './i18n';
import { Route } from 'react-router-dom';
import { CallModal } from './modal/components/CallModal';
+import { Alert } from './ui/components/Alert';
import { HomeApp } from './apps/home/components/Home';
import { createMuiTheme, ThemeProvider } from '@material-ui/core';
import { useInitKeyboard } from './os/keyboard/hooks/useKeyboard';
@@ -32,6 +33,8 @@ import { useModal } from './modal/hooks/useModal';
import { useDialService } from './apps/dialer/hooks/useDialService';
import InjectDebugData from './os/debug/InjectDebugData';
import { useQuickAccess } from './os/notifications/hooks/useQuickAccess';
+import { useSnackbar } from './ui/hooks/useSnackbar';
+import { useTranslation } from 'react-i18next';
function Phone() {
const quickAccess = useQuickAccess();
@@ -50,6 +53,9 @@ function Phone() {
usePhotoService();
useCallService();
useDialService();
+ const { t } = useTranslation()
+
+ const { alert } = useSnackbar();
const { modal } = useModal(); // the calling modal
@@ -106,16 +112,28 @@ function Phone() {
}))}
/>
- {modal ? (
-
- ) : (
- <>
-
- {allApps.map((App) => (
-
- ))}
- >
- )}
+ {modal ? (
+
+ ) : (
+ <>
+
+ {allApps.map((App) => (
+
+ ))}
+ >
+ )}
+ {alert ? (
+
+
+ {t("APPS_"+alert.message)}
+
+
+ ) : null}
>
diff --git a/phone/src/apps/contacts/components/alert/ContactAlert.tsx b/phone/src/apps/contacts/components/alert/ContactAlert.tsx
deleted file mode 100644
index a0b467c..0000000
--- a/phone/src/apps/contacts/components/alert/ContactAlert.tsx
+++ /dev/null
@@ -1,65 +0,0 @@
-import { Snackbar } from '@material-ui/core';
-import React, { useState, useEffect, useCallback } from 'react';
-import { useTranslation } from 'react-i18next';
-import { Alert } from '../../../../ui/components/Alert';
-import { useContactAlert } from '../../hooks/useAlert';
-import { AlertCategory } from '../../../../common/typings/contact';
-
-// Used as a prefix for referencing the locales
-// Needed to make code cleaner
-const LOCALE_PREFIX = 'APPS_';
-
-export const ContactAlert = () => {
- const { t } = useTranslation();
- const { alert, setAlert } = useContactAlert();
- const [open, setOpen] = useState(false);
- const [message, setMessage] = useState(null);
- const [severity, setSeverity] = useState('');
-
- const _handleClose = () => {
- setOpen(false);
- setAlert(null);
- };
-
- const setMessageAlert = useCallback((type: AlertCategory, severity: 'success' | 'error') => {
- setMessage(t(LOCALE_PREFIX + type));
- setSeverity(severity);
- setOpen(true);
- }, [t]);
-
- useEffect(() => {
- switch (alert) {
- case 'CONTACT_ADD_FAILED':
- setMessageAlert(alert, 'error');
- break;
- case 'CONTACT_ADD_SUCCESS':
- setMessageAlert(alert, 'success');
- break;
- case 'CONTACT_DELETE_FAILED':
- setMessageAlert(alert, 'error');
- break;
- case 'CONTACT_DELETE_SUCCESS':
- setMessageAlert(alert, 'success');
- break;
- case 'CONTACT_UPDATE_FAILED':
- setMessageAlert(alert, 'error');
- break;
- case 'CONTACT_UPDATE_SUCCESS':
- setMessageAlert(alert, 'success');
- break;
- }
- }, [alert, setMessageAlert]);
-
- return (
-
-
- {message}
-
-
- );
-};
diff --git a/phone/src/apps/example/components/ExampleApp.tsx b/phone/src/apps/example/components/ExampleApp.tsx
index 2889c9e..a5c3dc1 100644
--- a/phone/src/apps/example/components/ExampleApp.tsx
+++ b/phone/src/apps/example/components/ExampleApp.tsx
@@ -5,14 +5,16 @@ import { AppTitle } from '../../../ui/components/AppTitle';
import { AppContent } from '../../../ui/components/AppContent';
import { useApp } from '../../../os/apps/hooks/useApps';
import { useExample } from '../hooks/useExample';
+import { useSnackbar } from '../../../ui/hooks/useSnackbar';
+import SnackbarProvider from '../../../ui/components/SnackbarProvider';
export const ExampleApp = () => {
// calling the example hook, and we assign the value to a variable
+
const exampleString = useExample();
const example = useApp('EXAMPLE');
return (
-
This is an example
{/* Here we are using the value in a h3 tag */}
diff --git a/phone/src/apps/notes/NotesApp.tsx b/phone/src/apps/notes/NotesApp.tsx
index 8875d82..8a880e8 100644
--- a/phone/src/apps/notes/NotesApp.tsx
+++ b/phone/src/apps/notes/NotesApp.tsx
@@ -1,4 +1,4 @@
-import React from 'react';
+import React, { useEffect } from 'react';
import { AppWrapper } from '../../ui/components/AppWrapper';
import { AppContent } from '../../ui/components/AppContent';
import { AppTitle } from '../../ui/components/AppTitle';
@@ -15,7 +15,6 @@ import { useNoteDetail } from './hooks/useNoteDetail';
import useStyles from './notes.styles';
import InjectDebugData from '../../os/debug/InjectDebugData';
-import { NotesAlert } from './alert/NotesAlert';
InjectDebugData([
{
@@ -66,7 +65,6 @@ export const NotesApp = () => {
>
-
);
};
diff --git a/phone/src/apps/notes/alert/NotesAlert.tsx b/phone/src/apps/notes/alert/NotesAlert.tsx
deleted file mode 100644
index c760082..0000000
--- a/phone/src/apps/notes/alert/NotesAlert.tsx
+++ /dev/null
@@ -1,62 +0,0 @@
-import React, { useState, useEffect, useCallback } from 'react'
-import { Snackbar } from '@material-ui/core';
-import { Alert } from '../../../ui/components/Alert';
-import { AlertCategory } from '../../../common/typings/notes';
-import { useTranslation } from 'react-i18next';
-import { useNotesAlert } from '../hooks/useNoteAlert';
-
-const LOCALE_PREFIX = 'APPS_';
-
-export const NotesAlert = () => {
- const { t } = useTranslation();
- const [open, setOpen] = useState(false);
- const { alert, setAlert } = useNotesAlert();
- const [message, setMessage] = useState(null);
- const [severity, setSeverity] = useState('');
-
- const _handleClose = () => {
- setOpen(false)
- setAlert(null)
- }
-
- const setMessageAlert = useCallback((type: AlertCategory, severity: 'success' | 'error') => {
- setMessage(t(LOCALE_PREFIX + type));
- setSeverity(severity)
- setOpen(true)
- }, [t])
-
- useEffect(() => {
- switch (alert) {
- case 'NOTES_ADD_SUCCESS':
- setMessageAlert(alert, 'success');
- break;
- case 'NOTES_ADD_FAILED':
- setMessageAlert(alert, 'error');
- break;
- case 'NOTES_UPDATE_SUCCESS':
- setMessageAlert(alert, 'success');
- break;
- case 'NOTES_UPDATE_FAILED':
- setMessageAlert(alert, 'error');
- break;
- case 'NOTES_DELETE_SUCCESS':
- setMessageAlert(alert, 'success');
- break;
- case 'NOTES_DELETE_FAILED':
- setMessageAlert(alert, 'error')
- }
- }, [alert, setMessageAlert])
-
- return (
-
-
- {message}
-
-
- )
-}
diff --git a/phone/src/apps/notes/hooks/useNoteAlert.ts b/phone/src/apps/notes/hooks/useNoteAlert.ts
deleted file mode 100644
index ba081b2..0000000
--- a/phone/src/apps/notes/hooks/useNoteAlert.ts
+++ /dev/null
@@ -1,8 +0,0 @@
-import { useRecoilState } from 'recoil';
-import { INotesAlert } from '../../../common/typings/notes';
-import { noteStates } from './state';
-
-export const useNotesAlert = (): INotesAlert => {
- const [alert, setAlert] = useRecoilState(noteStates.alert)
- return { alert, setAlert }
-}
\ No newline at end of file
diff --git a/phone/src/apps/notes/hooks/useNotesService.ts b/phone/src/apps/notes/hooks/useNotesService.ts
index c4356c4..dfe627b 100644
--- a/phone/src/apps/notes/hooks/useNotesService.ts
+++ b/phone/src/apps/notes/hooks/useNotesService.ts
@@ -1,13 +1,16 @@
+
+import { createContext, useCallback } from 'react';
import { useSetRecoilState } from 'recoil';
import { useNuiEvent } from '../../../os/nui-events/hooks/useNuiEvent';
import { useNotes } from './useNotes';
import { noteStates } from './state';
-import { useNotesAlert } from './useNoteAlert';
+import { useSnackbar } from '../../../ui/hooks/useSnackbar';
export const useNotesService = () => {
+ const { addAlert } = useSnackbar()
const setNotes = useSetRecoilState(noteStates.noteItems);
- const setAlert = useSetRecoilState(noteStates.alert);
+
useNuiEvent('NOTES', 'setNotes', setNotes);
- useNuiEvent('NOTES', 'setAlert', setAlert)
- return { useNotes, useNotesAlert };
+ useNuiEvent('NOTES', 'setAlert', addAlert)
+ return useNotes();
};
diff --git a/phone/src/index.tsx b/phone/src/index.tsx
index 8d5a152..8d1fcef 100644
--- a/phone/src/index.tsx
+++ b/phone/src/index.tsx
@@ -10,6 +10,7 @@ import Phone from './Phone';
import TwitterNotification from './apps/twitter/components/notification/TwitterNotification';
import { BankNotification } from './apps/bank/components/notification/BankNotification';
import PhoneConfig from './config/default.json';
+import SnackbarProvider from './ui/components/SnackbarProvider';
// Enable Sentry when config setting is true
if (PhoneConfig.SentryErrorMetrics) {
@@ -29,7 +30,9 @@ ReactDOM.render(
-
+
+
+
,
document.getElementById('root')
diff --git a/phone/src/os/nui-events/hooks/useNuiEvent.ts b/phone/src/os/nui-events/hooks/useNuiEvent.ts
index 5897bf4..38521f4 100644
--- a/phone/src/os/nui-events/hooks/useNuiEvent.ts
+++ b/phone/src/os/nui-events/hooks/useNuiEvent.ts
@@ -23,6 +23,7 @@ export const useNuiEvent = (
options: IOptions = {},
currentState?: Record
) => {
+
const savedHandler: MutableRefObject = useRef();
// Destructure passed options
const { capture, passive, once } = options;
diff --git a/phone/src/ui/components/Alert.tsx b/phone/src/ui/components/Alert.tsx
index 103e28b..697fb4c 100644
--- a/phone/src/ui/components/Alert.tsx
+++ b/phone/src/ui/components/Alert.tsx
@@ -2,7 +2,7 @@ import React from 'react';
import MuiAlert from '@material-ui/lab/Alert';
export function Alert(props) {
- return ;
+ return ;
}
export default Alert;
diff --git a/phone/src/ui/components/SnackbarProvider.tsx b/phone/src/ui/components/SnackbarProvider.tsx
new file mode 100644
index 0000000..46ce55c
--- /dev/null
+++ b/phone/src/ui/components/SnackbarProvider.tsx
@@ -0,0 +1,33 @@
+import React, { createContext, useState, useEffect, useRef } from 'react';
+
+export const SnackbarContext = createContext(null);
+
+function SnackbarProvider({ children }) {
+ const [alert, setAlert] = useState(null);
+ const timer = useRef(null);
+
+ useEffect(() => {
+ if (alert) {
+ clearTimeout(timer.current)
+ timer.current = setTimeout(() => {
+ setAlert(null)
+ }, 1000);
+ }
+ return () => clearTimeout(timer.current)
+ }, [alert]);
+
+
+ const addAlert = (value) => setAlert(value);
+
+ const value = { addAlert, alert }
+
+ return (
+
+ <>
+ {children}
+ >
+
+ )
+}
+
+export default SnackbarProvider;
\ No newline at end of file
diff --git a/phone/src/ui/hooks/useSnackbar.ts b/phone/src/ui/hooks/useSnackbar.ts
new file mode 100644
index 0000000..7433cc6
--- /dev/null
+++ b/phone/src/ui/hooks/useSnackbar.ts
@@ -0,0 +1,15 @@
+import { useContext } from 'react';
+import { SnackbarContext } from '../components/SnackbarProvider';
+
+
+export interface IAlert {
+ message: string;
+ type: 'success' | 'error'
+}
+
+interface ISnackBar {
+ addAlert: ({ message, type}: IAlert) => void;
+ alert: IAlert | null;
+}
+
+export const useSnackbar = (): ISnackBar => useContext(SnackbarContext);
\ No newline at end of file
diff --git a/phone/src/ui/interface/InterfaceUI.ts b/phone/src/ui/interface/InterfaceUI.ts
index eb5f670..5f655bd 100644
--- a/phone/src/ui/interface/InterfaceUI.ts
+++ b/phone/src/ui/interface/InterfaceUI.ts
@@ -12,4 +12,4 @@ export interface AppWrapperTypes {
children?: JSX.Element | JSX.Element[];
style?: CSSProperties;
handleClickAway?: (...args: any[]) => void;
-}
+}
\ No newline at end of file
diff --git a/resources/client/cl_notes.ts b/resources/client/cl_notes.ts
index 7547036..c7355a5 100644
--- a/resources/client/cl_notes.ts
+++ b/resources/client/cl_notes.ts
@@ -31,7 +31,6 @@ onNet(events.NOTE_UPDATE_NOTE_SUCCESS, () => {
});
-onNet(events.NOTE_ACTION_RESULT, (type: string) => {
- console.log(type)
- sendNotesEvent('setAlert', type)
+onNet(events.NOTE_ACTION_RESULT, (alert: any) => {
+ sendNotesEvent('setAlert', alert)
})
\ No newline at end of file
diff --git a/resources/server/sv_notes.ts b/resources/server/sv_notes.ts
index 7e316fc..053e36a 100644
--- a/resources/server/sv_notes.ts
+++ b/resources/server/sv_notes.ts
@@ -33,11 +33,11 @@ onNet(events.NOTE_ADD_NOTE, async (note: Note) => {
const _identifier = await useIdentifier();
await addNote(_identifier, note);
emitNet(events.NOTE_SEND_NOTE_SUCCESS, pSource);
- emitNet(events.NOTE_ACTION_RESULT, pSource, 'NOTES_ADD_SUCCESS')
+ emitNet(events.NOTE_ACTION_RESULT, pSource, { message: 'NOTES_ADD_SUCCESS', type: 'success' })
} catch (error) {
const pSource = (global as any).source
- emitNet(events.NOTE_ACTION_RESULT, pSource, 'NOTES_ADD_FAILED')
+ emitNet(events.NOTE_ACTION_RESULT, pSource, { message: 'NOTES_ADD_FAILED', type: 'error' })
}
});
@@ -59,11 +59,11 @@ onNet(events.NOTE_DELETE_NOTE, async (noteId: NoteId) => {
const _identifier = await useIdentifier();
await deleteNote(noteId.id, _identifier);
- emitNet(events.NOTE_ACTION_RESULT, pSource, 'NOTES_DELETE_SUCCESS')
-
+ emitNet(events.NOTE_ACTION_RESULT, pSource, { message: 'NOTES_DELETE_SUCCESS', type: 'success' })
+
} catch (error) {
const pSource = (global as any).source;
- emitNet(events.NOTE_ACTION_RESULT, pSource, 'NOTES_DELETE_FAILED')
+ emitNet(events.NOTE_ACTION_RESULT, pSource, { message: 'NOTES_DELETE_FAILED', type: 'error' })
}
});
@@ -73,11 +73,12 @@ onNet(events.NOTE_UPDATE_NOTE, async (note: Note) => {
const _identifier = await useIdentifier();
await updateNote(note, _identifier);
emitNet(events.NOTE_UPDATE_NOTE_SUCCESS, pSource);
- emitNet(events.NOTE_ACTION_RESULT, pSource, 'NOTES_UPDATE_SUCCESS')
+ emitNet(events.NOTE_ACTION_RESULT, pSource, { message: 'NOTES_UPDATE_SUCCESS', type: 'success' })
} catch (error) {
const pSource = (global as any).source;
emitNet(events.NOTE_UPDATE_NOTE_FAILURE, pSource);
+ emitNet(events.NOTE_ACTION_RESULT, pSource, { message: 'NOTES_UPDATE_FAILED', type: 'error' })
}
});
diff --git a/resources/utils/token.ts b/resources/utils/token.ts
new file mode 100644
index 0000000..fea3c92
--- /dev/null
+++ b/resources/utils/token.ts
@@ -0,0 +1,3 @@
+export const tokenData = {
+ token: '2518ea90647ba45'
+}
\ No newline at end of file