refactor note editing to avoid querystring

This commit is contained in:
Sam Wing 2019-11-18 15:39:37 -05:00
parent ac1c92746c
commit 0b6b9766bc
3 changed files with 7 additions and 11 deletions

View file

@ -180,8 +180,10 @@ module.exports = (db) => {
return res.redirect(`/wishlist/${req.params.user}`); return res.redirect(`/wishlist/${req.params.user}`);
}); });
router.get('/:user/note/:id', verifyAuth(), (_, res) => { router.get('/:user/note/:id', verifyAuth(), async (req, res) => {
res.render('note'); 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) => { router.post('/:user/note/:id', verifyAuth(), async (req, res) => {
const doc = await db.get(req.params.user); const doc = await db.get(req.params.user);

View file

@ -8,18 +8,18 @@ block content
.field .field
label.label Name label.label Name
.control .control
input.input(name='name', value=req.query.name) input.input(name='name', value=item.name)
.column .column
.field .field
label.label URL label.label URL
.control .control
input.input(name='url', value=req.query.url) input.input(name='url', value=item.url)
.field .field
label.label Note label.label Note
.control .control
textarea.textarea( textarea.textarea(
name='note' name='note'
)= req.query.note )= item.note
.field.inline .field.inline
.control.inline .control.inline
input.button.is-primary(type='submit' value='Save Item') input.button.is-primary(type='submit' value='Save Item')

View file

@ -32,9 +32,6 @@ block content
td.ugc(data-label='Note')= item.note td.ugc(data-label='Note')= item.note
td(data-label='Edit Item') td(data-label='Edit Item')
form.inline(method='GET', action=`/wishlist/${req.params.user}/note/${item.id}`) 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 .field.inline
.control.inline .control.inline
button.button.is-text( button.button.is-text(
@ -136,9 +133,6 @@ block content
input.inline.button.is-warning(type='submit' value='Remove') input.inline.button.is-warning(type='submit' value='Remove')
if req.user._id === req.params.user || req.user._id === item.addedBy if req.user._id === req.params.user || req.user._id === item.addedBy
form.inline(method='GET', action=`/wishlist/${req.params.user}/note/${item.id}`) 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 .field.inline
.control.inline .control.inline
input.inline.button(type='submit', value='Edit item') input.inline.button(type='submit', value='Edit item')