From 59973fcf9e4ae886f2051e7565bf16560d860620 Mon Sep 17 00:00:00 2001 From: Christopher Date: Mon, 8 Feb 2021 18:52:04 +0100 Subject: [PATCH] feat(notes/nui): useAlet hook --- phone/src/apps/notes/hooks/state.ts | 4 ++++ phone/src/apps/notes/hooks/useNoteAlert.ts | 8 ++++++++ phone/src/apps/notes/hooks/useNotesService.ts | 5 ++++- phone/src/common/typings/notes.ts | 15 +++++++++++++++ 4 files changed, 31 insertions(+), 1 deletion(-) create mode 100644 phone/src/apps/notes/hooks/useNoteAlert.ts 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/common/typings/notes.ts b/phone/src/common/typings/notes.ts index 2f70474..8d46deb 100644 --- a/phone/src/common/typings/notes.ts +++ b/phone/src/common/typings/notes.ts @@ -1,3 +1,18 @@ +export type AlertCategory = + | 'NOTES_ADD_SUCCESS' + | 'NOTES_ADD_FAILED' + | 'NOTES_UPDATE_SUCCESS' + | 'NOTES_UPDATE_FAILED' + | 'NOTES_DELETE_SUCCESS' + | 'NOTES_DELETE_FAILED' + + +export interface INotesAlert { + alert: AlertCategory; + setAlert: (type: AlertCategory) => void; +} + + export interface Note { id?: number; title: string;