mirror of
https://github.com/block/buzz.git
synced 2026-08-18 06:50:31 +02:00
fix(desktop): filter punctuation from avatar initials (#1904)
Signed-off-by: Wes <wesbillman@users.noreply.github.com> Co-authored-by: Pinky <44b8e82baa6e0e254e0208d68f335c283c94e7b78dd1fa10d5a49d3f13dd0435@sprout-oss.stage.blox.sqprod.co>
This commit is contained in:
@@ -9,7 +9,7 @@ import {
|
||||
communityIconQueryKey,
|
||||
} from "@/features/communities/useCommunityIcons";
|
||||
import { useCommunities } from "@/features/communities/useCommunities";
|
||||
import { communityInitials } from "@/features/sidebar/ui/CommunityRail";
|
||||
import { getInitials } from "@/shared/lib/initials";
|
||||
import { setCommunityIcon } from "@/shared/api/communityProfile";
|
||||
import { Button } from "@/shared/ui/button";
|
||||
|
||||
@@ -72,9 +72,7 @@ export function CommunityIconSettingsCard() {
|
||||
}
|
||||
|
||||
const icon = iconQuery.data ?? null;
|
||||
const initials = activeCommunity
|
||||
? communityInitials(activeCommunity.name)
|
||||
: "";
|
||||
const initials = activeCommunity ? getInitials(activeCommunity.name) : "";
|
||||
|
||||
return (
|
||||
<div className="space-y-1.5" data-testid="community-icon-settings">
|
||||
|
||||
@@ -1,25 +1,7 @@
|
||||
import assert from "node:assert/strict";
|
||||
import { describe, it } from "node:test";
|
||||
|
||||
import {
|
||||
communityInitials,
|
||||
communityRailIndicators,
|
||||
} from "./CommunityRail.tsx";
|
||||
|
||||
describe("communityInitials", () => {
|
||||
it("filters punctuation before deriving initials", () => {
|
||||
assert.equal(communityInitials("B (relay)"), "BR");
|
||||
});
|
||||
it("handles a leading symbol on a single word", () => {
|
||||
assert.equal(communityInitials("(staging)"), "S");
|
||||
});
|
||||
it("still returns plain initials for normal names", () => {
|
||||
assert.equal(communityInitials("Bravo Beta"), "BB");
|
||||
});
|
||||
it("returns empty for a symbol-only name (caller falls back)", () => {
|
||||
assert.equal(communityInitials("()"), "");
|
||||
});
|
||||
});
|
||||
import { communityRailIndicators } from "./CommunityRail.tsx";
|
||||
|
||||
describe("communityRailIndicators", () => {
|
||||
it("shows no badge for an observed community with unread but no mentions", () => {
|
||||
|
||||
@@ -36,12 +36,6 @@ type CommunityRailProps = {
|
||||
|
||||
const MAX_BADGE = 99;
|
||||
|
||||
// Strip punctuation before initials so "B (relay)" yields "BR", not "B(".
|
||||
export function communityInitials(name: string): string {
|
||||
const cleaned = name.replace(/[^\p{L}\p{N}\s]/gu, " ");
|
||||
return getInitials(cleaned);
|
||||
}
|
||||
|
||||
/**
|
||||
* Presentation decisions for one community button, derived from its observed
|
||||
* mention state. Pure so it can be unit-tested without a DOM. The `state` guard
|
||||
@@ -129,7 +123,7 @@ function CommunityButton({
|
||||
src={iconUrl}
|
||||
/>
|
||||
) : (
|
||||
communityInitials(community.name) || "🐝"
|
||||
getInitials(community.name) || "🐝"
|
||||
)}
|
||||
</span>
|
||||
{showBadge ? (
|
||||
|
||||
@@ -0,0 +1,22 @@
|
||||
import assert from "node:assert/strict";
|
||||
import { describe, it } from "node:test";
|
||||
|
||||
import { getInitials } from "./initials.ts";
|
||||
|
||||
describe("getInitials", () => {
|
||||
it("filters punctuation before deriving initials", () => {
|
||||
assert.equal(getInitials("B (relay)"), "BR");
|
||||
});
|
||||
|
||||
it("handles a leading symbol on a single word", () => {
|
||||
assert.equal(getInitials("(staging)"), "S");
|
||||
});
|
||||
|
||||
it("still returns plain initials for normal names", () => {
|
||||
assert.equal(getInitials("Bravo Beta"), "BB");
|
||||
});
|
||||
|
||||
it("returns empty for a symbol-only name", () => {
|
||||
assert.equal(getInitials("()"), "");
|
||||
});
|
||||
});
|
||||
@@ -1,6 +1,7 @@
|
||||
/** Derive up to two uppercase initials from a display name. */
|
||||
export function getInitials(name: string): string {
|
||||
return name
|
||||
.replace(/[^\p{L}\p{N}\s]/gu, " ")
|
||||
.trim()
|
||||
.split(/\s+/)
|
||||
.map((part) => part[0] ?? "")
|
||||
|
||||
Reference in New Issue
Block a user