Skip to content

armgit / macro

Public Imported from GitHub
0

Macro is a unified workspace for teams: email, chat, docs, tasks, agents, calls, and CRM — @-linked together with shared AI memory.

Fix: Channel and email scroll jumping (#533)

dev-rb9d0a70076946
diff --git a/js/app/packages/block-channel/component/Channel.tsx b/js/app/packages/block-channel/component/Channel.tsx
index 75b03a0e8e..efa59a1fc8 100644
--- a/js/app/packages/block-channel/component/Channel.tsx
+++ b/js/app/packages/block-channel/component/Channel.tsx
@@ -1,5 +1,6 @@
import { useGlobalNotificationSource } from '@app/component/GlobalAppState';
import { useNavigatedFromJK } from '@app/component/useNavigatedFromJK';
+import { URL_PARAMS } from '@block-channel/constants';
import type { ChannelData } from '@block-channel/definition';
import {
latestActivitySignal,
@@ -88,7 +89,7 @@ export function Channel(props: { data: Required<ChannelData> }) {
const channelId = useBlockId();
const { track } = withAnalytics();
let containerRef!: HTMLDivElement;
- const [_searchParams] = useSearchParams();
+ const [searchParams] = useSearchParams();
const [channelInputAttachmentsStore, setChannelInputAttachmentsStore] =
createStore<Record<string, InputAttachment[]>>({});
// All messages, including threads, in order of how they should be displayed, i.e. thread children are placed after their parent message
@@ -100,10 +101,26 @@ export function Channel(props: { data: Required<ChannelData> }) {
const notificationSource = useGlobalNotificationSource();
const blockHandle = blockHandleSignal.get;
- const [targetMessage, setTargetMessage] = createSignal<{
- messageId: string;
- threadId?: string;
- }>();
+
+ const initialTargetMessage = () => {
+ const messageID = searchParams[URL_PARAMS.message];
+ const threadID = searchParams[URL_PARAMS.thread];
+
+ if (!messageID) return;
+
+ return {
+ messageId: Array.isArray(messageID) ? messageID[0] : messageID,
+ threadId: Array.isArray(threadID) ? threadID[0] : threadID,
+ };
+ };
+
+ const [targetMessage, setTargetMessage] = createSignal<
+ | {
+ messageId: string;
+ threadId?: string;
+ }
+ | undefined
+ >(initialTargetMessage());
createMethodRegistration(blockHandle, {
goToLocationFromParams: async (params: Record<string, any>) => {
diff --git a/js/app/packages/block-channel/component/MessageList/MessageList.tsx b/js/app/packages/block-channel/component/MessageList/MessageList.tsx
index c52b984d09..c03c2aaebc 100644
--- a/js/app/packages/block-channel/component/MessageList/MessageList.tsx
+++ b/js/app/packages/block-channel/component/MessageList/MessageList.tsx
@@ -59,6 +59,9 @@ const LONG_DATE_FORMATTER = new Intl.DateTimeFormat(undefined, {
year: 'numeric',
});
+// The size of a message with a profile picture and a one line message
+const BASE_ITEM_SIZE = 50;
+
const clampIndex = (value: number, minValue: number, maxValue: number) =>
Math.min(Math.max(value, minValue), maxValue);
@@ -218,27 +221,28 @@ export function MessageList(props: MessageListProps) {
const { messageId: targetMessageId, threadId } = target || {};
+ if (!targetMessageId) return;
+
// If we have a target message, scroll to it and focus it
- if (targetMessageId) {
- const index = props
- .orderedMessages()
- ?.findIndex((m) => m.id === targetMessageId);
-
- if (index >= 0) {
- if (threadId) {
- setThreadViewStore(threadId, (prev) => ({
- ...prev,
- threadExpanded: true,
- }));
- }
- if (scrollTimeoutId) clearTimeout(scrollTimeoutId);
- virtualHandle()?.scrollToIndex(index, {
- align: 'center',
- });
- setTargetIndex(index);
- return;
- }
+ const index = props
+ .orderedMessages()
+ ?.findIndex((m) => m.id === targetMessageId);
+
+ if (index === -1) return;
+
+ if (threadId) {
+ setThreadViewStore(threadId, (prev) => ({
+ ...prev,
+ threadExpanded: true,
+ }));
}
+
+ if (scrollTimeoutId) clearTimeout(scrollTimeoutId);
+
+ virtualHandle()?.scrollToIndex(index, {
+ align: 'center',
+ });
+ setTargetIndex(index);
},
5
);
@@ -526,7 +530,6 @@ export function MessageList(props: MessageListProps) {
// );
const [size, setSize] = createSignal<DOMRect>();
- const [initialized, setInitialized] = createSignal(false);
// scroll to bottom on size change, if the user is near the bottom
createEffect(
@@ -624,11 +627,10 @@ export function MessageList(props: MessageListProps) {
onPointerDown={markUserScrolled}
use:observedSize={{
setSize: setSize,
- setInitialized: setInitialized,
}}
>
<Switch fallback={<EmptyMessageList />}>
- <Match when={initialized() && props.messages.length > 0 && size()}>
+ <Match when={props.messages.length > 0}>
<VList
ref={setVirtualHandle}
style={{
@@ -639,6 +641,7 @@ export function MessageList(props: MessageListProps) {
'overflow-y': 'scroll',
}}
class="scrollbar-hidden"
+ itemSize={BASE_ITEM_SIZE}
data-channel-message-list
data={rows() ?? []}
overscan={10}
diff --git a/js/app/packages/block-channel/constants.ts b/js/app/packages/block-channel/constants.ts
index ec3215161a..9184611033 100644
--- a/js/app/packages/block-channel/constants.ts
+++ b/js/app/packages/block-channel/constants.ts
@@ -1,8 +1,8 @@
import { DEFAULT_ACTIVE_TARGET_TIME } from '@core/signal/activeTarget';
export const URL_PARAMS = {
- thread: 'thread_id',
- message: 'message_id',
+ thread: 'channel_thread_id',
+ message: 'channel_message_id',
};
// The index of the last message in a collapsed thread that will be shown
diff --git a/js/app/packages/block-channel/state/link.ts b/js/app/packages/block-channel/state/link.ts
index e80566ed56..c761a6ef7a 100644
--- a/js/app/packages/block-channel/state/link.ts
+++ b/js/app/packages/block-channel/state/link.ts
@@ -1,12 +1,14 @@
+import { URL_PARAMS } from '@block-channel/constants';
+
export function getUrlToMessage(
channelId: string,
messageId: string,
threadId?: string
) {
const origin = window.location.origin;
- let url = `${origin}/app/channel/${channelId}?message_id=${messageId}`;
+ let url = `${origin}/app/channel/${channelId}?${URL_PARAMS.message}=${messageId}`;
if (threadId) {
- url += `&thread_id=${threadId}`;
+ url += `&${URL_PARAMS.thread}=${threadId}`;
}
return url;
}
diff --git a/js/app/packages/block-email/component/Email.tsx b/js/app/packages/block-email/component/Email.tsx
index a1b2124e4a..9bb39d03d1 100644
--- a/js/app/packages/block-email/component/Email.tsx
+++ b/js/app/packages/block-email/component/Email.tsx
@@ -82,10 +82,11 @@ export function Email(props: EmailProps) {
const [searchParams] = useSearchParams();
const searchParamsMessageId = () => {
- if (typeof searchParams.message_id === 'string') {
- return searchParams.message_id;
- } else if (Array.isArray(searchParams.message_id)) {
- return searchParams.message_id[0];
+ const messageID = searchParams[URL_PARAMS.messageId];
+ if (typeof messageID === 'string') {
+ return messageID;
+ } else if (Array.isArray(messageID)) {
+ return messageID[0];
}
return undefined;
};
@@ -322,11 +323,15 @@ export function Email(props: EmailProps) {
const messages = untrack(() => filteredMessages());
if (!messages) return;
if (container && messages.length > 0) {
- scrollToLastMessage(container, behavior);
+ // We need to scroll after focus because the scroll needs to account
+ // for the size of the message with the focused styling applied
const lastMessageId = getLastMessageId(messages);
if (lastMessageId) {
setFocusedMessageId(lastMessageId);
}
+ queueMicrotask(() => {
+ scrollToLastMessage(container, behavior);
+ });
}
};
diff --git a/js/app/packages/block-email/constants.ts b/js/app/packages/block-email/constants.ts
index ccbb4be222..aaf168f1c3 100644
--- a/js/app/packages/block-email/constants.ts
+++ b/js/app/packages/block-email/constants.ts
@@ -1,3 +1,3 @@
export const URL_PARAMS = {
- messageId: 'message_id',
+ messageId: 'email_message_id',
};