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
feat(new-channels): scroll thread reply into view (#2331)
teo39c0c28c2976
diff --git a/js/app/packages/channel/Channel/Channel.tsx b/js/app/packages/channel/Channel/Channel.tsxindex 12eaaca10c..3aa75f2d51 100644--- a/js/app/packages/channel/Channel/Channel.tsx+++ b/js/app/packages/channel/Channel/Channel.tsx@@ -69,6 +69,7 @@ import { resetKeyboardModality } from './util';import { DebugSuspense } from '@channel/DebugSuspense';import { useChannelParticipants } from '@channel/use-channel-participants';import { usePostTypingUpdateMutation } from '@queries/channel/typing';+import { scrollReplyInputIntoView } from '../scroll-utils';type ChannelProps = {channelId: string;@@ -184,6 +185,7 @@ export function Channel(props: ChannelProps) {onReply: (ctx) => {const state = threadManager.getOrCreateThreadState(ctx.message.id);state.setIsReplying(true);+ requestAnimationFrame(() => scrollReplyInputIntoView(ctx.message.id));},onEdit: ({ message }) => {messageEditor.start(message);diff --git a/js/app/packages/channel/Channel/create-channel-hotkeys.ts b/js/app/packages/channel/Channel/create-channel-hotkeys.tsindex 73465019d8..1b7b9689da 100644--- a/js/app/packages/channel/Channel/create-channel-hotkeys.ts+++ b/js/app/packages/channel/Channel/create-channel-hotkeys.ts@@ -23,7 +23,6 @@ export function canReplyToSelectedMessageFromHotkey(input: {}) {return input.hasSelection && !input.isEditing;}-export function canEditOrDeleteSelectedMessageFromHotkey(input: {hasSelection: boolean;isEditing: boolean;diff --git a/js/app/packages/channel/Thread/ThreadReplyInput.tsx b/js/app/packages/channel/Thread/ThreadReplyInput.tsxindex f53d2eff56..195ede06ea 100644--- a/js/app/packages/channel/Thread/ThreadReplyInput.tsx+++ b/js/app/packages/channel/Thread/ThreadReplyInput.tsx@@ -43,7 +43,12 @@ export function ThreadReplyInput(props: ThreadReplyInputProps) {});return (- <div class="relative pt-2" style={{ 'margin-left': replyInputOffsetX }}>+ <div+ class="relative pt-2"+ style={{ 'margin-left': replyInputOffsetX }}+ data-reply-input+ data-reply-input-id={props.messageId}+ ><ThreadReplyInputConnector />{(() => {const droppable = entityDropZone.droppable;diff --git a/js/app/packages/channel/Thread/create-thread-hotkeys.ts b/js/app/packages/channel/Thread/create-thread-hotkeys.tsindex 8f81b4d611..52790ce1e7 100644--- a/js/app/packages/channel/Thread/create-thread-hotkeys.ts+++ b/js/app/packages/channel/Thread/create-thread-hotkeys.ts@@ -9,6 +9,7 @@ import { onCleanup, type Accessor } from 'solid-js';import type { MessageSelection } from '../Channel/create-message-selection';import type { ApiChannelMessage, ApiThreadReply } from '@service-comms/client';import type { MessageActions, MessageData } from '../Message';+import { scrollMessageIntoView } from '../scroll-utils';type CreateThreadHotkeysOptions = {messageListScopeId: string;@@ -48,12 +49,6 @@ export function canEditOrDeleteThreadReplyFromHotkey(input: {);}-function scrollReplyIntoView(replyId: string) {- document- .querySelector<HTMLElement>(`[data-message-id="${replyId}"]`)- ?.scrollIntoView({ block: 'nearest' });-}-export function createThreadHotkeys(options: CreateThreadHotkeysOptions) {const scope = options.messageListScopeId;const group = createHotkeyGroup();@@ -76,7 +71,7 @@ export function createThreadHotkeys(options: CreateThreadHotkeysOptions) {options.expandThread();const id = options.replySelection.selectFirst();if (id) {- requestAnimationFrame(() => scrollReplyIntoView(id));+ requestAnimationFrame(() => scrollMessageIntoView(id));}return true;},@@ -94,7 +89,7 @@ export function createThreadHotkeys(options: CreateThreadHotkeysOptions) {const before = options.replySelection.selectedId();const id = options.replySelection.selectPrevious();if (id && id !== before) {- scrollReplyIntoView(id);+ scrollMessageIntoView(id);} else {options.replySelection.clear();}@@ -113,7 +108,7 @@ export function createThreadHotkeys(options: CreateThreadHotkeysOptions) {keyDownHandler: () => {const id = options.replySelection.selectNext();if (id) {- scrollReplyIntoView(id);+ scrollMessageIntoView(id);return true;}options.replySelection.clear();diff --git a/js/app/packages/channel/scroll-utils.ts b/js/app/packages/channel/scroll-utils.tsnew file mode 100644index 0000000000..bcee1fd227--- /dev/null+++ b/js/app/packages/channel/scroll-utils.ts@@ -0,0 +1,44 @@+function getMessageElement(messageId: string) {+ return document.querySelector<HTMLElement>(+ `[data-message-id="${messageId}"]`+ );+}++function getReplyInputElement(messageId: string) {+ return document.querySelector<HTMLElement>(+ `[data-reply-input-id="${messageId}"]`+ );+}++function isElementInView(element: HTMLElement) {+ const rect = element.getBoundingClientRect();+ return rect.top >= 0 && rect.bottom <= window.innerHeight;+}++function scrollIntoViewIfNeeded(element: HTMLElement) {+ if (isElementInView(element)) return false;+ element.scrollIntoView({ block: 'nearest' });+ return true;+}++export function isMessageInView(messageId: string) {+ const element = getMessageElement(messageId);+ return !!element && isElementInView(element);+}++export function scrollMessageIntoView(messageId: string) {+ const element = getMessageElement(messageId);+ if (!element) return false;+ return scrollIntoViewIfNeeded(element);+}++export function isReplyInputInView(messageId: string) {+ const element = getReplyInputElement(messageId);+ return !!element && isElementInView(element);+}++export function scrollReplyInputIntoView(messageId: string) {+ const element = getReplyInputElement(messageId);+ if (!element) return false;+ return scrollIntoViewIfNeeded(element);+}