diff options
-rw-r--r-- | apps/Notes/Notes.module.scss | 2 | ||||
-rw-r--r-- | apps/Notes/helpers/export.js | 2 | ||||
-rw-r--r-- | apps/Notes/helpers/noteActions.js | 16 | ||||
-rw-r--r-- | pages/api/note/[id].js | 31 | ||||
-rw-r--r-- | pages/api/notes/[id].js (renamed from pages/api/notes.js) | 34 | ||||
-rw-r--r-- | pages/api/notes/index.js | 48 | ||||
-rw-r--r-- | styles/Main.module.scss | 1 |
7 files changed, 67 insertions, 67 deletions
diff --git a/apps/Notes/Notes.module.scss b/apps/Notes/Notes.module.scss index a87adac..a8ad168 100644 --- a/apps/Notes/Notes.module.scss +++ b/apps/Notes/Notes.module.scss @@ -111,6 +111,7 @@ } p { + line-height: 1.33; padding: 0 1rem 1rem; white-space: pre-line; user-select: text; @@ -157,7 +158,6 @@ border: none; padding: 0.5rem; font-size: 1rem; - // font-weight: 600; border: 1px dashed var(--color-window-buttons); &:placeholder { diff --git a/apps/Notes/helpers/export.js b/apps/Notes/helpers/export.js index 80fa100..4a0db9c 100644 --- a/apps/Notes/helpers/export.js +++ b/apps/Notes/helpers/export.js @@ -23,7 +23,7 @@ export const handleExport = (e, ids, notes) => { Promise.all(ids.map(async id => { const title = notes.find(n => n.noteId === id).title - const {content} = await fetchJson(`/api/note/${id}`) + const {content} = await fetchJson(`/api/notes/${id}`) zip.folder('notes').file(filename(title), content, {binary: true}) })).then(() => { zip.generateAsync({type:"blob"}) diff --git a/apps/Notes/helpers/noteActions.js b/apps/Notes/helpers/noteActions.js index f67e7a4..f864e58 100644 --- a/apps/Notes/helpers/noteActions.js +++ b/apps/Notes/helpers/noteActions.js @@ -4,7 +4,7 @@ import filename from '../helpers/fileName' export const getNote = async (note, setFetchedNote, t, setPopup, callback) => { try { - const {content} = await fetchJson(`/api/note/${note.noteId}`) + const {content} = await fetchJson(`/api/notes/${note.noteId}`) setFetchedNote({ ...note, content}) callback() } catch (err) { @@ -50,10 +50,10 @@ export const updateNote = async (e, note, mutateNotes, setAction, t, setPopup) = try { mutateNotes( - await fetchJson('/api/notes', { + await fetchJson(`/api/notes/${_id}`, { method: 'PUT', headers: { 'Content-Type': 'application/json' }, - body: JSON.stringify({_id, title, noteId, content}), + body: JSON.stringify({title, noteId, content}), }) ) setPopup({ @@ -76,10 +76,8 @@ export const removeNote = (e, _id, mutateNotes, t, setPopup, setAction) => { const remove = async () => { try { await mutateNotes( - await fetchJson('/api/notes', { + await fetchJson(`/api/notes/${_id}`, { method: 'DELETE', - headers: { 'Content-Type': 'application/json' }, - body: JSON.stringify({_id}), }) ) setPopup({ @@ -98,8 +96,8 @@ export const removeNote = (e, _id, mutateNotes, t, setPopup, setAction) => { setPopup({ content: t('notes_remove_confirm'), - yes: { label: t('remove'), action: remove }, - no: { label: t('cancel'), action: async () => {} }, + yes: {label: t('remove'), action: remove}, + no: {label: t('cancel'), action: async () => {}}, error: true, }) } @@ -108,7 +106,7 @@ export const exportNote = async note => { const {title} = note const {content} = note.content ? note - : await fetchJson(`/api/note/${note.noteId}`) + : await fetchJson(`/api/notes/${note.noteId}`) saveFile(content, filename(title), 'text/plain') } diff --git a/pages/api/note/[id].js b/pages/api/note/[id].js deleted file mode 100644 index 1781210..0000000 --- a/pages/api/note/[id].js +++ /dev/null @@ -1,31 +0,0 @@ -import dbConnect from 'configs/dbConnect' -import withSession from 'hocs/withSession' -import Note from 'models/Note' - -export default withSession(async (req, res) => { - const {id} = req.query - await dbConnect() - - switch (req.method) { - case 'GET': - try { - const user = req.session.get('user') - - if (!user || !user?.isVerified || !id ) { - throw new Error('Something went wrong') - } - - const note = await Note.getNote(id) - - if (!note) { - throw new Error('Something went wrong') - } - - res.status(200).json(note) - } catch (error) { - console.log(error) - res.status(400).json({error: true}) - } - break - } -}) diff --git a/pages/api/notes.js b/pages/api/notes/[id].js index 0439a7a..58e458f 100644 --- a/pages/api/notes.js +++ b/pages/api/notes/[id].js @@ -4,6 +4,7 @@ import NoteList from 'models/NoteList' import Note from 'models/Note' export default withSession(async (req, res) => { + const {id: _id} = req.query await dbConnect() switch (req.method) { @@ -11,38 +12,25 @@ export default withSession(async (req, res) => { try { const user = req.session.get('user') - if (!user || !user.isVerified) { + if (!user || !user?.isVerified || !_id ) { throw new Error('Something went wrong') } - const {notes} = await NoteList.getList(user.noteList) + const note = await Note.getNote(_id) - res.status(200).json(notes) - } catch (error) { - res.status(400).json([]) - } - break - case 'POST': - try { - const user = req.session.get('user') - const {title, content} = req.body - - if (!user || !user?.isVerified || !content) { + if (!note) { throw new Error('Something went wrong') } - const note = await Note.create({content}) - const {notes} = await NoteList.addNote(user.noteList, note._id, title) - - res.status(200).json(notes) + res.status(200).json(note) } catch (error) { - res.status(400).json([]) + console.log(error) + res.status(400).json({error: true}) } break case 'DELETE': try { const user = req.session.get('user') - const {_id} = req.body if (!user || !user?.isVerified || !_id) { throw new Error('Something went wrong') @@ -56,13 +44,14 @@ export default withSession(async (req, res) => { res.status(200).json(notes) } catch (error) { + console.log(error) res.status(400).json([]) } break case 'PUT': try { const user = req.session.get('user') - const {_id, title, noteId, content} = req.body + const {title, noteId, content} = req.body if (!user || !user?.isVerified || !_id || !content) { throw new Error('Something went wrong') @@ -77,10 +66,5 @@ export default withSession(async (req, res) => { res.status(400).json([]) } break - default: - res.status(400).send() - break } }) - - diff --git a/pages/api/notes/index.js b/pages/api/notes/index.js new file mode 100644 index 0000000..f62f849 --- /dev/null +++ b/pages/api/notes/index.js @@ -0,0 +1,48 @@ +import dbConnect from 'configs/dbConnect' +import withSession from 'hocs/withSession' +import NoteList from 'models/NoteList' +import Note from 'models/Note' + +export default withSession(async (req, res) => { + await dbConnect() + + switch (req.method) { + case 'GET': + try { + const user = req.session.get('user') + + if (!user || !user.isVerified) { + throw new Error('Something went wrong') + } + + const {notes} = await NoteList.getList(user.noteList) + + res.status(200).json(notes) + } catch (error) { + res.status(400).json([]) + } + break + case 'POST': + try { + const user = req.session.get('user') + const {title, content} = req.body + + if (!user || !user?.isVerified || !content) { + throw new Error('Something went wrong') + } + + const note = await Note.create({content}) + const {notes} = await NoteList.addNote(user.noteList, note._id, title) + + res.status(200).json(notes) + } catch (error) { + res.status(400).json([]) + } + break + default: + res.status(400).send() + break + } +}) + + diff --git a/styles/Main.module.scss b/styles/Main.module.scss index e5254d5..6663b15 100644 --- a/styles/Main.module.scss +++ b/styles/Main.module.scss @@ -11,6 +11,7 @@ display: inline-block; padding: .5em; text-align: center; + outline: none; img { width: 3em; |