From 5d74e72c92f7056acb70537fa26bc1983f357b76 Mon Sep 17 00:00:00 2001 From: Kalle <38327916+Sendouc@users.noreply.github.com> Date: Fri, 23 Oct 2026 18:17:52 +0300 Subject: [PATCH] Remove allTruthy in favor of plain && chains --- .../plus-suggestions-utils.ts | 34 +++++++++---------- app/utils/arrays.ts | 8 ----- 2 files changed, 17 insertions(+), 25 deletions(-) diff --git a/app/features/plus-suggestions/plus-suggestions-utils.ts b/app/features/plus-suggestions/plus-suggestions-utils.ts index f563994bf..c4a32f436 100644 --- a/app/features/plus-suggestions/plus-suggestions-utils.ts +++ b/app/features/plus-suggestions/plus-suggestions-utils.ts @@ -1,6 +1,5 @@ import type { Tables } from "~/db/tables"; import type * as PlusSuggestionRepository from "~/features/plus-suggestions/PlusSuggestionRepository.server"; -import { allTruthy } from "~/utils/arrays"; import type { UserWithPlusTier } from "~/utils/kysely.server"; import * as Seasons from "../mmr/core/Seasons"; import { isVotingActive } from "../plus-voting/core"; @@ -14,11 +13,12 @@ interface CanAddCommentToSuggestionArgs { export function canAddCommentToSuggestionFE( args: CanAddCommentToSuggestionArgs, ) { - return allTruthy([ - !alreadyCommentedByUser(args), - isPlusServerMember(args.user), - args.user?.plusTier && args.targetPlusTier >= args.user?.plusTier, - ]); + return Boolean( + !alreadyCommentedByUser(args) && + isPlusServerMember(args.user) && + args.user?.plusTier && + args.targetPlusTier >= args.user.plusTier, + ); } export function canAddCommentToSuggestionBE({ @@ -27,16 +27,16 @@ export function canAddCommentToSuggestionBE({ suggested, targetPlusTier, }: CanAddCommentToSuggestionArgs) { - return allTruthy([ + return Boolean( canAddCommentToSuggestionFE({ user, suggestions, suggested, targetPlusTier, - }), - playerAlreadySuggested({ suggestions, suggested, targetPlusTier }), - targetPlusTierIsSmallerOrEqual({ user, targetPlusTier }), - ]); + }) && + playerAlreadySuggested({ suggestions, suggested, targetPlusTier }) && + targetPlusTierIsSmallerOrEqual({ user, targetPlusTier }), + ); } function alreadyCommentedByUser({ @@ -89,12 +89,12 @@ export function canSuggestNewUser({ const existsSeason = Seasons.current() || Seasons.next(); - return allTruthy([ - !votingActive, - !hasSuggestedThisMonth, - isPlusServerMember(user), - existsSeason, - ]); + return Boolean( + !votingActive && + !hasSuggestedThisMonth && + isPlusServerMember(user) && + existsSeason, + ); } function isPlusServerMember(user?: Pick) { diff --git a/app/utils/arrays.ts b/app/utils/arrays.ts index 304235507..6d8efa601 100644 --- a/app/utils/arrays.ts +++ b/app/utils/arrays.ts @@ -1,11 +1,3 @@ -// TODO: when more examples of permissions profile difference between -// this implementation and one that takes arrays - -// (not all arrays need to necessarily run but they need to be defined) -export function allTruthy(arr: unknown[]) { - return arr.every(Boolean); -} - export function normalizeFormFieldArray( value: undefined | null | string | string[], ): string[] {