Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "yoji",
"productName": "yoji",
"version": "0.1.3",
"version": "0.1.4",
"private": true,
"description": "A desktop app for your tasks, calendar, inbox and AI agents, on a Convex backend you own.",
"license": "Apache-2.0",
Expand Down
17 changes: 13 additions & 4 deletions src/renderer/src/AgentButton.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,11 @@
// narrow composer, chips leave from the oldest end instead of shrinking. Like an inbox item, a chip clears with
// the × that opens a slot of its own after the title on hover or focus, a middle-click, ⌫, or Clear, Clear others and
// Clear all on a right-click, with Undo in a toast; the chat itself stays (agentChips.ts). After a clear by the × or a
// middle-click, an empty gap holds the chip's place until the pointer leaves the row, as Chrome holds its tabs, so the
// next chip never slides under the pointer; ⌫ and the menu let the row settle at once. While this row is on screen the
// middle-click, an empty gap holds the chip's place until the pointer leaves the row or rests on it for HOLD_REST, as
// Chrome holds its tabs, so a quick second click never lands on the next chip; a pointer that stays still (or a Mac that
// stops sending it moves, as under a screenshot) never leaves a hole in the row. ⌫ and the menu let the row settle at once. While this row is on screen the
// minimized dock (AgentPill) stays hidden, so the chats sit here instead of above the composer.
import { useLayoutEffect, useRef, useState, type ReactElement } from 'react';
import { useEffect, useLayoutEffect, useRef, useState, type ReactElement } from 'react';
import { AgentMark, Mark } from './AgentMark';
import { clearChips, restoreChips, useClearedChips } from './agentChips';
import { agentPanelShown, agentToggled } from './agentDismiss';
Expand Down Expand Up @@ -37,6 +38,9 @@ export function chipChats<T extends { _id: string; updatedAt: number }>(chats: r
return recentChats(chats).filter((c) => !cleared.includes(c._id)).reverse();
}

/** How long the pointer may rest on the row after a clear by the pointer before its gaps close anyway, in ms. */
export const HOLD_REST = 1000;

/** The width a chip gains on hover or focus to open the slot for its × (AgentPanel.css). */
export const X_SLOT = 18;

Expand Down Expand Up @@ -67,9 +71,14 @@ export function AgentButton(): ReactElement {
const row = useRef<HTMLDivElement>(null), cleared = useClearedChips(), chips = chipChats(chats, cleared);
const [menu, setMenu] = useState<{ x: number; y: number; id: string } | null>(null);
const [held, setHeld] = useState<Record<string, number>>({});
const rest = useRef<ReturnType<typeof setTimeout>>(undefined);
const settle = () => (clearTimeout(rest.current), setHeld({}));
const settleAtRest = () => (clearTimeout(rest.current), (rest.current = setTimeout(settle, HOLD_REST)));
useEffect(() => () => clearTimeout(rest.current), []);
const clearByPointer = (chip: HTMLElement, id: string) => {
const x = chip.querySelector('.x')!.getBoundingClientRect().width;
setHeld((h) => ({ ...h, [id]: chip.getBoundingClientRect().width - x }));
settleAtRest();
clearWithUndo([id]);
};
useLayoutEffect(() => {
Expand All @@ -80,7 +89,7 @@ export function AgentButton(): ReactElement {
useLayoutEffect(() => fitChips(row.current!));
const others = (id: string) => chips.filter((c) => c._id !== id).map((c) => c._id);
return (
<div className="ya-under" ref={row} onPointerLeave={() => setHeld({})}>
<div className="ya-under" ref={row} onPointerLeave={settle} onPointerMove={Object.keys(held).length ? settleAtRest : undefined}>
{recentChats(chats).reverse().map((c) => {
if (cleared.includes(c._id)) return held[c._id] !== undefined ? <span key={c._id} className="ya-held" style={{ width: held[c._id] }} aria-hidden="true" /> : null;
const shown = on && c._id === chatId;
Expand Down
27 changes: 26 additions & 1 deletion src/renderer/src/agentButton.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ beforeAll(() => {

const { getUI, setUI } = await import('./store');
const { getAgentChat, setAgentChat } = await import('../../shared/agentClient');
const { AgentButton, RECENT_CHATS, X_SLOT, chipChats, fitChips, recentChats } = await import('./AgentButton');
const { AgentButton, HOLD_REST, RECENT_CHATS, X_SLOT, chipChats, fitChips, recentChats } = await import('./AgentButton');
const { clearedChips, reloadAgentChips, trackAgentChips } = await import('./agentChips');
const { Sidebar } = await import('./Sidebar');
const { CaptainPane } = await import('./Captains');
Expand Down Expand Up @@ -282,6 +282,31 @@ describe('clearing chips', () => {
expect(css).toContain('.ya-held{flex:none;height:28px}');
});

it('closes the gap once the pointer rests on the row after a clear, so a still pointer never leaves a hole beside Agent', () => {
vi.useFakeTimers();
try {
data.chats = three();
render(createElement(AgentButton));
const row = document.querySelector('.ya-under')!;
const held = () => [...row.children].map((el) => (el.classList.contains('ya-held') ? 'gap' : el.querySelector('.t')?.textContent ?? 'Agent'));
act(() => (chips()[2]!.querySelector('.x') as HTMLElement).click());
expect(held()).toEqual(['Alpha', 'Bravo', 'gap', 'Agent']);
act(() => void vi.advanceTimersByTime(HOLD_REST - 100));
expect(held()).toEqual(['Alpha', 'Bravo', 'gap', 'Agent']);
act(() => void row.dispatchEvent(new PointerEvent('pointermove', { bubbles: true })));
act(() => void vi.advanceTimersByTime(HOLD_REST - 100));
expect(held()).toEqual(['Alpha', 'Bravo', 'gap', 'Agent']);
act(() => void chips()[1]!.dispatchEvent(new MouseEvent('auxclick', { bubbles: true, button: 1 })));
act(() => void vi.advanceTimersByTime(HOLD_REST - 100));
expect(held()).toEqual(['Alpha', 'gap', 'gap', 'Agent']);
act(() => void vi.advanceTimersByTime(100));
expect(held()).toEqual(['Alpha', 'Agent']);
expect(HOLD_REST).toBeLessThanOrEqual(1000);
} finally {
vi.useRealTimers();
}
});

it('clears one on a middle-click or ⌫, and a plain click still opens it', () => {
data.chats = three();
render(createElement(AgentButton));
Expand Down