From 8ee34be466fe7565a6fd755878c371d1c802cb21 Mon Sep 17 00:00:00 2001 From: Tulir Asokan Date: Tue, 10 Dec 2024 23:24:12 +0200 Subject: [PATCH] Revert "web/util: fix oxfordHumanJoin(React)? for two-element arrays" This reverts commit 3288d86e29dd5a0e73781f440f70c33f2b9e1608. --- web/src/ui/composer/TypingNotifications.tsx | 4 ++-- web/src/util/join.ts | 11 ++--------- web/src/util/reactjoin.tsx | 17 +++++------------ 3 files changed, 9 insertions(+), 23 deletions(-) diff --git a/web/src/ui/composer/TypingNotifications.tsx b/web/src/ui/composer/TypingNotifications.tsx index 499f94f..e901ad6 100644 --- a/web/src/ui/composer/TypingNotifications.tsx +++ b/web/src/ui/composer/TypingNotifications.tsx @@ -18,7 +18,7 @@ import { PulseLoader } from "react-spinners" import { getAvatarURL } from "@/api/media.ts" import { useRoomTyping } from "@/api/statestore" import { MemberEventContent } from "@/api/types/mxtypes.ts" -import { oxfordHumanJoinReact } from "@/util/reactjoin.tsx" +import { humanJoinReact } from "@/util/reactjoin.tsx" import ClientContext from "../ClientContext.ts" import { useRoomContext } from "../roomview/roomcontext.ts" import "./TypingNotifications.css" @@ -55,7 +55,7 @@ const TypingNotifications = () => { description =
{typing.length} users are typing
} else if (typing.length > 0) { description =
- {oxfordHumanJoinReact(memberNames)} + {humanJoinReact(memberNames)} {typing.length === 1 ? " is " : " are "} typing
diff --git a/web/src/util/join.ts b/web/src/util/join.ts index af7500e..2252efb 100644 --- a/web/src/util/join.ts +++ b/web/src/util/join.ts @@ -13,12 +13,7 @@ // // You should have received a copy of the GNU Affero General Public License // along with this program. If not, see . -export function humanJoin( - arr: string[], - sep: string = ", ", - sep2: string = " and ", - lastSep: string = " and ", -): string { +export function humanJoin(arr: string[], sep: string = ", ", lastSep: string = " and "): string { if (arr.length === 0) { return "" } @@ -26,9 +21,7 @@ export function humanJoin( return arr[0] } if (arr.length === 2) { - return arr.join(sep2) + return arr.join(lastSep) } return arr.slice(0, -1).join(sep) + lastSep + arr[arr.length - 1] } - -export const oxfordHumanJoin = (arr: string[]) => humanJoin(arr, ", ", " and ", ", and ") diff --git a/web/src/util/reactjoin.tsx b/web/src/util/reactjoin.tsx index 9997251..96f450d 100644 --- a/web/src/util/reactjoin.tsx +++ b/web/src/util/reactjoin.tsx @@ -18,20 +18,13 @@ import { Fragment, JSX } from "react" export function humanJoinReact( arr: (string | JSX.Element)[], sep: string | JSX.Element = ", ", - sep2: string | JSX.Element = " and ", lastSep: string | JSX.Element = " and ", ): JSX.Element[] { - return arr.map((elem, idx) => { - let separator = sep - if (idx === arr.length - 2) { - separator = (arr.length === 2) ? sep2 : lastSep - } - return + return arr.map((elem, idx) => + {elem} - {idx < arr.length - 1 ? separator : null} - - }) + {idx < arr.length - 1 ? (idx === arr.length - 2 ? lastSep : sep) : null} + ) } -export const oxfordHumanJoinReact = (arr: (string | JSX.Element)[]) => humanJoinReact(arr, ", ", " and ", ", and ") -export const joinReact = (arr: (string | JSX.Element)[]) => humanJoinReact(arr, " ", " ", " ") +export const joinReact = (arr: (string | JSX.Element)[]) => humanJoinReact(arr, " ", " ")