Skip to content

armgit / alook

Public Imported from GitHub
0

Multi-Agent Collaboration for Team and Friends

feat(community): cross-channel sheet Reply navigates to the message's channel

Shellyadef1b4307e0
diff --git a/src/web/src/app/c/channels/[serverId]/[channelId]/page.tsx b/src/web/src/app/c/channels/[serverId]/[channelId]/page.tsx
index a73920ab7..79c5e6404 100644
--- a/src/web/src/app/c/channels/[serverId]/[channelId]/page.tsx
+++ b/src/web/src/app/c/channels/[serverId]/[channelId]/page.tsx
@@ -613,6 +613,33 @@ function ChannelView() {
)
}, [serverId, channelId, channelName])
+ // Reply clicked inside the context sheet. Same-channel preview → seed THIS
+ // channel's composer directly. Cross-channel preview → you can't reply here to
+ // a message that lives in another channel (Gus #449/#452), so hand the target
+ // off through the store and navigate to that message's channel; its page seeds
+ // its own composer on arrival (see the pendingReply effect below). Reply stays
+ // available in both cases — it just routes you to where the reply belongs.
+ const onSheetReply = useCallback((target: { id: string; authorName: string; text: string }) => {
+ if (contextTarget && contextTarget.channelId !== channelId) {
+ useCommunityStore.getState().setPendingReply({ channelId: contextTarget.channelId, target })
+ setContextTarget(null)
+ uiHandlers.navigate?.(contextTarget.serverId, contextTarget.channelId)
+ } else {
+ setReplyTo(target)
+ setContextTarget(null)
+ }
+ }, [contextTarget, channelId, uiHandlers])
+
+ // Consume a reply handed off from a cross-channel sheet on another page: if a
+ // pendingReply targets THIS channel, seed the composer once and clear it.
+ const pendingReply = useCommunityStore((s) => s.pendingReply)
+ useEffect(() => {
+ if (pendingReply && pendingReply.channelId === channelId) {
+ setReplyTo(pendingReply.target)
+ useCommunityStore.getState().setPendingReply(null)
+ }
+ }, [pendingReply, channelId])
+
// Same-channel message ref (`/server/channel#N`, channel open) via `jumpToSeq`:
// message loaded in the window → scroll+highlight it in place; not loaded →
// open the context sheet on THIS channel. Reads `messages` lazily off the
@@ -1092,10 +1119,7 @@ function ChannelView() {
onOpenContextSheet={openContextSeq}
onOpenProfile={openProfile}
resolveUserName={resolveUserName}
- onReply={(target) => {
- setReplyTo(target)
- setContextTarget(null)
- }}
+ onReply={onSheetReply}
/>
</>
)
@@ -1243,10 +1267,7 @@ function ChannelView() {
onOpenContextSheet={openContextSeq}
onOpenProfile={openProfile}
resolveUserName={resolveUserName}
- onReply={(target) => {
- setReplyTo(target)
- setContextTarget(null)
- }}
+ onReply={onSheetReply}
/>
</>
)
diff --git a/src/web/src/stores/community/index.ts b/src/web/src/stores/community/index.ts
index 6f679c35c..405b4b3bb 100644
--- a/src/web/src/stores/community/index.ts
+++ b/src/web/src/stores/community/index.ts
@@ -103,6 +103,17 @@ type CommunityUiHandlers = {
openMessageContext?: (target: { serverId: string; channelId: string; label: string; seq: number }) => void
}
+/** A reply target handed off across a channel navigation. Clicking Reply on a
+ * CROSS-channel message-context sheet can't seed the current channel's composer
+ * (you'd stamp a reply to a message in another channel). Instead the sheet
+ * stashes the target here + navigates to that message's channel; the
+ * destination channel page consumes it on mount and seeds ITS composer, so the
+ * reply lands in the right channel (Gus #449/#452). */
+type PendingReply = {
+ channelId: string
+ target: { id: string; authorName: string; text: string }
+}
+
type Timer = ReturnType<typeof setTimeout>
export type CommunityStoreState = {
@@ -129,6 +140,10 @@ export type CommunityStoreState = {
// Machine pairing in flight (raw token id awaiting activate).
pendingMachineTokenId: string | null
+ // A reply target handed off across a channel navigation (cross-channel sheet
+ // Reply → navigate → destination page seeds its composer). See `PendingReply`.
+ pendingReply: PendingReply | null
+
// What the WS handler should treat as "focused" for setQueryData vs
// invalidate routing.
subscription: CommunitySubscription
@@ -144,6 +159,7 @@ export type CommunityStoreState = {
subscribe: (target: CommunitySubscription) => void
unsubscribe: () => void
setPendingMachineTokenId: (tokenId: string | null) => void
+ setPendingReply: (reply: PendingReply | null) => void
registerUiHandlers: (handlers: CommunityUiHandlers) => void
reset: () => void
}
@@ -160,6 +176,7 @@ const initialState = (): Pick<
| "lastTypingSent"
| "reactionTimers"
| "pendingMachineTokenId"
+ | "pendingReply"
| "subscription"
| "uiHandlers"
> => ({
@@ -171,6 +188,7 @@ const initialState = (): Pick<
lastTypingSent: new Map(),
reactionTimers: new Map(),
pendingMachineTokenId: null,
+ pendingReply: null,
subscription: {},
uiHandlers: {},
})
@@ -215,6 +233,8 @@ export const useCommunityStore = create<CommunityStoreState>((set, get) => ({
setPendingMachineTokenId: (tokenId) =>
set({ pendingMachineTokenId: tokenId }),
+ setPendingReply: (reply) => set({ pendingReply: reply }),
+
registerUiHandlers: (handlers) =>
set({ uiHandlers: { ...get().uiHandlers, ...handlers } }),