Skip to content

Commit 0bc3d89

Browse files
committed
Allow 0 pct forwards to pass only in the client
1 parent 980f6da commit 0bc3d89

File tree

3 files changed

+4
-4
lines changed

3 files changed

+4
-4
lines changed

components/adv-post-form.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -282,7 +282,7 @@ export default function AdvPostForm ({ children, item, sub, storageKeyPrefix })
282282
name={`forward[${index}].pct`}
283283
type='number'
284284
step={5}
285-
min={1}
285+
min={0}
286286
max={100}
287287
append={<InputGroup.Text className='text-monospace'>%</InputGroup.Text>}
288288
groupClassName={`${styles.percent} mb-0`}

lib/form.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,15 @@ import { hasDeleteMention, hasReminderMention } from './item'
22

33
/**
44
* Normalize an array of forwards by converting the pct from a string to a number
5-
* Also extracts nym from nested user object, if necessary
5+
* Also extracts nym from nested user object, if necessary and removes 0 pct fowards
66
* @param {*} forward Array of forward objects ({nym?: string, pct: string, user?: { name: string } })
77
* @returns normalized array, or undefined if not provided
88
*/
99
export const normalizeForwards = (forward) => {
1010
if (!Array.isArray(forward)) {
1111
return undefined
1212
}
13-
return forward.filter(fwd => fwd.nym || fwd.user?.name).map(fwd => ({ nym: fwd.nym ?? fwd.user?.name, pct: Number(fwd.pct) }))
13+
return forward.filter(fwd => (fwd.nym || fwd.user?.name) && Number(fwd.pct) > 0).map(fwd => ({ nym: fwd.nym ?? fwd.user?.name, pct: Number(fwd.pct) }))
1414
}
1515

1616
export const toastUpsertSuccessMessages = (toaster, upsertResponseData, dataKey, itemText) => {

lib/validate.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,7 @@ export function advPostSchemaMembers ({ me, existingBoost = 0, ...args }) {
145145
},
146146
message: 'cannot forward to yourself'
147147
}),
148-
pct: intValidator.required('must specify a percentage').min(1, 'percentage must be at least 1').max(100, 'percentage must not exceed 100')
148+
pct: intValidator.required('must specify a percentage').min(0, 'percentage must be at least 0').max(100, 'percentage must not exceed 100')
149149
}))
150150
.compact((v) => !v.nym && !v.pct)
151151
.test({

0 commit comments

Comments
 (0)