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.

feat(channels): debounce thread-replies on mount, change base page size to 50, unless cursor provided (#2172)

teo4d3c6e3e7097
diff --git a/js/app/packages/channel/Thread/ChannelThread.tsx b/js/app/packages/channel/Thread/ChannelThread.tsx
index 54d495f4c0..2853662010 100644
--- a/js/app/packages/channel/Thread/ChannelThread.tsx
+++ b/js/app/packages/channel/Thread/ChannelThread.tsx
@@ -3,6 +3,7 @@ import { createEffect, createSignal, on, Show } from 'solid-js';
import { ChannelMessage } from '../Message';
import { MarkMessaageNotifications } from '@notifications/components/MarkMessageNotifications';
import { useUserId } from '@core/context/user';
+import { deferredGate } from '@core/util/debounce';
import { tryMacroId, useDisplayName } from '@core/user';
import { Thread } from './Thread';
import type { ThreadProps } from './types';
@@ -25,7 +26,8 @@ export function ChannelThread(props: ThreadProps) {
const [displayName] = useDisplayName(macroId());
const thread = () => props.data().thread;
const hasReplies = () => thread().reply_count > 0;
- const fetchRepliesEnabled = () => props.data().thread.reply_count > 0;
+ const fetchRepliesEnabled = deferredGate(hasReplies, 300);
+
const isSelected = () => props.selectedMessageId?.() === props.data().id;
const repliesQuery = useThreadRepliesQuery(
diff --git a/js/app/packages/core/util/debounce.ts b/js/app/packages/core/util/debounce.ts
index c45ca728ce..1fb6aad072 100644
--- a/js/app/packages/core/util/debounce.ts
+++ b/js/app/packages/core/util/debounce.ts
@@ -67,6 +67,37 @@ export function laggedGate(source: () => boolean, delay = 300): () => boolean {
return follow;
}
+/**
+ * Create a cold-start lagged gate. Like {@link laggedGate} but always starts
+ * `false`, even when the source is already `true` at creation time. The gate
+ * opens only after the source has been continuously `true` for `delay` ms.
+ * If the owning scope is disposed (e.g. component unmounts) before the delay
+ * elapses the pending timer is cancelled and the gate never opens.
+ *
+ * Signal A ##############__________######
+ * Signal B _______#######________________
+ *
+ * @param source a boolean signal
+ * @param delay the delay time in ms
+ * @returns a derived signal
+ */
+export function deferredGate(
+ source: () => boolean,
+ delay = 300
+): () => boolean {
+ const [follow, setFollow] = createSignal(false);
+ const up = solidDebounce(() => setFollow(true), delay);
+ createEffect(() => {
+ if (source()) {
+ up();
+ } else {
+ up.clear();
+ setFollow(false);
+ }
+ });
+ return follow;
+}
+
/**
* Create a sticky-on-true signal. A debounced view that is only debounced on
* the falling edge. In the examples below (_) is the false state and (#) is the
diff --git a/js/app/packages/queries/channel/channel-messages.ts b/js/app/packages/queries/channel/channel-messages.ts
index 8324adc865..c89540eb3e 100644
--- a/js/app/packages/queries/channel/channel-messages.ts
+++ b/js/app/packages/queries/channel/channel-messages.ts
@@ -66,7 +66,7 @@ export function channelMessagesQueryOptions(
async () =>
await commsServiceClient.getChannelMessages({
channel_id: channelId,
- limit: 100,
+ limit: pageParam ? 100 : 50,
next_cursor: pageParam?.next_cursor ?? null,
previous_cursor: pageParam?.previous_cursor ?? null,
load_around_message_id: !pageParam ? loadAroundMessageId : null,