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
This commit is contained in:
Wingy 2022-10-03 11:32:25 -04:00 committed by GitHub
parent 0e6420f714
commit b94afc3579
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 6 additions and 3 deletions

View file

@ -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',

View file

@ -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}`)

View file

@ -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