Macro is a unified workspace for teams: email, chat, docs, tasks, agents, calls, and CRM — @-linked together with shared AI memory.
TypeScript agentaiai-agentsall-in-onecrmcrm-systememaillinearmcpmessagingnotesnotionofficerustslackslack-alternativestartupstartup-toolstypescriptworkspace
fix(channel): task mode switch morph broken (#5442)
dev-rb87838cfa3153
diff --git a/apps/web/src/features/channel/Channel/Channel.tsx b/apps/web/src/features/channel/Channel/Channel.tsxindex 32b4d326f7..fc8cd20b15 100644--- a/apps/web/src/features/channel/Channel/Channel.tsx+++ b/apps/web/src/features/channel/Channel/Channel.tsx@@ -3,6 +3,10 @@ import { createActivityTracker } from '@channel/activity-tracker';import { DebugSuspense } from '@channel/DebugSuspense';import type { ChannelInputProps } from '@channel/Input/ChannelInput';import { buildPostMessageSendPayload } from '@channel/Input/message-payload';+import {+ TaskModeChannelInput,+ type TaskModeChannelInputProps,+} from '@channel/Input/TaskModeChannelInput';import {makeAttachmentTrackerPersistenceKey,makeInputValuePersistenceKey,@@ -77,7 +81,6 @@ import {Switch,} from 'solid-js';import {- ChannelInput,createInputAttachmentTracker,type InputHandle,type InputSnapshot,@@ -618,7 +621,7 @@ export function Channel(props: ChannelProps) {// Task mode: post the freshly created task into the channel as a message// carrying a task mention.- const onSendTask: ChannelInputProps['onSendTask'] = (task) => {+ const onSendTask: TaskModeChannelInputProps['onSendTask'] = (task) => {const senderId = userId();if (!senderId) return;sendMessageMutation.mutate(@@ -895,7 +898,7 @@ export function Channel(props: ChannelProps) {)}</Match><Match when={true}>- <ChannelInput+ <TaskModeChannelInputautofocus={props.autofocus}collapsibleinput={{diff --git a/apps/web/src/features/channel/Input/ChannelInput.tsx b/apps/web/src/features/channel/Input/ChannelInput.tsxindex e0623b3ba9..1bfeab66bc 100644--- a/apps/web/src/features/channel/Input/ChannelInput.tsx+++ b/apps/web/src/features/channel/Input/ChannelInput.tsx@@ -23,18 +23,14 @@ import {} from '@core/util/upload';import type { EntityData } from '@entity';import { isIOS } from '@solid-primitives/platform';-import { makePersisted } from '@solid-primitives/storage';import { CollapsedInput, cn, Surface } from '@ui';import { $getRoot } from 'lexical';import {type Accessor,createSignal,type JSX,- lazy,Match,- onCleanup,Show,- Suspense,Switch,} from 'solid-js';import { isMacroAiId, macroAiMentionUser } from '../macroAi';@@ -47,8 +43,6 @@ import { createTypingTracker } from './create-typing-tracker';import { FormatButtons } from './FormatButtons';import { Input } from './Input';import { createMentionsTracker } from './mentions-tracker';-import type { TaskComposerSendPayload } from './TaskComposer';-import { TaskModeSwitch } from './TaskModeSwitch';import type {EntityMentionInsertCoordinates,InputAttachmentTracker,@@ -63,19 +57,9 @@ import { isReplyInput } from './types';import { uploadInputAttachments } from './upload-attachments';import { entityToDocumentMentionInfo } from './utils/entity-mention';import { applyInlineFormat, applyNodeFormat } from './utils/formatting';-import type { InputTaskPersistence } from './utils/persistence';import { $selectTrailingParagraph } from './utils/select-trailing-paragraph';import { hasSendableInputContent } from './utils/sendable-content';-// Keep the task/property/entity-heavy composer out of ChannelInput's eager-// module graph. ChannelInput is also pulled into StaticMarkdown through thread-// rendering, so importing TaskComposer eagerly creates an @entity cycle.-const TaskComposer = lazy(() =>- import('./TaskComposer').then((module) => ({- default: module.TaskComposer,- }))-);-export type ChannelInputProps = InputCallbacks & {input: InputData;markdownNamespace?: string;@@ -94,33 +78,25 @@ export type ChannelInputProps = InputCallbacks & {*/collapsible?: boolean;/**- * Fires when a task composed in the input's task mode has been created,- * so the host can post it into the channel. Providing this enables the- * message/task mode switch (desktop only).+ * Whether focus leaving the input may collapse it. Defaults to `true`.+ * Composed alternate input faces can disable this while the message face is+ * hidden so it remains expanded for the return transition.*/- onSendTask?: (task: TaskComposerSendPayload) => void;+ collapseOnFocusOut?: boolean;/**- * Persists the task draft and the message/task mode flag across visits- * (e.g. per channel), the way `persistenceKey` persists the message draft.+ * Optional composition slot around the message face inside the shared input+ * surface. Used by alternate input modes that need to preserve the surface+ * while switching content.*/- taskPersistence?: InputTaskPersistence;+ renderContent?: (messageFace: JSX.Element) => JSX.Element;};-function WebDefaultActions(props: {- input: InputData;- onEnterTaskMode?: () => void;-}) {+function WebDefaultActions(props: { input: InputData }) {return (<Input.Actions><Input.Actions.Left><Input.AttachFilesAction /><Input.ToggleFormatAction />- <Show when={props.onEnterTaskMode}>- <TaskModeSwitch- checked={false}- onChange={() => props.onEnterTaskMode?.()}- />- </Show><Show when={isReplyInput(props.input)}><Input.CloseReplyAction /></Show>@@ -149,19 +125,11 @@ function IosDefaultActions(props: { input: InputData }) {);}-function DefaultActions(props: {- input: InputData;- onEnterTaskMode?: () => void;-}) {+function DefaultActions(props: { input: InputData }) {return (<Showwhen={isPlatform('ios')}- fallback={- <WebDefaultActions- input={props.input}- onEnterTaskMode={props.onEnterTaskMode}- />- }+ fallback={<WebDefaultActions input={props.input} />}><IosDefaultActions input={props.input} /></Show>@@ -224,59 +192,7 @@ export function ChannelInput(props: ChannelInputProps) {attachFiles: (files) => inputState.commands.attachFiles(files),});- // Message/task mode. Task mode swaps the message editor for an embedded- // task composer. Desktop only — mobile keeps the plain message input.- const canUseTaskMode = () =>- !!props.onSendTask && !isPlatform('ios') && !isMobile();- const taskModeSignal = createSignal(false);- const [taskModeRequested, setTaskModeRequested] = props.taskPersistence- ? makePersisted(taskModeSignal, { name: props.taskPersistence.modeKey })- : taskModeSignal;- // True when the input opens directly in task mode (persisted from a prior- // visit); it decides who receives the mount-time autofocus.- const taskModeRestored = taskModeRequested() === true;- // Mount the composer on first use only, then keep it alive so a draft- // survives toggling back and forth.- const [taskComposerMounted, setTaskComposerMounted] =- createSignal(taskModeRestored);- const isTaskMode = () => canUseTaskMode() && taskModeRequested();-- const isCollapsed = () =>- !!props.collapsible && collapsedInput.isCollapsed() && !isTaskMode();-- // Height morph between the two input faces: pin the wrapper at its current- // height, swap faces, then transition to the new content height. The- // wrapper is measured for the start (mid-transition it reflects the- // animated height); the inner content for the target.- let morphWrapperEl: HTMLDivElement | undefined;- let morphContentEl: HTMLDivElement | undefined;- const [morphHeight, setMorphHeight] = createSignal<number>();- let morphTimer: ReturnType<typeof setTimeout> | undefined;- onCleanup(() => clearTimeout(morphTimer));-- const setTaskMode = (task: boolean) => {- if (task === taskModeRequested()) return;- if (task) setTaskComposerMounted(true);- const from = morphWrapperEl?.offsetHeight;- setTaskModeRequested(task);- if (!task) focusEditor();- if (from === undefined) return;- setMorphHeight(from);- requestAnimationFrame(() => {- // Reading offsetHeight forces a layout with the start height committed,- // so the height change below actually transitions.- const to = morphContentEl?.offsetHeight;- if (to === undefined) return;- setMorphHeight(to);- clearTimeout(morphTimer);- morphTimer = setTimeout(() => setMorphHeight(undefined), 350);- });- };-- const onTaskComposerSend = (task: TaskComposerSendPayload) => {- props.onSendTask?.(task);- setTaskMode(false);- };+ const isCollapsed = () => !!props.collapsible && collapsedInput.isCollapsed();let isEditorConnected = false;let pendingRestore:@@ -485,6 +401,72 @@ export function ChannelInput(props: ChannelInputProps) {},});+ const renderSurfaceContent = () => {+ const messageFace = (+ <Input.DropZone+ onDragStart={(valid) => inputState.setIsDraggedOver(valid)}+ onDragEnd={() => inputState.setIsDraggedOver(false)}+ >+ <Input.Layout>+ <Input.DropOverlay />+ <Input.FormatRibbon>+ <FormatButtons+ selectionState={() => markdownEditor.selection}+ onInlineFormat={(format) =>+ applyInlineFormat(markdownEditor.lexical, format)+ }+ onNodeFormat={(format) =>+ applyNodeFormat(markdownEditor.lexical, format)+ }+ />+ </Input.FormatRibbon>+ <Input.EditorShell+ ref={setScrollContainer}+ onClick={(event) => {+ if (!isMobile()) {+ event.stopPropagation();+ markdownEditor.controls.focus();+ }+ }}+ >+ <Input.Editor>+ <MarkdownShell+ config={markdownEditor}+ placeholder={props.input.placeholder}+ initialValue={inputState.view().value}+ autofocus={!isMobile() && (props.autofocus ?? true)}+ class="text-sm"+ refFn={attach}+ onConnect={() => {+ isEditorConnected = true;+ flushPendingRestore();+ flushPendingFocus();+ }}+ />+ <DragInsertIndicator+ editor={lexicalEditor()}+ state={entityDragInsertStore}+ active+ />+ </Input.Editor>+ </Input.EditorShell>+ <Input.Attachments kind="media" />+ <Input.Attachments kind="document" />+ <Input.Footer>+ <Switch>+ <Match when={props.children}>{props.children}</Match>+ <Match when>+ <DefaultActions input={inputState.view()} />+ </Match>+ </Switch>+ </Input.Footer>+ </Input.Layout>+ </Input.DropZone>+ );++ return props.renderContent?.(messageFace) ?? messageFace;+ };+return (<Input.Root input={inputState.view()} commands={inputState.commands}><Show when={isCollapsed()}>@@ -525,7 +507,7 @@ export function ChannelInput(props: ChannelInputProps) {const next = e.relatedTarget as Node | null;if (next && e.currentTarget.contains(next)) return;if (isInternalRefocus) return;- if (isTaskMode()) return;+ if (props.collapseOnFocusOut === false) return;collapsedInput.collapse();}}class={cn(@@ -537,133 +519,7 @@ export function ChannelInput(props: ChannelInputProps) {depth={isMobile() ? 3 : 2}solid>- <div- ref={(el) => {- morphWrapperEl = el;- }}- class={cn(- morphHeight() !== undefined &&- 'overflow-hidden transition-[height] duration-300 ease-in-out'- )}- style={{- height:- morphHeight() !== undefined ? `${morphHeight()}px` : undefined,- }}- >- <div- ref={(el) => {- morphContentEl = el;- }}- >- <div- class={cn(- isTaskMode() && 'hidden',- taskComposerMounted() &&- 'animate-[dialog-fullscreen-open_200ms_ease-out]'- )}- data-input-face="message"- >- <Input.DropZone- onDragStart={(valid) => inputState.setIsDraggedOver(valid)}- onDragEnd={() => inputState.setIsDraggedOver(false)}- >- <Input.Layout>- <Input.DropOverlay />- <Input.FormatRibbon>- <FormatButtons- selectionState={() => markdownEditor.selection}- onInlineFormat={(format) =>- applyInlineFormat(markdownEditor.lexical, format)- }- onNodeFormat={(format) =>- applyNodeFormat(markdownEditor.lexical, format)- }- />- </Input.FormatRibbon>- <Input.EditorShell- ref={setScrollContainer}- onClick={(event) => {- if (!isMobile()) {- event.stopPropagation();- markdownEditor.controls.focus();- }- }}- >- <Input.Editor>- <MarkdownShell- config={markdownEditor}- placeholder={props.input.placeholder}- initialValue={inputState.view().value}- autofocus={- !isMobile() &&- (props.autofocus ?? true) &&- !isTaskMode()- }- class="text-sm"- refFn={attach}- onConnect={() => {- isEditorConnected = true;- flushPendingRestore();- flushPendingFocus();- }}- />- <DragInsertIndicator- editor={lexicalEditor()}- state={entityDragInsertStore}- active- />- </Input.Editor>- </Input.EditorShell>- <Input.Attachments kind="media" />- <Input.Attachments kind="document" />- <Input.Footer>- <Switch>- <Match when={props.children}>{props.children}</Match>- <Match when>- <DefaultActions- input={inputState.view()}- onEnterTaskMode={- canUseTaskMode()- ? () => setTaskMode(true)- : undefined- }- />- </Match>- </Switch>- </Input.Footer>- </Input.Layout>- </Input.DropZone>- </div>- <Show when={taskComposerMounted()}>- <div- class={cn(- !isTaskMode() && 'hidden',- 'animate-[dialog-fullscreen-open_200ms_ease-out]'- )}- data-input-face="task"- >- <Suspense>- <TaskComposer- active={isTaskMode()}- autofocus={- taskModeRestored- ? !isMobile() && (props.autofocus ?? true)- : true- }- draftPersistenceKey={props.taskPersistence?.draftKey}- modeSwitch={- <TaskModeSwitch- checked={true}- onChange={() => setTaskMode(false)}- />- }- onSend={onTaskComposerSend}- />- </Suspense>- </div>- </Show>- </div>- </div>+ {renderSurfaceContent()}</Surface></Input.Root>);diff --git a/apps/web/src/features/channel/Input/TaskModeChannelInput.tsx b/apps/web/src/features/channel/Input/TaskModeChannelInput.tsxnew file mode 100644index 0000000000..28f883bcce--- /dev/null+++ b/apps/web/src/features/channel/Input/TaskModeChannelInput.tsx@@ -0,0 +1,190 @@+import { isMobile } from '@core/mobile/isMobile';+import { isPlatform } from '@core/util/platform';+import { makePersisted } from '@solid-primitives/storage';+import { cn } from '@ui';+import { createSignal, onCleanup, Show, splitProps } from 'solid-js';+import { ChannelInput, type ChannelInputProps } from './ChannelInput';+import { Input } from './Input';+import { TaskComposer, type TaskComposerSendPayload } from './TaskComposer';+import { TaskModeSwitch } from './TaskModeSwitch';+import type { InputHandle } from './types';+import type { InputTaskPersistence } from './utils/persistence';++/** Props for a full channel input with message and task composition modes. */+export type TaskModeChannelInputProps = Omit<+ ChannelInputProps,+ 'children' | 'collapseOnFocusOut' | 'renderContent'+> & {+ /** Called after the task composer creates a task. */+ onSendTask: (task: TaskComposerSendPayload) => void;+ /** Persistence keys for the task draft and selected input mode. */+ taskPersistence?: InputTaskPersistence;+};++function MessageModeActions(props: {+ canUseTaskMode: boolean;+ onEnterTaskMode: () => void;+}) {+ return (+ <Show+ when={isPlatform('ios')}+ fallback={+ <Input.Actions>+ <Input.Actions.Left>+ <Input.AttachFilesAction />+ <Input.ToggleFormatAction />+ <Show when={props.canUseTaskMode}>+ <TaskModeSwitch+ checked={false}+ onChange={props.onEnterTaskMode}+ />+ </Show>+ </Input.Actions.Left>+ <Input.Actions.Right>+ <Input.SendAction />+ </Input.Actions.Right>+ </Input.Actions>+ }+ >+ <Input.Actions>+ <Input.Actions.Left>+ <Input.AttachNativeMediaAction />+ <Input.ToggleFormatAction />+ </Input.Actions.Left>+ <Input.Actions.Right>+ <Input.SendAction />+ </Input.Actions.Right>+ </Input.Actions>+ </Show>+ );+}++/**+ * Composes the message-only ChannelInput with the task composer for full+ * channel and DM views. Import this module directly; exporting it from the+ * general Input barrel would pull the task/entity graph into thread inputs.+ */+export function TaskModeChannelInput(props: TaskModeChannelInputProps) {+ const [local, inputProps] = splitProps(props, [+ 'autofocus',+ 'onReady',+ 'onSendTask',+ 'taskPersistence',+ ]);++ const canUseTaskMode = () => !isPlatform('ios') && !isMobile();+ const taskModeSignal = createSignal(false);+ const [taskModeRequested, setTaskModeRequested] = local.taskPersistence+ ? makePersisted(taskModeSignal, { name: local.taskPersistence.modeKey })+ : taskModeSignal;+ const taskModeRestored = taskModeRequested() === true;+ const [taskComposerMounted, setTaskComposerMounted] =+ createSignal(taskModeRestored);+ const isTaskMode = () => canUseTaskMode() && taskModeRequested();++ let messageInputHandle: InputHandle | undefined;+ let morphWrapperEl: HTMLDivElement | undefined;+ let morphContentEl: HTMLDivElement | undefined;+ const [morphHeight, setMorphHeight] = createSignal<number>();+ let morphTimer: ReturnType<typeof setTimeout> | undefined;+ onCleanup(() => clearTimeout(morphTimer));++ const setTaskMode = (task: boolean) => {+ if (task === taskModeRequested()) return;+ if (task) setTaskComposerMounted(true);++ const from = morphWrapperEl?.offsetHeight;+ setTaskModeRequested(task);+ if (!task) messageInputHandle?.focus();+ if (from === undefined) return;++ setMorphHeight(from);+ requestAnimationFrame(() => {+ const to = morphContentEl?.offsetHeight;+ if (to === undefined) return;+ setMorphHeight(to);+ clearTimeout(morphTimer);+ morphTimer = setTimeout(() => setMorphHeight(undefined), 350);+ });+ };++ const handleTaskSend = (task: TaskComposerSendPayload) => {+ local.onSendTask(task);+ setTaskMode(false);+ };++ const setMessageInputHandle = (handle: InputHandle) => {+ messageInputHandle = handle;+ local.onReady?.(handle);+ };++ return (+ <ChannelInput+ {...inputProps}+ autofocus={taskModeRestored ? false : local.autofocus}+ collapseOnFocusOut={!isTaskMode()}+ onReady={setMessageInputHandle}+ renderContent={(messageFace) => (+ <div+ ref={(el) => {+ morphWrapperEl = el;+ }}+ class={cn(+ morphHeight() !== undefined &&+ 'overflow-hidden transition-[height] duration-300 ease-in-out'+ )}+ style={{+ height:+ morphHeight() !== undefined ? `${morphHeight()}px` : undefined,+ }}+ >+ <div+ ref={(el) => {+ morphContentEl = el;+ }}+ >+ <div+ class={cn(+ isTaskMode() && 'hidden',+ taskComposerMounted() &&+ 'animate-[dialog-fullscreen-open_200ms_ease-out]'+ )}+ data-input-face="message"+ >+ {messageFace}+ </div>+ <Show when={taskComposerMounted()}>+ <div+ class={cn(+ !isTaskMode() && 'hidden',+ 'animate-[dialog-fullscreen-open_200ms_ease-out]'+ )}+ data-input-face="task"+ >+ <TaskComposer+ active={isTaskMode()}+ autofocus={+ taskModeRestored ? (local.autofocus ?? true) : true+ }+ draftPersistenceKey={local.taskPersistence?.draftKey}+ modeSwitch={+ <TaskModeSwitch+ checked={true}+ onChange={() => setTaskMode(false)}+ />+ }+ onSend={handleTaskSend}+ />+ </div>+ </Show>+ </div>+ </div>+ )}+ >+ <MessageModeActions+ canUseTaskMode={canUseTaskMode()}+ onEnterTaskMode={() => setTaskMode(true)}+ />+ </ChannelInput>+ );+}diff --git a/apps/web/src/features/channel/Input/tests/task-mode.test.tsx b/apps/web/src/features/channel/Input/tests/task-mode.test.tsxindex 2421cd7add..34d050ecb3 100644--- a/apps/web/src/features/channel/Input/tests/task-mode.test.tsx+++ b/apps/web/src/features/channel/Input/tests/task-mode.test.tsx@@ -229,6 +229,7 @@ vi.mock('../TaskComposer', () => ({}));import { ChannelInput } from '../ChannelInput';+import { TaskModeChannelInput } from '../TaskModeChannelInput';import type { InputData } from '../types';const baseInput: InputData = {@@ -242,16 +243,21 @@ const baseInput: InputData = {};describe('Channel input task mode', () => {- it('omits the task mode switch when onSendTask is not provided', () => {+ it('keeps the base channel input message-only', () => {render(() => <ChannelInput input={baseInput} />);expect(screen.queryByRole('switch', { name: 'Task' })).toBeNull();expect(screen.queryByTestId('task-composer')).toBeNull();});- it('shows an unchecked task mode switch when onSendTask is provided', () => {- render(() => <ChannelInput input={baseInput} onSendTask={() => {}} />);+ it('shows an unchecked task mode switch at the normal input width', () => {+ const { container } = render(() => (+ <TaskModeChannelInput input={baseInput} onSendTask={() => {}} />+ ));+ expect(container.firstElementChild?.classList).toContain(+ 'macro-message-width'+ );const modeSwitch = screen.getByRole('switch', { name: 'Task' });expect(modeSwitch).toHaveProperty('checked', false);expect(screen.queryByTestId('task-composer')).toBeNull();@@ -260,7 +266,7 @@ describe('Channel input task mode', () => {it('swaps the input faces when toggling task mode on and off', async () => {const user = userEvent.setup();const { container } = render(() => (- <ChannelInput input={baseInput} onSendTask={() => {}} />+ <TaskModeChannelInput input={baseInput} onSendTask={() => {}} />));await user.click(screen.getByRole('switch', { name: 'Task' }));@@ -286,7 +292,9 @@ describe('Channel input task mode', () => {it('enters task mode from clicks on the switch pill itself, not just the control', async () => {const user = userEvent.setup();- render(() => <ChannelInput input={baseInput} onSendTask={() => {}} />);+ render(() => (+ <TaskModeChannelInput input={baseInput} onSendTask={() => {}} />+ ));// The pill (Kobalte switch root) is the label's parent; clicking its// padding must toggle just like clicking the control or label.@@ -305,7 +313,7 @@ describe('Channel input task mode', () => {localStorage.removeItem(taskPersistence.modeKey);const first = render(() => (- <ChannelInput+ <TaskModeChannelInputinput={baseInput}onSendTask={() => {}}taskPersistence={taskPersistence}@@ -320,7 +328,7 @@ describe('Channel input task mode', () => {first.unmount();const second = render(() => (- <ChannelInput+ <TaskModeChannelInputinput={baseInput}onSendTask={() => {}}taskPersistence={taskPersistence}@@ -341,7 +349,7 @@ describe('Channel input task mode', () => {const user = userEvent.setup();const onSendTask = vi.fn();const { container } = render(() => (- <ChannelInput input={baseInput} onSendTask={onSendTask} />+ <TaskModeChannelInput input={baseInput} onSendTask={onSendTask} />));await user.click(screen.getByRole('switch', { name: 'Task' }));