diff --git a/phone/src/apps/notes/NotesApp.tsx b/phone/src/apps/notes/NotesApp.tsx
index 7186f0c..8875d82 100644
--- a/phone/src/apps/notes/NotesApp.tsx
+++ b/phone/src/apps/notes/NotesApp.tsx
@@ -15,6 +15,7 @@ import { useNoteDetail } from './hooks/useNoteDetail';
import useStyles from './notes.styles';
import InjectDebugData from '../../os/debug/InjectDebugData';
+import { NotesAlert } from './alert/NotesAlert';
InjectDebugData([
{
@@ -32,7 +33,7 @@ InjectDebugData([
content: 'Hello, this is another shitty note',
},
],
- },
+ }
]);
export const NotesApp = () => {
@@ -54,7 +55,8 @@ export const NotesApp = () => {
-
+ {
>
-
+
);
};
diff --git a/phone/src/apps/notes/alert/NotesAlert.tsx b/phone/src/apps/notes/alert/NotesAlert.tsx
new file mode 100644
index 0000000..c760082
--- /dev/null
+++ b/phone/src/apps/notes/alert/NotesAlert.tsx
@@ -0,0 +1,62 @@
+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/state.ts b/phone/src/apps/notes/hooks/state.ts
index 37c31d5..b5c0ea7 100644
--- a/phone/src/apps/notes/hooks/state.ts
+++ b/phone/src/apps/notes/hooks/state.ts
@@ -13,4 +13,8 @@ export const noteStates = {
key: 'noteDetail',
default: null,
}),
+ alert: atom({
+ key: 'notesAlert',
+ default: null
+ })
};
diff --git a/phone/src/apps/notes/hooks/useNoteAlert.ts b/phone/src/apps/notes/hooks/useNoteAlert.ts
new file mode 100644
index 0000000..ba081b2
--- /dev/null
+++ b/phone/src/apps/notes/hooks/useNoteAlert.ts
@@ -0,0 +1,8 @@
+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 5e504a6..c4356c4 100644
--- a/phone/src/apps/notes/hooks/useNotesService.ts
+++ b/phone/src/apps/notes/hooks/useNotesService.ts
@@ -2,9 +2,12 @@ import { useSetRecoilState } from 'recoil';
import { useNuiEvent } from '../../../os/nui-events/hooks/useNuiEvent';
import { useNotes } from './useNotes';
import { noteStates } from './state';
+import { useNotesAlert } from './useNoteAlert';
export const useNotesService = () => {
const setNotes = useSetRecoilState(noteStates.noteItems);
+ const setAlert = useSetRecoilState(noteStates.alert);
useNuiEvent('NOTES', 'setNotes', setNotes);
- return useNotes();
+ useNuiEvent('NOTES', 'setAlert', setAlert)
+ return { useNotes, useNotesAlert };
};
diff --git a/phone/src/apps/notes/modal/NoteModal.tsx b/phone/src/apps/notes/modal/NoteModal.tsx
index fb75c6e..7867d2a 100644
--- a/phone/src/apps/notes/modal/NoteModal.tsx
+++ b/phone/src/apps/notes/modal/NoteModal.tsx
@@ -1,5 +1,5 @@
import { Button, TextField, Slide } from '@material-ui/core';
-import React, { useState } from 'react';
+import React, { useState, useEffect } from 'react';
import ArrowBackIcon from '@material-ui/icons/ArrowBack';
import { useNoteModal } from '../hooks/useNoteModal';
@@ -14,33 +14,37 @@ import Nui from '../../../os/nui-events/utils/Nui';
export const NoteModal = () => {
const { noteModal, setNoteModal } = useNoteModal();
const { detail, setDetail } = useNoteDetail();
- console.log(detail);
const [title, setTitle] = useState(detail ? detail.title : '');
const [content, setContent] = useState(detail ? detail.content : '');
- const classes = useStyles();
+ const classes = useStyles()
+
+
const _handleClose = () => {
- setNoteModal(false);
setDetail(null);
+ setNoteModal(false);
};
const handleNoteSave = () => {
- setNoteModal(false);
- setDetail(null);
Nui.send('phone:addNote', {
title,
content,
});
+ setDetail(null);
+ setNoteModal(false);
+
+ setTitle('')
+ setContent('')
};
const handleDeleteNote = () => {
const id = detail.id;
- setNoteModal(false);
Nui.send('phone:deleteNote', {
id,
});
setDetail(null);
+ setNoteModal(false);
};
const handleUpdateNote = () => {
@@ -49,8 +53,8 @@ export const NoteModal = () => {
title,
content,
});
- setNoteModal(false);
setDetail(null);
+ setNoteModal(false);
};
return (
@@ -63,9 +67,11 @@ export const NoteModal = () => {
{
className={classes.input}
inputProps={{
className: classes.inputPropsContent,
+ maxLength: 250,
}}
placeholder='Content'
multiline
@@ -84,8 +91,9 @@ export const NoteModal = () => {
value={content}
onChange={(e) => setContent(e.target.value)}
/>
- {!detail && (
-