From 0b6b9766bc16f293e49b3bffa243aff544683ad1 Mon Sep 17 00:00:00 2001 From: Sam Wing Date: Mon, 18 Nov 2019 15:39:37 -0500 Subject: [PATCH] refactor note editing to avoid querystring --- routes/wishlist/index.js | 6 ++++-- views/note.pug | 6 +++--- views/wishlist.pug | 6 ------ 3 files changed, 7 insertions(+), 11 deletions(-) diff --git a/routes/wishlist/index.js b/routes/wishlist/index.js index 5c9b086..5f73b95 100644 --- a/routes/wishlist/index.js +++ b/routes/wishlist/index.js @@ -180,8 +180,10 @@ module.exports = (db) => { return res.redirect(`/wishlist/${req.params.user}`); }); - router.get('/:user/note/:id', verifyAuth(), (_, res) => { - res.render('note'); + router.get('/:user/note/:id', verifyAuth(), async (req, res) => { + const doc = await db.get(req.params.user); + const item = doc.wishlist.find(item => item.id === req.params.id) + res.render('note', { item }); }); router.post('/:user/note/:id', verifyAuth(), async (req, res) => { const doc = await db.get(req.params.user); diff --git a/views/note.pug b/views/note.pug index 07dfe30..e1abf99 100644 --- a/views/note.pug +++ b/views/note.pug @@ -8,18 +8,18 @@ block content .field label.label Name .control - input.input(name='name', value=req.query.name) + input.input(name='name', value=item.name) .column .field label.label URL .control - input.input(name='url', value=req.query.url) + input.input(name='url', value=item.url) .field label.label Note .control textarea.textarea( name='note' - )= req.query.note + )= item.note .field.inline .control.inline input.button.is-primary(type='submit' value='Save Item') \ No newline at end of file diff --git a/views/wishlist.pug b/views/wishlist.pug index a15c17e..cecef74 100644 --- a/views/wishlist.pug +++ b/views/wishlist.pug @@ -32,9 +32,6 @@ block content td.ugc(data-label='Note')= item.note td(data-label='Edit Item') form.inline(method='GET', action=`/wishlist/${req.params.user}/note/${item.id}`) - input(type='hidden', name='name', value=item.name) - input(type='hidden', name='note', value=item.note) - input(type='hidden', name='url', value=item.url) .field.inline .control.inline button.button.is-text( @@ -136,9 +133,6 @@ block content input.inline.button.is-warning(type='submit' value='Remove') if req.user._id === req.params.user || req.user._id === item.addedBy form.inline(method='GET', action=`/wishlist/${req.params.user}/note/${item.id}`) - input(type='hidden', name='name', value=item.name) - input(type='hidden', name='note', value=item.note) - input(type='hidden', name='url', value=item.url) .field.inline .control.inline input.inline.button(type='submit', value='Edit item')