mirror of
https://github.com/darksaid98/new-phone-who-dis.git
synced 2026-12-04 06:28:51 +00:00
working updates
This commit is contained in:
1 parent
18be1a7d0f
commit
ce951ceecc
10 files changed
+92
-53
No files matched your search
@@ -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 (
|
||||
<AppWrapper id="notes-app">
|
||||
<NotesTitle />
|
||||
<NoteModal />
|
||||
<NoteModal key={detail?.id} />
|
||||
<AppContent>
|
||||
<NoteList notes={notes}/>
|
||||
<Fab
|
||||
|
||||
@@ -6,14 +6,12 @@ import { useNoteDetail } from '../hooks/useNoteDetail';
|
||||
|
||||
// add search bar later
|
||||
const NoteList = ({notes}) => {
|
||||
|
||||
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 (
|
||||
|
||||
@@ -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 (
|
||||
<div className={noteModal ? classes.modalRoot : classes.modalHide}>
|
||||
@@ -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)}
|
||||
/>
|
||||
<TextField
|
||||
className={classes.input}
|
||||
@@ -92,11 +86,12 @@ export const NoteModal = (note): any => {
|
||||
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 : <Button className={classes.saveButton} onClick={handleNoteSave}>Save</Button>}
|
||||
{detail ? <Button className={classes.deleteButton} onClick={handleDeleteNote}>Delete</Button> : null}
|
||||
{!detail && <Button className={classes.saveButton} onClick={handleNoteSave}>Save</Button>}
|
||||
{detail && <Button className={classes.updateButton} onClick={handleUpdateNote}>Update</Button>}
|
||||
{detail && <Button className={classes.deleteButton} onClick={handleDeleteNote}>Delete</Button>}
|
||||
</div>
|
||||
</div>
|
||||
</Slide>
|
||||
|
||||
@@ -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'
|
||||
|
||||
@@ -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);
|
||||
})*/
|
||||
onNet(events.NOTE_UPDATE_NOTE_SUCCESS, () => {
|
||||
emitNet(events.NOTE_FETCH_ALL_NOTES)
|
||||
});
|
||||
@@ -1 +1,44 @@
|
||||
<!doctype html><html lang="en"><head><meta charset="utf-8"/><link rel="icon" href="%PUBLIC_URL%/favicon.ico"/><link rel="stylesheet" href="https://fonts.googleapis.com/css?family=Roboto:300,400,500,700&display=swap"/><link rel="stylesheet" href="https://fonts.googleapis.com/icon?family=Material+Icons"/><meta name="viewport" content="width=device-width,initial-scale=1"/><meta name="theme-color" content="#000000"/><meta name="description" content="Web site created using create-react-app"/><title>React App</title></head><body><noscript>You need to enable JavaScript to run this app.</noscript><div id="root"></div><script src="main.js"></script></body></html>
|
||||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="utf-8" />
|
||||
<link rel="icon" href="/favicon.ico" />
|
||||
<link rel="stylesheet" href="https://fonts.googleapis.com/css?family=Roboto:300,400,500,700&display=swap" />
|
||||
<link rel="stylesheet" href="https://fonts.googleapis.com/icon?family=Material+Icons" />
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1" />
|
||||
<meta name="theme-color" content="#000000" />
|
||||
<meta
|
||||
name="description"
|
||||
content="Web site created using create-react-app"
|
||||
/>
|
||||
<!--
|
||||
manifest.json provides metadata used when your web app is installed on a
|
||||
user's mobile device or desktop. See https://developers.google.com/web/fundamentals/web-app-manifest/
|
||||
-->
|
||||
|
||||
<!--
|
||||
Notice the use of in the tags above.
|
||||
It will be replaced with the URL of the `public` folder during the build.
|
||||
Only files inside the `public` folder can be referenced from the HTML.
|
||||
|
||||
Unlike "/favicon.ico" or "favicon.ico", "/favicon.ico" will
|
||||
work correctly both with client-side routing and a non-root public URL.
|
||||
Learn how to configure a non-root public URL by running `npm run build`.
|
||||
-->
|
||||
<title>React App</title>
|
||||
</head>
|
||||
<body>
|
||||
<noscript>You need to enable JavaScript to run this app.</noscript>
|
||||
<div id="root"></div>
|
||||
<!--
|
||||
This HTML file is a template.
|
||||
If you open it directly in the browser, you will see an empty page.
|
||||
|
||||
You can add webfonts, meta tags, or analytics to this file.
|
||||
The build step will place the bundled scripts into the <body> tag.
|
||||
|
||||
To begin the development, run `npm start` or `yarn start`.
|
||||
To create a production bundle, use `npm run build` or `yarn build`.
|
||||
-->
|
||||
<script src="dev.js"></script></body>
|
||||
</html>
|
||||
Binary file not shown.
@@ -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,
|
||||
|
||||
@@ -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<any> {
|
||||
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<any> {
|
||||
async function updateNote(note: Note, identifier: string): Promise<any> {
|
||||
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)
|
||||
}
|
||||
})*/
|
||||
})
|
||||
@@ -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'
|
||||
}
|
||||
Reference in new issue
Block a user