diff --git a/phone/src/apps/notes/NotesApp.tsx b/phone/src/apps/notes/NotesApp.tsx index 8ea059e..9db0372 100644 --- a/phone/src/apps/notes/NotesApp.tsx +++ b/phone/src/apps/notes/NotesApp.tsx @@ -11,23 +11,26 @@ 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'; export const NotesApp = () => { - const { noteModal, setNoteModal } = useNoteModal(); + const { setNoteModal } = useNoteModal(); + const { detail, setDetail } = useNoteDetail(); const notes = useNotes(); const classes = useStyles(); const handleModal = () => { setNoteModal(true) + setDetail(null); } return ( - + { - - const { noteModal, setNoteModal } = useNoteModal(); - const { detail, setDetail } = useNoteDetail(); + const { setNoteModal } = useNoteModal(); + const { setDetail } = useNoteDetail(); const handleNoteModal = (note) => { setNoteModal(true) setDetail(note) - console.log(note.id) } return ( diff --git a/phone/src/apps/notes/modal/NoteModal.tsx b/phone/src/apps/notes/modal/NoteModal.tsx index 7f91cbe..005d741 100644 --- a/phone/src/apps/notes/modal/NoteModal.tsx +++ b/phone/src/apps/notes/modal/NoteModal.tsx @@ -16,10 +16,9 @@ import Nui from '../../../os/nui-events/utils/Nui'; export const NoteModal = (note): any => { const { noteModal, setNoteModal } = useNoteModal(); const { detail, setDetail } = useNoteDetail(); - - const notes = useNotes(); - const [title, setTitle] = useState(''); - const [content, setContent] = useState(''); + console.log(detail); + const [title, setTitle] = useState(detail ? detail.title : ""); + const [content, setContent] = useState(detail ? detail.content: ""); const classes = useStyles(); @@ -51,20 +50,15 @@ export const NoteModal = (note): any => { setDetail(null) } - //const handleUpdateNote = () => { - // const id = detail.id; - // const detailTitle = detail.title; - // const detailContent = detail.content - // console.log("NOTE", detailTitle, detailContent) -// - // Nui.send('pone:updateNote', { - // id, - // detailTitle, - // detailContent - // }) - // setNoteModal(false); - // setDetail(null) - //} + const handleUpdateNote = () => { + Nui.send('phone:updateNote', { + id: detail.id, + title, + content + }); + setNoteModal(false); + setDetail(null) + } return (
@@ -79,8 +73,8 @@ export const NoteModal = (note): any => { className: classes.inputPropsTitle }} fullWidth - value={detail ? detail.title : title} - onChange={detail ? e => setDetail(e.target.value) : e => setTitle(e.target.value)} + value={title} + onChange={e => setTitle(e.target.value)} /> { fullWidth rows={19} variant="outlined" - value={detail ? detail.content : content} - onChange={detail ? e => setDetail(e.target.value) : e => setContent(e.target.value)} + value={content} + onChange={e => setContent(e.target.value)} /> - {detail ? null : } - {detail ? : null} + {!detail && } + {detail && } + {detail && }
diff --git a/phone/src/apps/notes/modal/modal.styles.ts b/phone/src/apps/notes/modal/modal.styles.ts index 912c305..079dd05 100644 --- a/phone/src/apps/notes/modal/modal.styles.ts +++ b/phone/src/apps/notes/modal/modal.styles.ts @@ -35,6 +35,11 @@ const useStyles = makeStyles((theme) => ({ background: '#f9a825', padding: '10px 30px' }, + updateButton: { + background: '#f9a825', + padding: '10px 30px', + marginRight: '8px' + }, deleteButton: { background: '#c62828', padding: '10px 30px' diff --git a/resources/client/cl_notes.ts b/resources/client/cl_notes.ts index 8418648..d660347 100644 --- a/resources/client/cl_notes.ts +++ b/resources/client/cl_notes.ts @@ -33,14 +33,12 @@ on(`__cfx_nui:${events.NOTE_DELETE_NOTE}`, (data: any) => { // coming soon tm - -/*RegisterNuiCallbackType(events.NOTE_UPDATE_NOTE); +RegisterNuiCallbackType(events.NOTE_UPDATE_NOTE); on(`__cfx_nui:${events.NOTE_UPDATE_NOTE}`, (data: any) => { const note = data; emitNet(events.NOTE_UPDATE_NOTE, note) +}) - - setTimeout(() => { - emitNet(events.NOTE_FETCH_ALL_NOTES) - }, 500); -})*/ \ No newline at end of file +onNet(events.NOTE_UPDATE_NOTE_SUCCESS, () => { + emitNet(events.NOTE_FETCH_ALL_NOTES) +}); diff --git a/resources/html/index.html b/resources/html/index.html index 9c511ba..d196fe9 100644 --- a/resources/html/index.html +++ b/resources/html/index.html @@ -1 +1,44 @@ -React App
\ No newline at end of file + + + + + + + + + + + + + + React App + + + +
+ + + diff --git a/resources/html/media/BAHNSCHRIFT.8cab203d.woff b/resources/html/media/BAHNSCHRIFT.8cab203d.woff new file mode 100644 index 0000000..2d86200 Binary files /dev/null and b/resources/html/media/BAHNSCHRIFT.8cab203d.woff differ diff --git a/resources/import.sql b/resources/import.sql index 0deb636..18d14b9 100644 --- a/resources/import.sql +++ b/resources/import.sql @@ -58,7 +58,7 @@ CREATE TABLE IF NOT EXISTS `npwd_twitter_likes` ( ) ENGINE=InnoDB AUTO_INCREMENT=41 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci; -CREATE TABLE IF NOT EXIST npwd_notes ( +CREATE TABLE IF NOT EXISTS npwd_notes ( id int(11) NOT NULL AUTO_INCREMENT, identifier varchar(255) NOT NULL, title varchar(255) NOT NULL, diff --git a/resources/server/sv_notes.ts b/resources/server/sv_notes.ts index 95a45e7..77a6c7d 100644 --- a/resources/server/sv_notes.ts +++ b/resources/server/sv_notes.ts @@ -4,6 +4,7 @@ import { pool } from './db'; import { useIdentifier } from './functions'; interface Note { + id?: number; title: string; content: string; } @@ -12,12 +13,6 @@ interface NoteId { id: number } -interface UpdateNote { - id: number; - title: string; - content: string; -} - async function addNote(identifier: string, note: Note): Promise { const query = "INSERT INTO npwd_notes (identifier, title, content) VALUES (?, ?, ?)" await pool.query(query, @@ -41,7 +36,7 @@ async function deleteNote(noteId: number, identifier: string) { await pool.query(query, [noteId, identifier]) } -/*async function updateNote(note: UpdateNote, identifier: string): Promise { +async function updateNote(note: Note, identifier: string): Promise { const query = "UPDATE npwd_notes SET title = ?, content = ? WHERE id = ? AND identifier = ?" await pool.query(query, [ note.title, @@ -49,7 +44,7 @@ async function deleteNote(noteId: number, identifier: string) { note.id, identifier ]) -}*/ +} onNet(events.NOTE_ADD_NOTE, async (note: Note) => { try { @@ -84,13 +79,13 @@ onNet(events.NOTE_DELETE_NOTE, async (noteId: NoteId) => { } }) -// coming soon tm - -/*onNet(events.NOTE_UPDATE_NOTE, async (note: UpdateNote) => { +onNet(events.NOTE_UPDATE_NOTE, async (note: Note) => { + const _source = (global as any).source; try { const _identifier = await useIdentifier(); updateNote(note, _identifier) + emitNet(events.NOTE_UPDATE_NOTE_SUCCESS, _source) } catch (error) { - console.log("NOTE ERROR:", error) + emitNet(events.NOTE_UPDATE_NOTE_FAILURE, _source) } -})*/ \ No newline at end of file +}) \ No newline at end of file diff --git a/resources/utils/events.ts b/resources/utils/events.ts index 75ebe6d..eb673a7 100644 --- a/resources/utils/events.ts +++ b/resources/utils/events.ts @@ -52,5 +52,7 @@ export default { NOTE_FETCH_ALL_NOTES: 'phone:fetchAllNotes', NOTE_SEND_NOTE: 'phone:sendNote', NOTE_DELETE_NOTE: 'phone:deleteNote', - NOTE_UPDATE_NOTE: 'phone:updateNote' + NOTE_UPDATE_NOTE: 'phone:updateNote', + NOTE_UPDATE_NOTE_SUCCESS: 'phone:updateNoteSuccess', + NOTE_UPDATE_NOTE_FAILURE: 'phone:updateNoteFailure' }