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(email): thread scroll jumping and loading indicator (#1014)

dev-rbe893fb3a196a
diff --git a/js/app/packages/block-email/component/Email.tsx b/js/app/packages/block-email/component/Email.tsx
index 3a2ba5f84d..4a93343588 100644
--- a/js/app/packages/block-email/component/Email.tsx
+++ b/js/app/packages/block-email/component/Email.tsx
@@ -415,6 +415,11 @@ function EmailContent(props: EmailViewProps) {
/>
<CustomScrollbar reverse scrollContainer={context.messagesListRef} />
</div>
+ <FloatingInputLoader
+ isLoading={context.query.isFetching}
+ loadingText="Loading messages"
+ class="top-2"
+ />
<Show
when={
context.permissions().isOwner &&
@@ -426,10 +431,6 @@ function EmailContent(props: EmailViewProps) {
return (
<div class="shrink-0 w-full px-4 pb-2">
<div class="relative w-full flex flex-row justify-center bg-panel macro-message-width mx-auto">
- <FloatingInputLoader
- isLoading={context.query.isFetching}
- loadingText="Loading messages"
- />
<EmailInput
replyingTo={lastMessage}
draft={
diff --git a/js/app/packages/block-email/component/EmailContext.tsx b/js/app/packages/block-email/component/EmailContext.tsx
index 893ac7a1e1..148135c507 100644
--- a/js/app/packages/block-email/component/EmailContext.tsx
+++ b/js/app/packages/block-email/component/EmailContext.tsx
@@ -413,7 +413,8 @@ export function EmailProvider(props: FlowProps<{ threadID: string }>) {
query: {
hasMore: () => threadQuery.hasNextPage ?? false,
fetchNextPage: threadQuery.fetchNextPage,
- isFetching: () => threadQuery.isFetching,
+ isFetching: () =>
+ threadQuery.isLoading || threadQuery.isFetchingNextPage,
refetch: threadQuery.refetch,
},
drafts: {
diff --git a/js/app/packages/block-email/component/MessageList.tsx b/js/app/packages/block-email/component/MessageList.tsx
index 4dea2073ad..892577ce44 100644
--- a/js/app/packages/block-email/component/MessageList.tsx
+++ b/js/app/packages/block-email/component/MessageList.tsx
@@ -1,7 +1,7 @@
import { useEmailContext } from '@block-email/component/EmailContext';
import { isScrollingToMessage } from '@block-email/signal/scrollState';
import { StaticMarkdownContext } from '@core/component/LexicalMarkdown/component/core/StaticMarkdown';
-import { createMemo, createSelector, For, Show } from 'solid-js';
+import { createMemo, createSelector, Index, Show } from 'solid-js';
import { MessageContainer } from './MessageContainer';
interface MessageListProps {
@@ -50,13 +50,16 @@ export function MessageList(props: MessageListProps) {
}}
>
<StaticMarkdownContext>
- <For each={context.messages.list().toReversed()}>
+ {/* We use Index because the index of the messages should always be stable and
+ only the value changes. This also helps prevent nested inputs from rerendering
+ */}
+ <Index each={context.messages.list().toReversed()}>
{(message, index) => {
// We need the index as if the list was not reversed
const normalizedIndex = createMemo(() => {
const listLength = context.messages.list().length;
- const normalized = listLength - 1 - index();
+ const normalized = listLength - 1 - index;
// The element at the 0th index isn't actually the first message
// if there is more data to load so we return -1 so that `isFirstMessage`
@@ -76,13 +79,13 @@ export function MessageList(props: MessageListProps) {
normalizedIndex() ===
(context.messages.list().length ?? 0) - 1
}
- isFocused={isFocusedSelector(message.db_id ?? undefined)}
- isTarget={isTargetSelector(message.db_id ?? undefined)}
- message={message}
+ isFocused={isFocusedSelector(message().db_id ?? undefined)}
+ isTarget={isTargetSelector(message().db_id ?? undefined)}
+ message={message()}
/>
);
}}
- </For>
+ </Index>
</StaticMarkdownContext>
<Show when={props.title}>
<div class="shrink-0 w-full flex justify-center pb-4">
diff --git a/js/app/packages/core/component/FloatingInputLoader.tsx b/js/app/packages/core/component/FloatingInputLoader.tsx
index 68f718c1e6..11c1a9e0e1 100644
--- a/js/app/packages/core/component/FloatingInputLoader.tsx
+++ b/js/app/packages/core/component/FloatingInputLoader.tsx
@@ -1,5 +1,6 @@
import CheckCircle from '@icon/regular/check-circle.svg';
import Spinner from '@icon/regular/spinner.svg';
+import { cn } from '@ui/utils/classname';
import {
type Accessor,
createEffect,
@@ -17,6 +18,7 @@ interface FloatingInputLoaderProps {
successDuration?: number;
loadingText?: string;
successText?: string;
+ class?: string;
}
export function FloatingInputLoader(props: FloatingInputLoaderProps) {
@@ -82,11 +84,13 @@ export function FloatingInputLoader(props: FloatingInputLoaderProps) {
return (
<div
- class={`absolute bottom-full left-1/2 -translate-x-1/2 mb-2 transition-all duration-200 ease-out ${
+ class={cn(
+ 'absolute bottom-full left-1/2 -translate-x-1/2 mb-2 transition-all duration-200 ease-out',
isVisible()
? 'opacity-100 translate-y-0'
- : 'opacity-0 translate-y-1 pointer-events-none'
- }`}
+ : 'opacity-0 translate-y-1 pointer-events-none',
+ props.class
+ )}
>
<div class="flex items-center gap-2 px-3 py-1.5 rounded-md bg-panel border border-edge-muted shadow-sm">
<Show