Skip to content

The agent that grows with you

fix(desktop): disband via ConfirmDialog, close without onBack, lazy previews

unsupportedpastels537b410a740c
diff --git a/apps/desktop/src/plugins/hermes-bots/canonical-group-header.tsx b/apps/desktop/src/plugins/hermes-bots/canonical-group-header.tsx
index 6eec7ab495e..142eae271b5 100644
--- a/apps/desktop/src/plugins/hermes-bots/canonical-group-header.tsx
+++ b/apps/desktop/src/plugins/hermes-bots/canonical-group-header.tsx
@@ -1,4 +1,4 @@
-import { Button, Input } from '@hermes/plugin-sdk'
+import { Button, ConfirmDialog, Input } from '@hermes/plugin-sdk'
import { useState } from 'react'
import { CanonicalGroupRoster, type CanonicalMemberPhase } from './canonical-group-activity'
@@ -9,7 +9,7 @@ interface CanonicalGroupHeaderProps {
busy: boolean
canStop: boolean
onBack?: () => void
- onDisband: () => void
+ onDisband: () => Promise<void>
onRename: (name: string) => void
onStop: () => void
phases: Map<string, CanonicalMemberPhase>
@@ -27,11 +27,6 @@ export function CanonicalGroupHeader({ busy, canStop, onBack, onDisband, onRenam
if (name) {onRename(name)}
}
- const end = () => {
- setEnding(false)
- onDisband()
- }
-
return <>
<header className="flex items-center gap-2">
{onBack && <Button onClick={onBack}>{labels.back}</Button>}
@@ -48,10 +43,8 @@ export function CanonicalGroupHeader({ busy, canStop, onBack, onDisband, onRenam
<Button disabled={busy || !renaming.trim()} type="submit">{labels.save}</Button>
<Button onClick={() => setRenaming(null)} type="button">{labels.cancel}</Button>
</form>}
- {ending && <div aria-label={labels.disbandTitle} role="alertdialog">
- <p>{labels.disbandTitle}</p>
- <Button disabled={busy} onClick={end}>{labels.disband}</Button>
- <Button onClick={() => setEnding(false)}>{labels.cancel}</Button>
- </div>}
+ {ending && <ConfirmDialog busyLabel={labels.disbanding} confirmLabel={labels.disband}
+ description={<span>{labels.disbandDescPrefix}<span className="font-medium text-foreground">{room?.name}</span>{labels.disbandDescSuffix(room?.members?.length ?? 0)}</span>}
+ destructive doneLabel={labels.disbandDone} onClose={() => setEnding(false)} onConfirm={onDisband} open title={labels.disbandTitle} />}
</>
}
diff --git a/apps/desktop/src/plugins/hermes-bots/canonical-group-history.tsx b/apps/desktop/src/plugins/hermes-bots/canonical-group-history.tsx
index d4b8a5b352b..cf1f8c56519 100644
--- a/apps/desktop/src/plugins/hermes-bots/canonical-group-history.tsx
+++ b/apps/desktop/src/plugins/hermes-bots/canonical-group-history.tsx
@@ -1,5 +1,5 @@
import * as sdk from '@hermes/plugin-sdk'
-import { useEffect, useState } from 'react'
+import { useEffect, useRef, useState } from 'react'
import { type CanonicalGroupAttachment, CanonicalGroupAttachments, fetchCanonicalGroupAttachment } from './canonical-group-attachments'
import { useCanonicalGroupLabels } from './canonical-group-labels'
@@ -73,12 +73,25 @@ function ImagePreview({ binding, eventId, attachment, disabled }: {
binding: CanonicalGroupBinding; eventId: string; attachment: CanonicalGroupAttachment; disabled: boolean
}) {
const [src, setSrc] = useState('')
+ const [near, setNear] = useState(false)
+ const box = useRef<HTMLDivElement>(null)
const { attachment_id: attachmentId, size } = attachment
const { connectionId, profile, roomId } = binding
- const previewable = size !== undefined && size <= IMAGE_PREVIEW_MAX_BYTES
+ const previewable = !!attachmentId && size !== undefined && size <= IMAGE_PREVIEW_MAX_BYTES
+ // History loads the whole room: fetch only near the viewport, which also bounds concurrent downloads.
useEffect(() => {
- if (disabled || !attachmentId || !previewable) {return}
+ const el = box.current
+
+ if (near || !el) {return}
+ const observer = new IntersectionObserver(entries => { if (entries.some(entry => entry.isIntersecting)) {setNear(true)} }, { rootMargin: '200px' })
+ observer.observe(el)
+
+ return () => observer.disconnect()
+ }, [near])
+
+ useEffect(() => {
+ if (disabled || !near || !attachmentId || !previewable) {return}
let cancelled = false
let url = ''
// A failed preview leaves the Download button as the way to the file.
@@ -89,9 +102,9 @@ function ImagePreview({ binding, eventId, attachment, disabled }: {
}, () => undefined)
return () => { cancelled = true; URL.revokeObjectURL(url); setSrc('') }
- }, [connectionId, profile, roomId, eventId, attachmentId, disabled, previewable])
+ }, [connectionId, profile, roomId, eventId, attachmentId, disabled, near, previewable])
- return src ? <img alt={attachment.name} className="max-h-64 max-w-full rounded object-contain" src={src} /> : null
+ return previewable ? <div ref={box}>{src && <img alt={attachment.name} className="max-h-64 max-w-full rounded object-contain" src={src} />}</div> : null
}
export function CanonicalGroupHistory({ binding, events, members = [], disabled = false }: CanonicalGroupHistoryProps) {
diff --git a/apps/desktop/src/plugins/hermes-bots/canonical-group-labels.ts b/apps/desktop/src/plugins/hermes-bots/canonical-group-labels.ts
index 57ae8392ad8..55c348fe622 100644
--- a/apps/desktop/src/plugins/hermes-bots/canonical-group-labels.ts
+++ b/apps/desktop/src/plugins/hermes-bots/canonical-group-labels.ts
@@ -21,6 +21,10 @@ export function useCanonicalGroupLabels() {
renameLabel: t.fileMenu.renameLabel,
save: t.common.save,
disband: group.disbandAction,
+ disbanding: group.disbanding,
+ disbandDone: group.disbandDone,
+ disbandDescPrefix: group.disbandDescPrefix,
+ disbandDescSuffix: group.disbandDescSuffix,
disbandTitle: group.disbandTitle
}
}
diff --git a/apps/desktop/src/plugins/hermes-bots/canonical-group-workspace.test.tsx b/apps/desktop/src/plugins/hermes-bots/canonical-group-workspace.test.tsx
index 8cd12a1dd06..697cad8d222 100644
--- a/apps/desktop/src/plugins/hermes-bots/canonical-group-workspace.test.tsx
+++ b/apps/desktop/src/plugins/hermes-bots/canonical-group-workspace.test.tsx
@@ -10,8 +10,9 @@ vi.mock('@hermes/plugin-sdk', async () => {
const gateway = createGroupGateway()
const { en } = await import('@/i18n/en')
const { CANONICAL_GROUP_LOCALES } = await import('./canonical-group-locales')
+ const { ConfirmDialog } = await import('@/components/ui/confirm-dialog')
- return { ...await pluginSdkMock(gateway.host), atom, useValue: useStore,
+ return { ...await pluginSdkMock(gateway.host), atom, useValue: useStore, ConfirmDialog,
useI18n: () => ({ t: en }),
usePluginI18n: () => (key: string) => CANONICAL_GROUP_LOCALES.en[key.replace('canonical.', '') as keyof typeof CANONICAL_GROUP_LOCALES.en] ?? key,
Button: (p: ComponentProps<'button'>) => <button {...p} />,
@@ -22,10 +23,11 @@ vi.mock('@hermes/plugin-sdk', async () => {
import { registerCanonicalGroup } from './canonical-group-registry'
import { prepareCanonicalGroupSend, readCanonicalGroupSend } from './canonical-group-send'
import { CanonicalGroupWorkspace } from './canonical-group-workspace'
+import { $groupChatWorkspace } from './group-chat'
import { GroupChatWorkspace } from './group-chat-view'
const originalDesktop = window.hermesDesktop
beforeEach(() => { Object.defineProperty(window, 'hermesDesktop', { configurable: true, writable: true, value: undefined }) })
-afterEach(() => { cleanup(); request.mockReset(); localStorage.clear(); window.hermesDesktop = originalDesktop })
+afterEach(() => { cleanup(); request.mockReset(); localStorage.clear(); window.hermesDesktop = originalDesktop; vi.unstubAllGlobals() })
it('preserves the unsent draft when only the room display name changes', async () => {
request.mockImplementation(async (_route, method) => method === 'groups.state'
@@ -225,9 +227,11 @@ it('describes only a send restored from the journal as restored, never an ordina
await screen.findByText(/unconfirmed send was restored/)
})
-it('renames the room and disbands it only after confirmation, through the gateway handlers', async () => {
+it('renames the room and disbands it only through ConfirmDialog, which stays open with a failed disband\'s error', async () => {
const onBack = vi.fn()
- request.mockImplementation(async (_route, method) => roomReads()(method) ?? {})
+ let disbands = 0
+ request.mockImplementation(async (_route, method) => roomReads()(method)
+ ?? (method === 'groups.disband' && ++disbands === 1 ? Promise.reject(new Error('disband failed')) : {}))
render(<CanonicalGroupWorkspace binding={{ connectionId: 'remote', profile: 'team', roomId: 'controls' }} onBack={onBack} />)
fireEvent.click(await screen.findByRole('button', { name: 'Rename' }))
fireEvent.change(screen.getByRole('textbox', { name: 'New name' }), { target: { value: ' Renamed ' } })
@@ -237,9 +241,26 @@ it('renames the room and disbands it only after confirmation, through the gatewa
await waitFor(() => expect(disband.disabled).toBe(false))
fireEvent.click(disband)
expect(request.mock.calls.some(c => c[1] === 'groups.disband')).toBe(false)
- fireEvent.click(within(screen.getByRole('alertdialog')).getByRole('button', { name: /disband/i }))
+ const dialog = await screen.findByRole('dialog')
+ fireEvent.click(within(dialog).getByRole('button', { name: /disband/i }))
+ await within(dialog).findByText('disband failed')
+ expect(onBack).not.toHaveBeenCalled()
+ fireEvent.click(within(screen.getByRole('dialog')).getByRole('button', { name: /disband/i }))
await waitFor(() => expect(onBack).toHaveBeenCalledOnce())
- expect(request.mock.calls.find(c => c[1] === 'groups.disband')?.[2]).toMatchObject({ room_id: 'controls', cancel_id: expect.any(String) })
+ expect(request.mock.calls.filter(c => c[1] === 'groups.disband').map(c => c[2])).toEqual([
+ expect.objectContaining({ room_id: 'controls', cancel_id: expect.any(String) }), expect.objectContaining({ room_id: 'controls' })])
+})
+
+it('leaves the in-panel room after a disband even though no tab supplies onBack', async () => {
+ request.mockImplementation(async (_route, method) => roomReads()(method) ?? {})
+ const group = registerCanonicalGroup({ connectionId: 'local', profile: 'default' }, { room_id: 'panel', name: 'Room', members: [] })
+ $groupChatWorkspace.set(group)
+ render(<GroupChatWorkspace group={group} members={[]} origin="key" />)
+ const disband = await screen.findByRole('button', { name: /disband/i }) as HTMLButtonElement
+ await waitFor(() => expect(disband.disabled).toBe(false))
+ fireEvent.click(disband)
+ fireEvent.click(within(await screen.findByRole('dialog')).getByRole('button', { name: /disband/i }))
+ await waitFor(() => expect($groupChatWorkspace.get()).toBeNull())
})
it('@-completes room members with the exact handle the gateway resolves', async () => {
@@ -263,7 +284,12 @@ it('uploads pasted and dropped files through the room upload and previews commit
request.mockImplementation(async (_route, method, params) => roomReads([], events)(method)
?? (method === 'groups.attachment.upload' ? { attachment_id: `att-${params.name}`, kind: params.kind, name: params.name, mime: params.mime, size: 1 }
: method === 'groups.attachment.download' ? { ...image, data_base64: 'QQ==' } : {}))
+ const observers: IntersectionObserverCallback[] = []
+ vi.stubGlobal('IntersectionObserver', class { constructor(callback: IntersectionObserverCallback) { observers.push(callback) } observe() {} disconnect() {} })
render(<CanonicalGroupWorkspace binding={{ connectionId: 'local', profile: 'team', roomId: 'paste' }} />)
+ await waitFor(() => expect(observers).toHaveLength(1))
+ expect(request.mock.calls.some(c => c[1] === 'groups.attachment.download')).toBe(false)
+ act(() => observers[0]([{ isIntersecting: true }] as IntersectionObserverEntry[], {} as IntersectionObserver))
await waitFor(() => expect(screen.getByRole('img', { name: 'shot.png' }).getAttribute('src')).toBe('blob:preview'))
expect(request.mock.calls.filter(c => c[1] === 'groups.attachment.download').map(c => c[2].attachment_id)).toEqual(['img'])
const box = screen.getByRole('textbox')
diff --git a/apps/desktop/src/plugins/hermes-bots/canonical-group-workspace.tsx b/apps/desktop/src/plugins/hermes-bots/canonical-group-workspace.tsx
index ecb9767e52d..20280fc1210 100644
--- a/apps/desktop/src/plugins/hermes-bots/canonical-group-workspace.tsx
+++ b/apps/desktop/src/plugins/hermes-bots/canonical-group-workspace.tsx
@@ -165,9 +165,12 @@ function CanonicalRoomView({ binding: initialBinding, visible, onBack }: {
const rename = (name: string) =>
void mutate(() => canonicalGroupRequest(binding, 'groups.rename', { room_id: binding.roomId, event_id: crypto.randomUUID(), name }))
- // A disbanded room no longer reads back, so leave it instead of refreshing.
- const end = () =>
- void mutate(() => canonicalGroupRequest(binding, 'groups.disband', { room_id: binding.roomId, cancel_id: crypto.randomUUID() }), () => onBack?.())
+ // Rejects so ConfirmDialog stays open with the error; a disbanded room no longer reads back, so leave it.
+ const end = async () => {
+ await canonicalGroupRequest(binding, 'groups.disband', { room_id: binding.roomId, cancel_id: crypto.randomUUID() })
+
+ if (alive.current) {onBack?.()}
+ }
const composerLocked = !restored || busy || !!pending
const phases = canonicalMemberPhases(state?.driver_status)
diff --git a/apps/desktop/src/plugins/hermes-bots/group-chat-view.tsx b/apps/desktop/src/plugins/hermes-bots/group-chat-view.tsx
index ffce9562459..ef9ba68ddb2 100644
--- a/apps/desktop/src/plugins/hermes-bots/group-chat-view.tsx
+++ b/apps/desktop/src/plugins/hermes-bots/group-chat-view.tsx
@@ -591,7 +591,8 @@ export function GroupChatWorkspace(props: GroupChatWorkspaceProps) {
const profile = useValue(host.state.profile)
const binding = canonicalGroupBindingFor(bindings, { connectionId: connectionId ?? '', profile }, props.group, props.origin ?? 'name')
- if (binding) {return <CanonicalGroupWorkspace binding={binding} onBack={props.onBack} visible={props.visible} />}
+ // The in-panel fallback has no tab to close, so leaving deselects the room, as in the legacy view.
+ if (binding) {return <CanonicalGroupWorkspace binding={binding} onBack={props.onBack ?? (() => $groupChatWorkspace.set(null))} visible={props.visible} />}
return <GroupExecutionGate {...props} />
}