Skip to content

Commit 7e10639

Browse files
vitalyiegorovclaude
andcommitted
fix(web): offset sidebar badge off the glyph and share the badge heuristic
The row badge sat fully inside the 14px glyph and swallowed it; use the same corner-offset geometry the composer trigger already uses. Extract the duplicated show-badge heuristic (three hand-rolled copies in the sidebar rows, ProviderModelPicker, and ModelPickerSidebar) into shouldShowInstanceBadge in providerInstances.ts. Co-Authored-By: Claude Fable 5 <[email protected]>
1 parent 931e4d1 commit 7e10639

4 files changed

Lines changed: 37 additions & 42 deletions

File tree

‎apps/web/src/components/Sidebar.tsx‎

Lines changed: 10 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,11 @@ import {
155155
import { ProjectFavicon } from "./ProjectFavicon";
156156
import { ProviderInstanceIcon } from "./chat/ProviderInstanceIcon";
157157
import { getTriggerDisplayModelLabel } from "./chat/providerIconUtils";
158-
import { deriveProviderInstanceEntries, type ProviderInstanceEntry } from "../providerInstances";
158+
import {
159+
deriveProviderInstanceEntries,
160+
shouldShowInstanceBadge,
161+
type ProviderInstanceEntry,
162+
} from "../providerInstances";
159163
import { primaryServerProvidersAtom } from "../state/server";
160164
import { useThreadRunningTerminalIds } from "../state/terminalSessions";
161165
import { stackedThreadToast, toastManager } from "./ui/toast";
@@ -238,21 +242,6 @@ function terminalProcessLabel(count: number): string {
238242
return `${count} terminal ${count === 1 ? "process" : "processes"} running`;
239243
}
240244

241-
// Several accounts on the same provider share one glyph, so the account badge
242-
// is the only thing telling them apart.
243-
function hasDuplicateDriverInstances(
244-
entries: ReadonlyMap<string, ProviderInstanceEntry>,
245-
driverKind: ProviderInstanceEntry["driverKind"],
246-
): boolean {
247-
let seen = false;
248-
for (const entry of entries.values()) {
249-
if (entry.driverKind !== driverKind) continue;
250-
if (seen) return true;
251-
seen = true;
252-
}
253-
return false;
254-
}
255-
256245
function SidebarThreadTooltip({
257246
thread,
258247
projectTitle,
@@ -336,8 +325,7 @@ function SidebarThreadTooltip({
336325
providerEntry?.displayName ?? thread.session?.providerName ?? modelInstanceId
337326
}
338327
accentColor={providerEntry?.accentColor}
339-
// Initials would swallow a size-3 glyph, so the accent reads as
340-
// a plain dot here and the account name lands in the label.
328+
// Initials would swallow a size-3 glyph: accent dot, name in label.
341329
showBadge={showInstanceBadge && providerEntry?.accentColor !== undefined}
342330
badgeContent="none"
343331
badgeClassName="h-2 min-w-2 px-0"
@@ -890,8 +878,7 @@ const SidebarThreadRow = memo(function SidebarThreadRow(props: {
890878
const driverKind = providerEntry?.driverKind ?? null;
891879
const showInstanceBadge =
892880
providerEntry !== null &&
893-
(Boolean(providerEntry.accentColor) ||
894-
hasDuplicateDriverInstances(props.providerEntryByInstanceId, providerEntry.driverKind));
881+
shouldShowInstanceBadge(providerEntry, props.providerEntryByInstanceId.values());
895882
const selectedModel = providerEntry?.models.find(
896883
(model) => model.slug === thread.modelSelection.model,
897884
);
@@ -1498,10 +1485,9 @@ const SidebarThreadRow = memo(function SidebarThreadRow(props: {
14981485
}
14991486
accentColor={providerEntry?.accentColor}
15001487
showBadge={showInstanceBadge}
1501-
// Only the glyph dims; the accent badge has to stay
1502-
// saturated to read as an account color.
1488+
// Glyph dims, badge stays saturated; offset matches the composer trigger.
15031489
iconClassName="size-3.5 opacity-60"
1504-
badgeClassName="h-3 min-w-3 px-0.5 text-[7px]"
1490+
badgeClassName="right-[-0.1875rem] bottom-[-0.1875rem] h-3 min-w-3 px-0.5 text-[7px]"
15051491
/>
15061492
</span>
15071493
) : null}
@@ -1560,8 +1546,7 @@ const SidebarSearchResultRow = memo(function SidebarSearchResultRow(props: {
15601546
const providerEntry = props.providerEntryByInstanceId.get(modelInstanceId) ?? null;
15611547
const showInstanceBadge =
15621548
providerEntry !== null &&
1563-
(Boolean(providerEntry.accentColor) ||
1564-
hasDuplicateDriverInstances(props.providerEntryByInstanceId, providerEntry.driverKind));
1549+
shouldShowInstanceBadge(providerEntry, props.providerEntryByInstanceId.values());
15651550
const selectedModel = providerEntry?.models.find(
15661551
(model) => model.slug === thread.modelSelection.model,
15671552
);

‎apps/web/src/components/chat/ModelPickerSidebar.tsx‎

Lines changed: 7 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,14 @@
11
import { type ProviderInstanceId } from "@t3tools/contracts";
2-
import { memo, useLayoutEffect, useMemo, useRef, useState } from "react";
2+
import { memo, useLayoutEffect, useRef, useState } from "react";
33
import { SparklesIcon, StarIcon } from "lucide-react";
44
import { ProviderInstanceIcon } from "./ProviderInstanceIcon";
55
import { Tooltip, TooltipPopup, TooltipTrigger } from "../ui/tooltip";
66
import { cn } from "~/lib/utils";
7-
import { isProviderInstancePickerReady, type ProviderInstanceEntry } from "../../providerInstances";
7+
import {
8+
isProviderInstancePickerReady,
9+
shouldShowInstanceBadge,
10+
type ProviderInstanceEntry,
11+
} from "../../providerInstances";
812

913
/**
1014
* Build the hover tooltip for an instance button. Mirrors the old
@@ -65,14 +69,6 @@ export const ModelPickerSidebar = memo(function ModelPickerSidebar(props: {
6569
const [hoveredInstanceId, setHoveredInstanceId] = useState<ProviderInstanceId | null>(null);
6670
const sidebarContentRef = useRef<HTMLDivElement>(null);
6771
const [selectedIndicatorTop, setSelectedIndicatorTop] = useState<number | null>(null);
68-
const duplicateDriverCounts = useMemo(() => {
69-
const counts = new Map<string, number>();
70-
for (const entry of props.instanceEntries) {
71-
counts.set(entry.driverKind, (counts.get(entry.driverKind) ?? 0) + 1);
72-
}
73-
return counts;
74-
}, [props.instanceEntries]);
75-
7672
useLayoutEffect(() => {
7773
const content = sidebarContentRef.current;
7874
if (!content) {
@@ -143,8 +139,7 @@ export const ModelPickerSidebar = memo(function ModelPickerSidebar(props: {
143139
const isSelected = props.selectedInstanceId === entry.instanceId;
144140
const isHovered = hoveredInstanceId === entry.instanceId;
145141
const showNewBadge = props.newBadgeInstanceIds?.has(entry.instanceId) ?? false;
146-
const showInstanceBadge =
147-
Boolean(entry.accentColor) || (duplicateDriverCounts.get(entry.driverKind) ?? 0) > 1;
142+
const showInstanceBadge = shouldShowInstanceBadge(entry, props.instanceEntries);
148143

149144
const tooltip = isUnavailable
150145
? describeUnavailableInstance(entry)

‎apps/web/src/components/chat/ProviderModelPicker.tsx‎

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ import {
1616
getTriggerDisplayModelLabel,
1717
getTriggerDisplayModelName,
1818
} from "./providerIconUtils";
19-
import type { ProviderInstanceEntry } from "../../providerInstances";
19+
import { shouldShowInstanceBadge, type ProviderInstanceEntry } from "../../providerInstances";
2020
import { ComposerControl, ComposerControlChevron } from "./ComposerControl";
2121

2222
export const ProviderModelPicker = memo(function ProviderModelPicker(props: {
@@ -67,10 +67,8 @@ export const ProviderModelPicker = memo(function ProviderModelPicker(props: {
6767
selectedInstanceOptions[0];
6868
const triggerTitle = selectedModel ? getTriggerDisplayModelName(selectedModel) : props.model;
6969
const triggerLabel = selectedModel ? getTriggerDisplayModelLabel(selectedModel) : props.model;
70-
const duplicateDriverCount = props.instanceEntries.filter(
71-
(entry) => activeEntry !== null && entry.driverKind === activeEntry.driverKind,
72-
).length;
73-
const showInstanceBadge = Boolean(activeEntry?.accentColor) || duplicateDriverCount > 1;
70+
const showInstanceBadge =
71+
activeEntry !== null && shouldShowInstanceBadge(activeEntry, props.instanceEntries);
7472

7573
const setIsMenuOpen = (open: boolean) => {
7674
props.onOpenChange?.(open);

‎apps/web/src/providerInstances.ts‎

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,23 @@ function driverKindLabel(driverKind: ProviderDriverKind): string {
109109
return PROVIDER_DISPLAY_NAMES[driverKind] ?? formatProviderDriverKindLabel(driverKind);
110110
}
111111

112+
/**
113+
* Whether an instance's icon carries the account badge: accent color set, or
114+
* several instances sharing a driver so the brand glyph alone is ambiguous.
115+
* Shared by the composer trigger, the picker rail, and sidebar rows.
116+
*/
117+
export function shouldShowInstanceBadge(
118+
entry: ProviderInstanceEntry,
119+
entries: Iterable<ProviderInstanceEntry>,
120+
): boolean {
121+
if (entry.accentColor) return true;
122+
let sharedDriverCount = 0;
123+
for (const candidate of entries) {
124+
if (candidate.driverKind === entry.driverKind && ++sharedDriverCount > 1) return true;
125+
}
126+
return false;
127+
}
128+
112129
export function normalizeProviderAccentColor(value: string | undefined): string | undefined {
113130
const trimmed = value?.trim();
114131
if (!trimmed) return undefined;

0 commit comments

Comments
 (0)