Skip to content

Commit b394e95

Browse files
wpfleger96npub1mn7jgtj4w2pd0g0zeuhxsa6jy6p0rewxz4kujt98my82ahfmp72sxjexk7
andauthored
feat(desktop): active-draft badge, send-from-drafts confirm dialog, thread-deleted state (#1581)
Signed-off-by: Will Pfleger <[email protected]> Co-authored-by: npub1mn7jgtj4w2pd0g0zeuhxsa6jy6p0rewxz4kujt98my82ahfmp72sxjexk7 <dcfd242e557282d7a1e2cf2e6877522682f1e5c6156dc92ca7d90eaedd3b0f95@sprout-oss.stage.blox.sqprod.co>
1 parent b90e804 commit b394e95

25 files changed

Lines changed: 1542 additions & 69 deletions

‎desktop/scripts/check-file-sizes.mjs‎

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -227,7 +227,11 @@ const overrides = new Map([
227227
// +18: pendingImetaForPersistRef (local snapshot ref) + synchronous restore
228228
// path writes in the draft-key effect body, fixing the image-drop bug on
229229
// top-level nav switch (StrictMode simulate-unmount race on remount).
230-
["src/features/messages/ui/MessageComposer.tsx", 1021],
230+
// +12 autoSubmitDraftKey/onAutoSubmitComplete props + onAutoSubmitCompleteRef
231+
// + mount-only useEffect for the Drafts-panel "Send message" confirm-dialog
232+
// flow. Load-bearing feature growth; queued to split with the rest of this
233+
// list.
234+
["src/features/messages/ui/MessageComposer.tsx", 1033],
231235
]);
232236

233237
await runFileSizeCheck({

‎desktop/src/app/navigation/useAppNavigation.ts‎

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,12 @@ export function useAppNavigation() {
147147
options?: {
148148
/** Open the agent activity pane for this agent pubkey on arrival. */
149149
agentSession?: string;
150+
/**
151+
* When set, the main composer auto-submits the draft with this key
152+
* once on mount. Clears itself (via `?autoSend` search param) after
153+
* firing. Used by the Drafts panel "Send message" confirm flow.
154+
*/
155+
autoSend?: string;
150156
messageId?: string;
151157
replace?: boolean;
152158
threadRootId?: string | null;
@@ -168,6 +174,7 @@ export function useAppNavigation() {
168174
...(options?.agentSession
169175
? { agentSession: options.agentSession }
170176
: {}),
177+
...(options?.autoSend ? { autoSend: options.autoSend } : {}),
171178
},
172179
},
173180
{

‎desktop/src/app/routes/ChannelRouteScreen.tsx‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ import type { RelayEvent } from "@/shared/api/types";
1515
import { ViewLoadingFallback } from "@/shared/ui/ViewLoadingFallback";
1616

1717
type ChannelRouteScreenProps = {
18+
autoSendDraftKey: string | null;
1819
channelId: string;
1920
selectedPostId: string | null;
2021
targetMessageId: string | null;
@@ -94,6 +95,7 @@ async function fetchRouteTargetEvents(
9495
}
9596

9697
export function ChannelRouteScreen({
98+
autoSendDraftKey,
9799
channelId,
98100
selectedPostId,
99101
targetMessageId,
@@ -195,6 +197,7 @@ export function ChannelRouteScreen({
195197
return (
196198
<ChannelScreen
197199
activeChannel={activeChannel}
200+
autoSendDraftKey={autoSendDraftKey}
198201
currentIdentity={identityQuery.data}
199202
currentProfile={profileQuery.data}
200203
onCloseForumPost={() => {

‎desktop/src/app/routes/channels.$channelId.posts.$postId.tsx‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ function ForumPostRouteComponent() {
3939
fallback={<ViewLoadingFallback includeHeader kind="forum" />}
4040
>
4141
<ChannelRouteScreen
42+
autoSendDraftKey={null}
4243
channelId={channelId}
4344
selectedPostId={postId}
4445
targetMessageId={null}

‎desktop/src/app/routes/channels.$channelId.tsx‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,12 @@ import { ViewLoadingFallback } from "@/shared/ui/ViewLoadingFallback";
1111

1212
type ChannelRouteSearch = {
1313
agentSession?: string;
14+
/**
15+
* When set, the composer on mount will auto-submit its loaded draft once,
16+
* then clear this param. Value is the draft key that was loaded so the
17+
* composer can verify it has the right draft before firing.
18+
*/
19+
autoSend?: string;
1420
messageId?: string;
1521
profile?: string;
1622
profileTab?: ProfilePanelTab;
@@ -28,6 +34,7 @@ function validateChannelSearch(
2834
): ChannelRouteSearch {
2935
return {
3036
agentSession: nonEmptyString(search.agentSession),
37+
autoSend: nonEmptyString(search.autoSend),
3138
messageId: nonEmptyString(search.messageId),
3239
profile: nonEmptyString(search.profile),
3340
profileTab: parseProfilePanelTab(search.profileTab) ?? undefined,
@@ -56,6 +63,7 @@ function ChannelRouteComponent() {
5663
fallback={<ViewLoadingFallback includeHeader kind="channel" />}
5764
>
5865
<ChannelRouteScreen
66+
autoSendDraftKey={search.autoSend ?? null}
5967
channelId={channelId}
6068
selectedPostId={null}
6169
targetMessageId={search.messageId ?? null}

‎desktop/src/features/channels/ui/ChannelPane.tsx‎

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import * as React from "react";
22
import { Bot, Hash, LogIn, Plus, Sparkles, UserPlus } from "lucide-react";
3+
import { useAppNavigation } from "@/app/navigation/useAppNavigation";
34
import { useMediaUpload } from "@/features/messages/lib/useMediaUpload";
45
import { MessageComposer } from "@/features/messages/ui/MessageComposer";
56
import { DropZoneOverlay } from "@/features/messages/ui/ComposerAttachments";
@@ -61,6 +62,8 @@ export const ChannelPane = React.memo(function ChannelPane({
6162
agentPubkeysPending = false,
6263
agentSessionAgents,
6364
activityAgents = agentSessionAgents,
65+
autoSendDraftKey = null,
66+
onAutoSendComplete = null,
6467
botTypingEntries,
6568
channelFind,
6669
channelManagementOpen = false,
@@ -148,6 +151,7 @@ export const ChannelPane = React.memo(function ChannelPane({
148151
const welcomeComposerHideTimerRef = React.useRef<number | null>(null);
149152
const [welcomeComposerBannerState, setWelcomeComposerBannerState] =
150153
React.useState<WelcomeComposerBannerState>("prompt");
154+
const { goChannel } = useAppNavigation();
151155
const mainComposerMedia = useMediaUpload();
152156
const isNonMemberView =
153157
activeChannel !== null &&
@@ -156,6 +160,20 @@ export const ChannelPane = React.memo(function ChannelPane({
156160
!activeChannel.archivedAt;
157161
const hasMainComposerOverlay = !isNonMemberView;
158162
const activeChannelId = activeChannel?.id ?? null;
163+
// Clear the ?autoSend search param once the auto-submit fires so
164+
// back-navigation cannot re-trigger the send.
165+
// When `onAutoSendComplete` is provided it does a surgical single-key clear
166+
// that preserves `?thread` and all other panel search state (required for
167+
// the thread-draft send path so the thread panel does not unmount before the
168+
// deferred setTimeout(0) submit fires). The goChannel fallback is kept for
169+
// callers that do not supply the prop (e.g. isolated tests / older wrappers).
170+
const handleAutoSubmitComplete = React.useCallback(() => {
171+
if (onAutoSendComplete) {
172+
onAutoSendComplete();
173+
} else if (activeChannelId) {
174+
void goChannel(activeChannelId, { replace: true });
175+
}
176+
}, [activeChannelId, goChannel, onAutoSendComplete]);
159177
const huddleMemberPubkeys = React.useMemo(
160178
() => getDmHuddleMemberPubkeys(activeChannel, agentPubkeys, currentPubkey),
161179
[activeChannel, agentPubkeys, currentPubkey],
@@ -668,6 +686,8 @@ export const ChannelPane = React.memo(function ChannelPane({
668686
containerClassName="px-5"
669687
disabled={isComposerDisabled}
670688
editTarget={mainEditTarget}
689+
autoSubmitDraftKey={autoSendDraftKey}
690+
onAutoSubmitComplete={handleAutoSubmitComplete}
671691
isSending={isSending}
672692
mediaController={mainComposerMedia}
673693
onCancelEdit={onCancelEdit}
@@ -760,6 +780,8 @@ export const ChannelPane = React.memo(function ChannelPane({
760780
}
761781
layout={useSplitAuxiliaryPane ? "split" : "standalone"}
762782
transparentChrome={useSplitAuxiliaryPane}
783+
autoSendDraftKey={autoSendDraftKey}
784+
onAutoSubmitComplete={handleAutoSubmitComplete}
763785
onCancelEdit={onCancelEdit}
764786
onCancelReply={onCancelThreadReply}
765787
onClose={onCloseThread}

‎desktop/src/features/channels/ui/ChannelPane.types.ts‎

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,20 @@ export type ChannelPaneProps = {
1919
agentPubkeys?: ReadonlySet<string>;
2020
agentPubkeysPending?: boolean;
2121
agentSessionAgents: ChannelAgentSessionAgent[];
22+
/**
23+
* When non-null, the main composer fires `submitMessage` once after loading
24+
* the draft identified by this key — i.e. the user clicked "Send message"
25+
* in the Drafts panel and confirmed. Cleared by the composer after firing so
26+
* back-navigation cannot re-trigger.
27+
*/
28+
autoSendDraftKey?: string | null;
29+
/**
30+
* Called after the auto-submit guard fires to surgically clear `?autoSend`
31+
* from the URL while preserving `?thread` and all other panel search state.
32+
* If omitted, ChannelPane falls back to a full goChannel() re-navigation
33+
* (safe for the main-composer path, which carries no URL-backed thread).
34+
*/
35+
onAutoSendComplete?: (() => void) | null;
2236
botTypingEntries: TypingIndicatorEntry[];
2337
channelFind: ReturnType<typeof useChannelFind>;
2438
channelManagementOpen?: boolean;

‎desktop/src/features/channels/ui/ChannelScreen.tsx‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,7 @@ const HEADER_ACTIONS_COMPACT_BREAKPOINT_PX = 760,
8484
EMPTY_RELAY_EVENTS: RelayEvent[] = [];
8585
export function ChannelScreen({
8686
activeChannel,
87+
autoSendDraftKey,
8788
currentIdentity,
8889
currentProfile,
8990
onCloseForumPost,
@@ -112,6 +113,7 @@ export function ChannelScreen({
112113
} = useAppShell();
113114
const {
114115
channelManagementOpen,
116+
clearAutoSend,
115117
clearMessageRouteTarget,
116118
openAgentSessionChannelId,
117119
openAgentSessionPubkey,
@@ -846,6 +848,8 @@ export function ChannelScreen({
846848
agentPubkeys={agentPubkeys}
847849
agentPubkeysPending={agentPubkeysPending}
848850
agentSessionAgents={agentSessionAgents}
851+
autoSendDraftKey={autoSendDraftKey}
852+
onAutoSendComplete={clearAutoSend}
849853
botTypingEntries={botTypingEntries}
850854
channelFind={channelFind}
851855
channelManagementOpen={channelManagementOpen}

‎desktop/src/features/channels/ui/ChannelScreen.types.ts‎

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,13 @@ import type {
77

88
export type ChannelScreenProps = {
99
activeChannel: Channel | null;
10+
/**
11+
* When non-null, the main channel composer auto-submits once on mount after
12+
* loading the draft identified by this key. The route component clears the
13+
* `?autoSend` search param after the submit fires so back-navigation does
14+
* not re-trigger. Value must match the composer's `effectiveDraftKey`.
15+
*/
16+
autoSendDraftKey: string | null;
1017
currentIdentity?: Identity;
1118
currentProfile?: Profile;
1219
onCloseForumPost: () => void;
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
/**
2+
* URL search-param keys managed by the channel-panel history state.
3+
*
4+
* Kept in a separate pure module (no React / router imports) so tests can
5+
* import and assert the patch contracts without a browser environment.
6+
*/
7+
8+
export const CHANNEL_SEARCH_KEYS = [
9+
"agentSession",
10+
"agentSessionChannel",
11+
"autoSend",
12+
"channelManagement",
13+
"messageId",
14+
"profile",
15+
"profileTab",
16+
"profileView",
17+
"thread",
18+
"threadRootId",
19+
] as const;
20+
21+
export type ChannelSearchKey = (typeof CHANNEL_SEARCH_KEYS)[number];
22+
23+
/**
24+
* Returns the search-param patch that clears only the `autoSend` trigger.
25+
*
26+
* Exported so tests can verify the patch is surgical — it must not include
27+
* `thread` or any other panel key that would collapse open panels. This is
28+
* the regression guard for the "auto-submit clear drops the thread route"
29+
* defect: a `goChannel()` re-navigation drops every search key including
30+
* `thread`; this patch removes only `autoSend` via `applyPatch`, preserving
31+
* the thread panel across the deferred `setTimeout(0)` submit.
32+
*/
33+
export function buildAutoSendClearPatch(): Partial<
34+
Record<ChannelSearchKey, string | null>
35+
> {
36+
return { autoSend: null };
37+
}

0 commit comments

Comments
 (0)