Skip to content

armgit / kwant

Public Imported from GitHub
0

Your own team of AI bots in one self-hosted binary: spaces, every account you have, handoffs, approvals and routines. Open-source, self-hosted alternative to Grok Bot, Claude Duet and OpenAI dots. Rust + React.

18e team-chips-plain: team named once, long names stay in their pill, Approve hands focus back (#670)

Oleksandr Ivanchenko8ef6af74a40c
diff --git a/frontend/src/approvalAsk.ts b/frontend/src/approvalAsk.ts
index 99479f69..3b70ed59 100644
--- a/frontend/src/approvalAsk.ts
+++ b/frontend/src/approvalAsk.ts
@@ -57,3 +57,13 @@ export const APPROVE_TEXT = 'Approved, go ahead.';
export const changePlaceholder = (name: string): string => `What should ${name} change?`;
/** The row's caption and group name. */
export const waitingCaption = (name: string): string => `${name} is waiting for your OK`;
+
+/**
+ * 18e: after Approve settles, put focus back in the composer on desktop when the person's focus was lost with the
+ * row (it unmounts when the reply lands, leaving focus on <body>) or still sits in the row (a failed send).
+ * Never on a phone (it would open the keyboard) and never when they already moved focus somewhere else.
+ */
+export function refocusAfterApprove(o: { phone: boolean; focusLost: boolean; inRow: boolean }): boolean {
+ if (o.phone) return false;
+ return o.focusLost || o.inRow;
+}
diff --git a/frontend/src/botHome.ts b/frontend/src/botHome.ts
index 51bc6bde..a72b6fb5 100644
--- a/frontend/src/botHome.ts
+++ b/frontend/src/botHome.ts
@@ -150,6 +150,16 @@ export function teamAnswerLine(teamName?: string): string {
return `${teamName ? `The ${teamNamed(teamName)}` : 'The team'} answers. Type\u00a0@ and a name to ask one member.`;
}
+/** 18e: the Ask row's team chip says the name once ("@Booktun.ing Team"); the Users icon already says "team". */
+export function teamChipLabel(teamName: string): string {
+ return `@${teamName.trim()}`;
+}
+
+/** 18e: the team chip's title and accessible name, without "team team": "Ask the whole Booktun.ing Team". */
+export function teamChipTitle(teamName: string): string {
+ return `Ask the whole ${teamNamed(teamName)}`;
+}
+
/** "helpers" → "helpers team"; "Booktun.ing Team" stays as it is (no "team team"). */
export function teamNamed(name: string): string {
return /\bteam$/i.test(name.trim()) ? name.trim() : `${name.trim()} team`;
diff --git a/frontend/src/components/ChatView.tsx b/frontend/src/components/ChatView.tsx
index ab1bedcc..cec0793a 100644
--- a/frontend/src/components/ChatView.tsx
+++ b/frontend/src/components/ChatView.tsx
@@ -17,7 +17,7 @@ import { ModernAvatar } from './ModernAvatar';
import { WorkingAvatar } from './WorkingAvatar';
import { BotHome } from './BotHome';
import { accountCardShows } from '../firstScreen';
-import { ChatHome, answerTarget, goodAt, recipientsOf, teamAnswerLine } from '../botHome';
+import { ChatHome, answerTarget, goodAt, recipientsOf, teamAnswerLine, teamChipLabel, teamChipTitle } from '../botHome';
import { moodNoticed } from '../kwantMood';
import { NewTag } from './NewTag';
import { PHONE_QUERY, TOUCH_QUERY } from '../layout';
@@ -82,7 +82,7 @@ import { ConnectionSuggestionMeta, parseConnectionMeta } from '../connectionSugg
import { routeReasonText, routeWhyText } from '../routeReason';
import { useInbox } from '../inboxStore';
import { doneItemsOf, doneOf } from '../replyDone';
-import { APPROVE_TEXT, asksApproval, changePlaceholder, metaHidesApprove } from '../approvalAsk';
+import { APPROVE_TEXT, asksApproval, changePlaceholder, metaHidesApprove, refocusAfterApprove } from '../approvalAsk';
import { DoneCheckLine } from './DoneMarker';
import { ApproveRow } from './ApproveRow';
import { CopyGhost } from './CopyGhost';
@@ -1215,12 +1215,21 @@ export const ChatView: React.FC<ChatViewProps> = ({
setApproving(msg.id);
playSfx('click');
stickRef.current = true;
+ // 18e: remember the row so focus can come back to the composer instead of the page top.
+ const row = (document.activeElement as HTMLElement | null)?.closest?.('[data-approve-row]') ?? null;
try {
const sent = await onSendMessage(APPROVE_TEXT, [], { replyTo: msg });
// A failed send keeps the row (it is still the newest message) and offers the words in the composer.
if (sent === false) setInputVal((now) => now || APPROVE_TEXT);
} finally {
setApproving(null);
+ // After React commits (the row may unmount, the button re-enables), check where focus ended up.
+ setTimeout(() => {
+ const active = document.activeElement;
+ const focusLost = !active || active === document.body || !active.isConnected;
+ const inRow = !!row && row.isConnected && !!active && row.contains(active);
+ if (refocusAfterApprove({ phone, focusLost, inRow })) focusComposer();
+ }, 0);
}
};
const react = async (msg: ChatMessage, reaction: Reaction | null): Promise<boolean> => {
@@ -2671,13 +2680,15 @@ export const ChatView: React.FC<ChatViewProps> = ({
data-compact={phone ? '' : undefined}
className={
phone
- ? 'kws-hit h-7 shrink-0 whitespace-nowrap flex items-center gap-1.5 px-2.5 rounded-full bg-sky-950/60 hover:bg-sky-900/60 text-sky-300 hover:text-sky-200 border border-sky-800/60 transition-all text-xs cursor-pointer shadow-sm active:scale-95'
- : 'shrink-0 whitespace-nowrap flex items-center gap-1.5 px-2.5 py-1 rounded-full bg-sky-950/60 hover:bg-sky-900/60 text-sky-300 hover:text-sky-200 border border-sky-800/60 transition-all text-xs cursor-pointer shadow-sm active:scale-95'
+ ? 'kws-hit h-7 shrink-0 max-w-[14rem] whitespace-nowrap flex items-center gap-1.5 px-2.5 rounded-full bg-sky-950/60 hover:bg-sky-900/60 text-sky-300 hover:text-sky-200 border border-sky-800/60 transition-all text-xs cursor-pointer shadow-sm active:scale-95'
+ : 'shrink-0 max-w-[14rem] whitespace-nowrap flex items-center gap-1.5 px-2.5 py-1 rounded-full bg-sky-950/60 hover:bg-sky-900/60 text-sky-300 hover:text-sky-200 border border-sky-800/60 transition-all text-xs cursor-pointer shadow-sm active:scale-95'
}
- title={`Ask whole team @${teamName}`}
+ title={teamChipTitle(teamName)}
+ aria-label={teamChipTitle(teamName)}
+ data-team-chip=""
>
- <Users size={12} className="text-sky-400" />
- <span>@{teamName} (Team)</span>
+ <Users size={12} className="shrink-0 text-sky-400" aria-hidden="true" />
+ <span className="min-w-0 truncate">{teamChipLabel(teamName)}</span>
</button>
)}
</ScrollRow>
@@ -2987,12 +2998,13 @@ export const ChatView: React.FC<ChatViewProps> = ({
>
{showAnswers && (
<span
- className={`kw-chip shrink-0 ${target.kind === 'laya' ? 'kw-chip-accent' : target.kind === 'mention' ? 'kw-chip-info' : ''}`}
+ className={`kw-chip min-w-0 ${showHintText ? 'max-w-[min(22rem,60%)]' : 'max-w-full'} ${target.kind === 'laya' ? 'kw-chip-accent' : target.kind === 'mention' ? 'kw-chip-info' : ''}`}
title={target.detail}
data-answer-target={target.kind}
>
- {target.kind === 'laya' ? <Sparkles size={12} aria-hidden="true" /> : <AtSign size={12} aria-hidden="true" />}
- <span className="text-zinc-400 font-normal">Answers:</span> {target.kind === 'laya' ? target.label : target.label.replace(/^@/, '')}
+ {target.kind === 'laya' ? <Sparkles size={12} className="shrink-0" aria-hidden="true" /> : <AtSign size={12} className="shrink-0" aria-hidden="true" />}
+ <span className="shrink-0 whitespace-nowrap text-zinc-400 font-normal">Answers:</span>
+ <span className="min-w-0 truncate" data-answer-name="">{target.kind === 'laya' ? target.label : target.label.replace(/^@/, '')}</span>
</span>
)}
{showHintText && (
diff --git a/frontend/tests/mobileCards.test.mjs b/frontend/tests/mobileCards.test.mjs
index 9f431b06..0f2e645a 100644
--- a/frontend/tests/mobileCards.test.mjs
+++ b/frontend/tests/mobileCards.test.mjs
@@ -347,11 +347,11 @@ test('Ask chips on a phone: 28 px to look at, 44 px to tap; desktop chips unchan
const src = readFileSync(new URL('../src/components/ChatView.tsx', import.meta.url), 'utf8');
const start = src.indexOf('aria-label="Ask a member"');
const block = src.slice(src.lastIndexOf('<ScrollRow', start), src.indexOf('</ScrollRow>', start));
- // The exact desktop classes from before 0.7.5, row and both chip kinds.
+ // The exact desktop classes from before 0.7.5, row and both chip kinds (18e: the team chip gains a 14rem cap).
for (const desk of [
"'kw-scroll-row max-w-4xl mx-auto mb-2.5 flex items-center gap-1.5 overflow-x-auto text-xs select-none'",
"'shrink-0 whitespace-nowrap flex items-center gap-1.5 px-2.5 py-1 rounded-full bg-zinc-800/90 hover:bg-zinc-700 text-zinc-300 hover:text-zinc-100 border border-zinc-700/60 transition-all text-xs cursor-pointer shadow-sm active:scale-95'",
- "'shrink-0 whitespace-nowrap flex items-center gap-1.5 px-2.5 py-1 rounded-full bg-sky-950/60 hover:bg-sky-900/60 text-sky-300 hover:text-sky-200 border border-sky-800/60 transition-all text-xs cursor-pointer shadow-sm active:scale-95'",
+ "'shrink-0 max-w-[14rem] whitespace-nowrap flex items-center gap-1.5 px-2.5 py-1 rounded-full bg-sky-950/60 hover:bg-sky-900/60 text-sky-300 hover:text-sky-200 border border-sky-800/60 transition-all text-xs cursor-pointer shadow-sm active:scale-95'",
])
assert.ok(block.includes(desk), desk);
const phoneChips = [...block.matchAll(/\? '(kws-hit[^']*)'/g)].map((x) => x[1]);
diff --git a/frontend/tests/teamChips.test.mjs b/frontend/tests/teamChips.test.mjs
new file mode 100644
index 00000000..4b041f86
--- /dev/null
+++ b/frontend/tests/teamChips.test.mjs
@@ -0,0 +1,59 @@
+// 18e team-chips-plain: a team chat names the team once, long names stay inside their pill, and Approve hands
+// focus back to the composer on desktop.
+import assert from 'node:assert/strict';
+import test from 'node:test';
+import { readFileSync } from 'node:fs';
+import { loadBundled } from './bundle.mjs';
+
+const m = await loadBundled(`
+ export { teamChipLabel, teamChipTitle, answerTarget } from './src/botHome';
+ export { refocusAfterApprove } from './src/approvalAsk';
+`);
+const chat = readFileSync(new URL('../src/components/ChatView.tsx', import.meta.url), 'utf8');
+
+test('the team chip names the team once, without "(Team)"', () => {
+ assert.equal(m.teamChipLabel('Booktun.ing Team'), '@Booktun.ing Team');
+ assert.equal(m.teamChipLabel('helpers'), '@helpers');
+ assert.equal(m.teamChipLabel(' Booktun.ing Marketing Operations Team '), '@Booktun.ing Marketing Operations Team');
+ assert.doesNotMatch(chat, /\(Team\)/);
+ assert.doesNotMatch(chat, /Ask whole team/);
+});
+
+test('the team chip title says "the whole … team" without doubling "team"', () => {
+ assert.equal(m.teamChipTitle('Booktun.ing Team'), 'Ask the whole Booktun.ing Team');
+ assert.equal(m.teamChipTitle('helpers'), 'Ask the whole helpers team');
+ assert.equal(m.teamChipTitle('Ops TEAM'), 'Ask the whole Ops TEAM');
+ assert.doesNotMatch(m.teamChipTitle('Booktun.ing Team'), /team team/i);
+});
+
+test('a long team name truncates inside the chip and the Answers pill; the full name stays in the title', () => {
+ const chip = chat.slice(chat.indexOf('data-team-chip'), chat.indexOf('data-team-chip') + 400);
+ assert.match(chat, /bg-sky-950\/60[^']*'/);
+ assert.equal((chat.match(/max-w-\[14rem\] whitespace-nowrap flex items-center gap-1\.5 px-2\.5[^']*bg-sky-950\/60/g) ?? []).length, 2);
+ assert.match(chip, /className="min-w-0 truncate">\{teamChipLabel\(teamName\)\}/);
+ assert.match(chat, /title=\{teamChipTitle\(teamName\)\}/);
+ const pill = chat.slice(chat.indexOf('data-answer-target'), chat.indexOf('data-answer-name') + 200);
+ // Beside the hint text it takes at most 22rem or 60% of the row; alone (phone) it may use the whole row.
+ assert.match(chat, /kw-chip min-w-0 \$\{showHintText \? 'max-w-\[min\(22rem,60%\)\]' : 'max-w-full'\}/);
+ assert.match(pill, /shrink-0 whitespace-nowrap text-zinc-400 font-normal">Answers:/);
+ assert.match(pill, /className="min-w-0 truncate" data-answer-name/);
+ // answerTarget's words are unchanged (18e doesn't touch them): the title keeps the full name.
+ const t = m.answerTarget({ kind: 'team', text: '', teamName: 'Booktun.ing Marketing Operations Team', names: [] });
+ assert.equal(t.label, '@Booktun.ing Marketing Operations Team');
+ assert.match(t.detail, /^@Booktun\.ing Marketing Operations Team answers\./);
+});
+
+test('focus returns to the composer after Approve on desktop only when it was lost or still in the row', () => {
+ // The row unmounted with the reply: focus fell to <body>.
+ assert.equal(m.refocusAfterApprove({ phone: false, focusLost: true, inRow: false }), true);
+ // A failed send keeps the row; focus is still on Approve.
+ assert.equal(m.refocusAfterApprove({ phone: false, focusLost: false, inRow: true }), true);
+ // The person already moved on (Tab to another control, clicked the sidebar): leave it.
+ assert.equal(m.refocusAfterApprove({ phone: false, focusLost: false, inRow: false }), false);
+ // Never on a phone: focusing the field would open the keyboard.
+ assert.equal(m.refocusAfterApprove({ phone: true, focusLost: true, inRow: false }), false);
+ assert.equal(m.refocusAfterApprove({ phone: true, focusLost: false, inRow: true }), false);
+ const approve = chat.slice(chat.indexOf('const approve = async'), chat.indexOf('const react = async'));
+ assert.match(approve, /finally \{[\s\S]*refocusAfterApprove\(\{ phone, focusLost, inRow \}\)\) focusComposer\(\)/);
+ assert.match(approve, /closest\?\.\('\[data-approve-row\]'\)/);
+});