From b94afc3579410e17b195a6b99a6c5adeddfcb5a5 Mon Sep 17 00:00:00 2001 From: Wingy Date: Mon, 3 Oct 2022 11:32:25 -0400 Subject: [PATCH] Add the ability to suggest items for someone else without pledging for it (#29) * add suggest button to wishlist * make suggest button work * remove delete-on-unpledge logic --- languages/en-us.js | 1 + routes/wishlist/index.js | 3 +-- views/wishlist.pug | 5 ++++- 3 files changed, 6 insertions(+), 3 deletions(-) diff --git a/languages/en-us.js b/languages/en-us.js index 2449125..f794410 100644 --- a/languages/en-us.js +++ b/languages/en-us.js @@ -168,6 +168,7 @@ module.exports.strings = { WISHLIST_REMOVE_GUARD: 'Not correct user', WISHLIST_REMOVE_MISSING: 'Failed to find item', WISHLIST_REMOVE_SUCCESS: 'Successfully removed from wishlist', + WISHLIST_SUGGEST: 'Suggest item', WISHLIST_TITLE: name => `${_CC.config.siteTitle} - Wishlist - ${name}`, WISHLIST_UNPLEDGE_GUARD: 'You did not pledge for this', // should never happen unless someone makes their own http requests WISHLIST_UNPLEDGE_MISSING: 'Failed to find item', diff --git a/routes/wishlist/index.js b/routes/wishlist/index.js index a54d6db..fe6f4b0 100644 --- a/routes/wishlist/index.js +++ b/routes/wishlist/index.js @@ -99,7 +99,7 @@ module.exports = (db) => { item.price = productData?.price item.image = productData?.image item.addedBy = req.user._id - item.pledgedBy = (req.user._id === req.params.user ? undefined : req.user._id) + item.pledgedBy = (req.user._id === req.params.user || req.body.suggest ? undefined : req.user._id) item.note = req.body.note if (url) item.url = url if (!url) item.name = req.body.itemUrlOrName @@ -150,7 +150,6 @@ module.exports = (db) => { return res.redirect(`/wishlist/${req.params.user}`) } docs.rows[i].doc.wishlist[j].pledgedBy = undefined - if (docs.rows[i].doc.wishlist[j].addedBy === req.user._id) docs.rows[i].doc.wishlist.splice(j, 1) await db.put(docs.rows[i].doc) req.flash('success', _CC.lang('WISHLIST_UNPLEDGE_SUCCESS')) return res.redirect(`/wishlist/${req.params.user}`) diff --git a/views/wishlist.pug b/views/wishlist.pug index 1668d42..23cdd63 100644 --- a/views/wishlist.pug +++ b/views/wishlist.pug @@ -215,9 +215,12 @@ block content name='note', placeholder=lang('WISHLIST_OPTIONAL') ) - .field + .field.is-grouped .control input.button(type='submit' value=(req.user._id === req.params.user ? lang('WISHLIST_ADD') : lang('WISHLIST_PLEDGE_ITEM'))) + if req.user._id !== req.params.user + .control + input.inline.button(type='submit', value=lang('WISHLIST_SUGGEST'), name='suggest') script(src=`${_CC.config.base}js/wishlist.js`) block print