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
chg(new-channels): wait for channel ready before exposing handle (#2061)
teo447237e0d679
diff --git a/js/app/packages/block-channel/component/NewChannelBlockAdapter.tsx b/js/app/packages/block-channel/component/NewChannelBlockAdapter.tsxindex 02a6b92638..862240eb04 100644--- a/js/app/packages/block-channel/component/NewChannelBlockAdapter.tsx+++ b/js/app/packages/block-channel/component/NewChannelBlockAdapter.tsx@@ -4,7 +4,7 @@ import {} from '@channel/Channel/Channel';import { useBlockId } from '@core/block';import { EntityPermissionsGate } from '@core/component/EntityPermissionsGate';-import { createSignal, Suspense } from 'solid-js';+import { Suspense } from 'solid-js';import { blockHandleSignal } from '@core/signal/load';import { createMethodRegistration } from '@core/orchestrator';import { URL_PARAMS } from '@block-channel/constants';@@ -35,30 +35,30 @@ function NewTop(props: { channelId: string }) {export function NewChannelBlockAdapter() {useBlockEntityCommands();const channelId = useBlockId();- const [channelHandle, setChannelHandle] = createSignal<ChannelHandle>();-const blockHandle = blockHandleSignal.get;- createMethodRegistration(blockHandle, {- goToLocationFromParams: async (params: Record<string, unknown>) => {- const threadId = params[URL_PARAMS.thread] as string | undefined;- const messageId = params[URL_PARAMS.message] as string | undefined;- // For compatibility the naming is a little strange here.- // New channels index by top level message and then spertately handle replies.- // If we have a threadId that is actually the top level message and the reply is the message id.- const topLevelMessageId = threadId ? threadId : messageId;- const messageReplyId = threadId ? messageId : threadId;- const handle = channelHandle();+ const onChannelReady = (handle: ChannelHandle) => {+ createMethodRegistration(blockHandle, {+ goToLocationFromParams: async (params: Record<string, unknown>) => {+ const threadId = params[URL_PARAMS.thread] as string | undefined;+ const messageId = params[URL_PARAMS.message] as string | undefined;++ // For compatibility the naming is a little strange here.+ // New channels index by top level message and then spertately handle replies.+ // If we have a threadId that is actually the top level message and the reply is the message id.+ const topLevelMessageId = threadId ? threadId : messageId;+ const messageReplyId = threadId ? messageId : threadId;- if (topLevelMessageId && handle) {- handle.goToMessage(topLevelMessageId, messageReplyId);- }- },- });+ if (topLevelMessageId && handle) {+ handle.goToMessage(topLevelMessageId, messageReplyId);+ }+ },+ });+ };return (<EntityPermissionsGate entityType="channel" entityId={channelId}>- <NewChannel channelId={channelId} onHandleReady={setChannelHandle} />+ <NewChannel channelId={channelId} onHandleReady={onChannelReady} /><NewTop channelId={channelId} /></EntityPermissionsGate>);diff --git a/js/app/packages/channel/Channel/Channel.tsx b/js/app/packages/channel/Channel/Channel.tsxindex 68573df01f..e56ebe00be 100644--- a/js/app/packages/channel/Channel/Channel.tsx+++ b/js/app/packages/channel/Channel/Channel.tsx@@ -7,6 +7,7 @@ import {createEffect,createMemo,createSignal,+ on,onMount,Show,Suspense,@@ -215,12 +216,18 @@ export function Channel(props: ChannelProps) {});};- createEffect(() => {- if (props.onHandleReady)- props.onHandleReady({- goToMessage: targetMessageController.goToMessage,- });- });+ const isChannelReady = () => {+ return messagesQuery.isFetched && threadListNavigation();+ };++ createEffect(+ on(isChannelReady, () => {+ if (props.onHandleReady)+ props.onHandleReady({+ goToMessage: targetMessageController.goToMessage,+ });+ })+ );return (<Suspense>