mirror of
https://github.com/darksaid98/new-phone-who-dis.git
synced 2026-12-04 22:16:40 +00:00
feat(notes/client|server): sending alert results!
This commit is contained in:
1 parent
4d92847163
commit
a8f025aff3
5 files changed
+46
-29
No files matched your search
@@ -1,19 +1,13 @@
|
|||||||
import events from '../utils/events';
|
import events from '../utils/events';
|
||||||
|
import { sendNotesEvent } from '../utils/messages';
|
||||||
|
|
||||||
onNet(events.NOTE_SEND_NOTE, (notes: any) => {
|
onNet(events.NOTE_SEND_NOTE, (notes: any) => {
|
||||||
SendNuiMessage(
|
sendNotesEvent('setNotes', notes);
|
||||||
JSON.stringify({
|
|
||||||
app: 'NOTES',
|
|
||||||
method: 'setNotes',
|
|
||||||
data: notes,
|
|
||||||
})
|
|
||||||
);
|
|
||||||
});
|
});
|
||||||
|
|
||||||
RegisterNuiCallbackType(events.NOTE_ADD_NOTE);
|
RegisterNuiCallbackType(events.NOTE_ADD_NOTE);
|
||||||
on(`__cfx_nui:${events.NOTE_ADD_NOTE}`, (data: any) => {
|
on(`__cfx_nui:${events.NOTE_ADD_NOTE}`, (data: any) => {
|
||||||
const note = data;
|
emitNet(events.NOTE_ADD_NOTE, data);
|
||||||
emitNet(events.NOTE_ADD_NOTE, note);
|
|
||||||
});
|
});
|
||||||
|
|
||||||
onNet(events.NOTE_SEND_NOTE_SUCCESS, () => {
|
onNet(events.NOTE_SEND_NOTE_SUCCESS, () => {
|
||||||
@@ -22,18 +16,22 @@ onNet(events.NOTE_SEND_NOTE_SUCCESS, () => {
|
|||||||
|
|
||||||
RegisterNuiCallbackType(events.NOTE_DELETE_NOTE);
|
RegisterNuiCallbackType(events.NOTE_DELETE_NOTE);
|
||||||
on(`__cfx_nui:${events.NOTE_DELETE_NOTE}`, (data: any) => {
|
on(`__cfx_nui:${events.NOTE_DELETE_NOTE}`, (data: any) => {
|
||||||
const noteId = data;
|
emitNet(events.NOTE_DELETE_NOTE, data);
|
||||||
emitNet(events.NOTE_DELETE_NOTE, noteId);
|
|
||||||
|
|
||||||
emitNet(events.NOTE_FETCH_ALL_NOTES);
|
emitNet(events.NOTE_FETCH_ALL_NOTES);
|
||||||
});
|
});
|
||||||
|
|
||||||
RegisterNuiCallbackType(events.NOTE_UPDATE_NOTE);
|
RegisterNuiCallbackType(events.NOTE_UPDATE_NOTE);
|
||||||
on(`__cfx_nui:${events.NOTE_UPDATE_NOTE}`, (data: any) => {
|
on(`__cfx_nui:${events.NOTE_UPDATE_NOTE}`, (data: any) => {
|
||||||
const note = data;
|
emitNet(events.NOTE_UPDATE_NOTE, data);
|
||||||
emitNet(events.NOTE_UPDATE_NOTE, note);
|
|
||||||
});
|
});
|
||||||
|
|
||||||
onNet(events.NOTE_UPDATE_NOTE_SUCCESS, () => {
|
onNet(events.NOTE_UPDATE_NOTE_SUCCESS, () => {
|
||||||
emitNet(events.NOTE_FETCH_ALL_NOTES);
|
emitNet(events.NOTE_FETCH_ALL_NOTES);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
|
onNet(events.NOTE_ACTION_RESULT, (type: string) => {
|
||||||
|
console.log(type)
|
||||||
|
sendNotesEvent('setAlert', type)
|
||||||
|
})
|
||||||
@@ -13,8 +13,7 @@ async function fetchAllNotes(identifier: string): Promise<Note[]> {
|
|||||||
const query =
|
const query =
|
||||||
'SELECT * FROM npwd_notes WHERE identifier = ? ORDER BY id DESC';
|
'SELECT * FROM npwd_notes WHERE identifier = ? ORDER BY id DESC';
|
||||||
const [result] = await pool.query(query, [identifier]);
|
const [result] = await pool.query(query, [identifier]);
|
||||||
const notes = <Note[]>result;
|
return <Note[]>result;
|
||||||
return notes;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
async function deleteNote(noteId: number, identifier: string) {
|
async function deleteNote(noteId: number, identifier: string) {
|
||||||
@@ -30,42 +29,55 @@ async function updateNote(note: Note, identifier: string): Promise<any> {
|
|||||||
|
|
||||||
onNet(events.NOTE_ADD_NOTE, async (note: Note) => {
|
onNet(events.NOTE_ADD_NOTE, async (note: Note) => {
|
||||||
try {
|
try {
|
||||||
|
const pSource = (global as any).source
|
||||||
const _identifier = await useIdentifier();
|
const _identifier = await useIdentifier();
|
||||||
addNote(_identifier, note);
|
await addNote(_identifier, note);
|
||||||
emitNet(events.NOTE_SEND_NOTE_SUCCESS, getSource());
|
emitNet(events.NOTE_SEND_NOTE_SUCCESS, pSource);
|
||||||
|
emitNet(events.NOTE_ACTION_RESULT, pSource, 'NOTES_ADD_SUCCESS')
|
||||||
|
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.log('NOTES ERROR: ', error);
|
const pSource = (global as any).source
|
||||||
|
emitNet(events.NOTE_ACTION_RESULT, pSource, 'NOTES_ADD_FAILED')
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
onNet(events.NOTE_FETCH_ALL_NOTES, async () => {
|
onNet(events.NOTE_FETCH_ALL_NOTES, async () => {
|
||||||
try {
|
try {
|
||||||
const _source = (global as any).source;
|
const pSource = (global as any).source
|
||||||
const _identifier = await useIdentifier();
|
const _identifier = await useIdentifier();
|
||||||
const notes = await fetchAllNotes(_identifier);
|
const notes = await fetchAllNotes(_identifier);
|
||||||
emitNet(events.NOTE_SEND_NOTE, _source, notes);
|
emitNet(events.NOTE_SEND_NOTE, pSource, notes);
|
||||||
|
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.log('NOTE ERROR: ', error);
|
console.dir(error)
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
onNet(events.NOTE_DELETE_NOTE, async (noteId: NoteId) => {
|
onNet(events.NOTE_DELETE_NOTE, async (noteId: NoteId) => {
|
||||||
try {
|
try {
|
||||||
|
const pSource = (global as any).source;
|
||||||
const _identifier = await useIdentifier();
|
const _identifier = await useIdentifier();
|
||||||
const id = noteId.id;
|
await deleteNote(noteId.id, _identifier);
|
||||||
await deleteNote(id, _identifier);
|
|
||||||
|
emitNet(events.NOTE_ACTION_RESULT, pSource, 'NOTES_DELETE_SUCCESS')
|
||||||
|
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.log('NOTE ERROR:', error);
|
const pSource = (global as any).source;
|
||||||
|
emitNet(events.NOTE_ACTION_RESULT, pSource, 'NOTES_DELETE_FAILED')
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
onNet(events.NOTE_UPDATE_NOTE, async (note: Note) => {
|
onNet(events.NOTE_UPDATE_NOTE, async (note: Note) => {
|
||||||
const _source = (global as any).source;
|
|
||||||
try {
|
try {
|
||||||
|
const pSource = (global as any).source;
|
||||||
const _identifier = await useIdentifier();
|
const _identifier = await useIdentifier();
|
||||||
updateNote(note, _identifier);
|
await updateNote(note, _identifier);
|
||||||
emitNet(events.NOTE_UPDATE_NOTE_SUCCESS, _source);
|
emitNet(events.NOTE_UPDATE_NOTE_SUCCESS, pSource);
|
||||||
|
emitNet(events.NOTE_ACTION_RESULT, pSource, 'NOTES_UPDATE_SUCCESS')
|
||||||
|
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
emitNet(events.NOTE_UPDATE_NOTE_FAILURE, _source);
|
const pSource = (global as any).source;
|
||||||
|
emitNet(events.NOTE_UPDATE_NOTE_FAILURE, pSource);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -1,4 +1,5 @@
|
|||||||
export default {
|
export default {
|
||||||
TWITTER: 'TWITTER',
|
TWITTER: 'TWITTER',
|
||||||
MESSAGES: 'MESSAGES',
|
MESSAGES: 'MESSAGES',
|
||||||
|
NOTES: 'NOTES'
|
||||||
};
|
};
|
||||||
@@ -76,6 +76,8 @@ export default {
|
|||||||
NOTE_UPDATE_NOTE: 'phone:updateNote',
|
NOTE_UPDATE_NOTE: 'phone:updateNote',
|
||||||
NOTE_UPDATE_NOTE_SUCCESS: 'phone:updateNoteSuccess',
|
NOTE_UPDATE_NOTE_SUCCESS: 'phone:updateNoteSuccess',
|
||||||
NOTE_UPDATE_NOTE_FAILURE: 'phone:updateNoteFailure',
|
NOTE_UPDATE_NOTE_FAILURE: 'phone:updateNoteFailure',
|
||||||
|
NOTE_ACTION_RESULT: 'phone:notesActionResult',
|
||||||
|
|
||||||
|
|
||||||
// DO NOT CHANGE WHATS BELOW, PLEASE - CHIP
|
// DO NOT CHANGE WHATS BELOW, PLEASE - CHIP
|
||||||
OPEN_APP_CONTACTS: 'phone:app:CONTACTS',
|
OPEN_APP_CONTACTS: 'phone:app:CONTACTS',
|
||||||
|
|||||||
@@ -17,3 +17,7 @@ export function sendTwitterMessage(method: string, data: any = {}) {
|
|||||||
export function sendMessageEvent(method: string, data: any = {}) {
|
export function sendMessageEvent(method: string, data: any = {}) {
|
||||||
return sendMessage(apps.MESSAGES, method, data);
|
return sendMessage(apps.MESSAGES, method, data);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export function sendNotesEvent(method: string, data: any = {}) {
|
||||||
|
return sendMessage(apps.NOTES, method, data);
|
||||||
|
}
|
||||||
Reference in new issue
Block a user