From 2f191e04f9d00f9e95c543fc45c97fb109def3c0 Mon Sep 17 00:00:00 2001 From: k00b Date: Thu, 19 Sep 2024 15:27:09 -0500 Subject: [PATCH] ek boost hint suggestions --- api/resolvers/item.js | 5 +++-- components/adv-post-form.js | 10 +++++----- 2 files changed, 8 insertions(+), 7 deletions(-) diff --git a/api/resolvers/item.js b/api/resolvers/item.js index 8238c7e7..96345395 100644 --- a/api/resolvers/item.js +++ b/api/resolvers/item.js @@ -690,7 +690,8 @@ export default { boost: { gte: boost }, status: 'ACTIVE', deletedAt: null, - outlawed: false + outlawed: false, + parentId: null } if (id) { where.id = { not: Number(id) } @@ -698,7 +699,7 @@ export default { return { home: await models.item.count({ where }) === 0, - sub: await models.item.count({ where: { ...where, subName: sub } }) === 0 + sub: sub ? await models.item.count({ where: { ...where, subName: sub } }) === 0 : false } } }, diff --git a/components/adv-post-form.js b/components/adv-post-form.js index 98cbb260..5e688e54 100644 --- a/components/adv-post-form.js +++ b/components/adv-post-form.js @@ -90,8 +90,8 @@ export function BoostItemInput ({ item, sub, act = false, ...props }) { const [boost, setBoost] = useState(Number(item?.boost) + (act ? BOOST_MULT : 0)) const [getBoostPosition, { data }] = useLazyQuery(gql` - query BoostPosition($id: ID, $boost: Int) { - boostPosition(sub: "${item?.subName || sub?.name}", id: $id, boost: $boost) { + query BoostPosition($sub: String, $id: ID, $boost: Int) { + boostPosition(sub: $sub, id: $id, boost: $boost) { home sub } @@ -101,10 +101,10 @@ export function BoostItemInput ({ item, sub, act = false, ...props }) { const getPositionDebounce = useDebounceCallback((...args) => getBoostPosition(...args), 1000, [getBoostPosition]) useEffect(() => { - if (boost) { - getPositionDebounce({ variables: { boost: Number(boost), id: item?.id } }) + if (boost >= 0 && !item?.parentId) { + getPositionDebounce({ variables: { sub: item?.subName || sub?.name, boost: Number(boost), id: item?.id } }) } - }, [boost, item?.id]) + }, [boost, item?.id, !item?.parentId, item?.subName || sub?.name]) const boostMessage = useMemo(() => { if (!item?.parentId) {