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): fix scroll to bottom when mid pagination (#2696)

teo46a14450d613
diff --git a/js/app/packages/channel/Channel/Channel.tsx b/js/app/packages/channel/Channel/Channel.tsx
index 45afbea109..51b19347b2 100644
--- a/js/app/packages/channel/Channel/Channel.tsx
+++ b/js/app/packages/channel/Channel/Channel.tsx
@@ -2,7 +2,9 @@ import {
type ChannelMessagesData,
useChannelMessagesQuery,
createMessageIndex,
+ getChannelMessagesQueryKey,
} from '@queries/channel/channel-messages';
+import { queryClient } from '@queries/client';
import {
createEffect,
createMemo,
@@ -275,6 +277,16 @@ export function Channel(props: ChannelProps) {
(channelInputSnapshot()?.value.trim().length ?? 0) === 0,
});
+ const handleScrollToBottom = () => {
+ if (messagesQuery.hasPreviousPage) {
+ targetMessageController.reset();
+ const defaultKey = getChannelMessagesQueryKey(props.channelId, null);
+ queryClient.resetQueries({ queryKey: defaultKey });
+ } else {
+ threadListNavigation()?.scrollToBottom('end');
+ }
+ };
+
createStickyScrollEffect({
isNearBottom: () => threadListScrollState()?.isNearBottom ?? false,
hasMoreBelow: () => threadPaginator.hasMorePrepend(),
@@ -410,8 +422,8 @@ export function Channel(props: ChannelProps) {
}}
</ThreadList>
<ScrollToBottomOverlay
- navigation={threadListNavigation}
scrollState={threadListScrollState}
+ onScrollToBottom={handleScrollToBottom}
/>
</Show>
</div>
diff --git a/js/app/packages/channel/Channel/ScrollToBottomOverlay.tsx b/js/app/packages/channel/Channel/ScrollToBottomOverlay.tsx
index 11081b2990..6aa0514157 100644
--- a/js/app/packages/channel/Channel/ScrollToBottomOverlay.tsx
+++ b/js/app/packages/channel/Channel/ScrollToBottomOverlay.tsx
@@ -1,5 +1,5 @@
import { Show, type Accessor } from 'solid-js';
-import type { ThreadListNavigation, ThreadListScrollState } from './ThreadList';
+import type { ThreadListScrollState } from './ThreadList';
export function shouldShowScrollToBottomButton(
state: ThreadListScrollState | undefined
@@ -14,8 +14,8 @@ export function shouldShowScrollToBottomButton(
}
type ScrollToBottomOverlayProps = {
- navigation: Accessor<ThreadListNavigation | undefined>;
scrollState: Accessor<ThreadListScrollState | undefined>;
+ onScrollToBottom: () => void;
class?: string;
};
@@ -26,7 +26,7 @@ export function ScrollToBottomOverlay(props: ScrollToBottomOverlayProps) {
type="button"
class={`absolute top-4 left-1/2 -translate-x-1/2 z-10 px-3 py-1.5 text-xs bg-menu border border-edge-muted hover:bg-hover hover-transition-bg ${props.class ?? ''}`}
onClick={() => {
- props.navigation()?.scrollToBottom('end');
+ props.onScrollToBottom();
}}
>
Scroll to bottom
diff --git a/js/app/packages/channel/Channel/create-target-message-controller.ts b/js/app/packages/channel/Channel/create-target-message-controller.ts
index 2736b30e10..3e41692750 100644
--- a/js/app/packages/channel/Channel/create-target-message-controller.ts
+++ b/js/app/packages/channel/Channel/create-target-message-controller.ts
@@ -117,6 +117,16 @@ export function createTargetMessageController(
)
);
+ const reset = () => {
+ setTargetMessageData({
+ activeTargetMessageId: undefined,
+ activeTargetMessageReplyId: undefined,
+ loadAroundMessageId: undefined,
+ pendingScrollTargetId: undefined,
+ pendingTargetReplyId: undefined,
+ });
+ };
+
return {
activeTargetMessageId: () => targetMessageData['activeTargetMessageId'],
activeTargetMessageReplyId: () =>
@@ -128,6 +138,7 @@ export function createTargetMessageController(
goToMessage,
completePendingScroll,
completePendingReplyScroll,
+ reset,
};
}