Revert "web/util: fix oxfordHumanJoin(React)? for two-element arrays"

This reverts commit 3288d86e29.
This commit is contained in:
Tulir Asokan 2024-12-10 23:24:12 +02:00
parent ac3438ad25
commit 8ee34be466
3 changed files with 9 additions and 23 deletions

View file

@ -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 = <div>{typing.length} users are typing</div>
} else if (typing.length > 0) {
description = <div>
{oxfordHumanJoinReact(memberNames)}
{humanJoinReact(memberNames)}
{typing.length === 1 ? " is " : " are "}
typing
</div>

View file

@ -13,12 +13,7 @@
//
// You should have received a copy of the GNU Affero General Public License
// along with this program. If not, see <https://www.gnu.org/licenses/>.
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 ")

View file

@ -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 <Fragment key={idx}>
return arr.map((elem, idx) =>
<Fragment key={idx}>
{elem}
{idx < arr.length - 1 ? separator : null}
</Fragment>
})
{idx < arr.length - 1 ? (idx === arr.length - 2 ? lastSep : sep) : null}
</Fragment>)
}
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, " ", " ")