Skip to content

YC (S26) | Open Computer History | Continuously record your company computer work, map your workflows, help you find work worth automating, and power your agents' context

fix(share): keep each mode's connection across the send toggle

Louis Beaumontb995c5ccfdbd
diff --git a/apps/screenpipe-app-tauri/components/connected-share-dialog.test.tsx b/apps/screenpipe-app-tauri/components/connected-share-dialog.test.tsx
index 3cd46dcfd..0ae1b1e10 100644
--- a/apps/screenpipe-app-tauri/components/connected-share-dialog.test.tsx
+++ b/apps/screenpipe-app-tauri/components/connected-share-dialog.test.tsx
@@ -432,6 +432,76 @@ describe("ConnectedShareDialog", () => {
);
});
+ // The mode toggle describes how a snapshot is processed, not where it goes.
+ // It used to blank the destination on the side it left, so a person who
+ // looked at "send unchanged" and came back found Obsidian gone and the send
+ // button back to "choose a destination" — two clicks on a toggle silently
+ // discarded the connection.
+ it("keeps each mode's connection when the toggle moves between them", async () => {
+ mocks.localFetch.mockImplementation(async (path: string) => {
+ if (path === "/connections") {
+ return jsonResponse({
+ data: [
+ { id: "slack", connected: true },
+ { id: "notion", connected: true, mcp: true },
+ { id: "obsidian", connected: true, mcp: true },
+ ],
+ });
+ }
+ if (path === "/connections/slack/instances") {
+ return jsonResponse({ instances: [] });
+ }
+ if (path.startsWith("/connections/slack/conversations")) {
+ return jsonResponse({ channels: [] });
+ }
+ throw new Error(`unexpected request: ${path}`);
+ });
+
+ render(
+ <ConnectedShareDialog open onOpenChange={vi.fn()} artifact={artifact} />,
+ );
+
+ const unchanged = await screen.findByTestId(
+ "connected-share-mode-unchanged",
+ );
+ const chat = screen.getByTestId("connected-share-mode-chat");
+ const destination = screen.getByTestId("connected-share-destination");
+ const confirm = screen.getByTestId("connected-share-confirm");
+
+ // Chat has two apps, so it opens unanswered until the person picks one.
+ fireEvent.click(chat);
+ await waitFor(() => expect(chat).toHaveAttribute("aria-pressed", "true"));
+ expect(destination).toHaveTextContent("choose where this goes");
+ await openDestinations();
+ fireEvent.click(
+ await screen.findByTestId("connected-share-destination-chat-obsidian"),
+ );
+ await waitFor(() => expect(destination).toHaveTextContent("Obsidian"));
+
+ // Obsidian cannot receive a frozen copy directly, so unchanged shows the
+ // one app that can. That is a different question, not a lost answer.
+ fireEvent.click(unchanged);
+ await waitFor(() =>
+ expect(unchanged).toHaveAttribute("aria-pressed", "true"),
+ );
+ expect(destination).toHaveTextContent("Slack");
+ expect(confirm).toHaveTextContent("send to Slack");
+
+ fireEvent.click(chat);
+ await waitFor(() => expect(chat).toHaveAttribute("aria-pressed", "true"));
+ expect(destination).toHaveTextContent("Obsidian");
+ expect(destination).not.toHaveTextContent("choose where this goes");
+ expect(confirm).toHaveTextContent("prepare Obsidian in Chat");
+ expect(confirm).not.toBeDisabled();
+
+ // And back again: the unchanged side kept its own answer too.
+ fireEvent.click(unchanged);
+ await waitFor(() =>
+ expect(unchanged).toHaveAttribute("aria-pressed", "true"),
+ );
+ expect(destination).toHaveTextContent("Slack");
+ });
+
// A failed check used to resolve to the clipboard, so the dialog quietly
// offered a local write under a button that says send. It now says it could
// not check and offers retry, and nothing is sendable until it succeeds.
diff --git a/apps/screenpipe-app-tauri/components/connected-share-dialog.tsx b/apps/screenpipe-app-tauri/components/connected-share-dialog.tsx
index 673b38cb5..1f2a9cba8 100644
--- a/apps/screenpipe-app-tauri/components/connected-share-dialog.tsx
+++ b/apps/screenpipe-app-tauri/components/connected-share-dialog.tsx
@@ -268,6 +268,28 @@ export function ConnectedShareDialog({
*/
const pendingRecallRef = useRef<RememberedShare | null>(null);
+ /**
+ * The last destination each mode held, so the toggle is not destructive.
+ *
+ * Switching mode used to blank the destination whenever the chosen app had
+ * no counterpart on the other side — Obsidian can only be prepared in Chat —
+ * and switching back did not bring it back. Two clicks on a toggle that
+ * describes *how* a snapshot is processed silently discarded *where* it was
+ * going, so the send button fell back to "choose a destination".
+ */
+ const modeDestinationRef = useRef<
+ Record<ShareMode, ConnectedShareDestination | null>
+ >({ unchanged: null, chat: null });
+
+ /** Record a destination against its own mode, for a later switch back. */
+ const rememberModeDestination = useCallback(
+ (next: ConnectedShareDestination | null) => {
+ if (!next) return;
+ modeDestinationRef.current[shareModeForDestination(next)] = next;
+ },
+ [],
+ );
+
/**
* Claim the remembered target for a destination, once.
*
@@ -314,6 +336,7 @@ export function ConnectedShareDialog({
useEffect(() => {
if (!open) return;
pendingRecallRef.current = null;
+ modeDestinationRef.current = { unchanged: null, chat: null };
resetPreview(allSectionIds);
setLinearTitle(artifact.title);
// Stays null until the connection check says what is actually reachable.
@@ -394,6 +417,7 @@ export function ConnectedShareDialog({
connected,
) as ConnectedShareDestination | null);
setDestination(nextDestination);
+ rememberModeDestination(nextDestination);
// Make the data-processing choice visible before the destination menu.
// When both are possible, unchanged is the lower-authority default;
// the destination remains unanswered until the person chooses one.
@@ -443,7 +467,13 @@ export function ConnectedShareDialog({
clearTimeout(timeoutId);
controller.abort();
};
- }, [artifact.surface, connectionsRefresh, initialDestination, open]);
+ }, [
+ artifact.surface,
+ connectionsRefresh,
+ initialDestination,
+ open,
+ rememberModeDestination,
+ ]);
useEffect(() => {
if (!open || !availability.direct.slack) return;
@@ -661,6 +691,7 @@ export function ConnectedShareDialog({
const selectDestination = (next: ConnectedShareDestination) => {
setDestination(next);
+ rememberModeDestination(next);
setShareMode(shareModeForDestination(next));
setReceipt(null);
setActionError(null);
@@ -886,16 +917,26 @@ export function ConnectedShareDialog({
const selectShareMode = (nextMode: ShareMode) => {
const nextOptions = nextMode === "chat" ? chatOptions : directOptions;
- const currentStillFits =
- destination !== null &&
- shareModeForDestination(destination) === nextMode &&
- nextOptions.some((option) => option.value === destination);
+ // Hold the connection this mode is leaving, so coming back is a switch and
+ // not a re-pick. Every app belongs to exactly one mode — Slack only sends
+ // unchanged, Obsidian and Notion only prepare in Chat, and Linear is one
+ // or the other depending on whether it arrived over MCP — so the toggle
+ // cannot carry an app across. What it can do is stop destroying the choice
+ // on the side it left.
+ rememberModeDestination(destination);
+ const remembered = modeDestinationRef.current[nextMode];
+ const rememberedStillFits =
+ remembered && nextOptions.some((option) => option.value === remembered)
+ ? remembered
+ : null;
+ // Choosing a mode is not permission to choose among several external
+ // targets. Auto-select only when the mode has exactly one possible app.
+ const nextDestination =
+ rememberedStillFits ??
+ (nextOptions.length === 1 ? nextOptions[0].value : null);
setShareMode(nextMode);
- if (!currentStillFits) {
- // Choosing a mode is not permission to choose among several external
- // targets. Auto-select only when the mode has exactly one possible app.
- setDestination(nextOptions.length === 1 ? nextOptions[0].value : null);
- }
+ setDestination(nextDestination);
+ rememberModeDestination(nextDestination);
setReceipt(null);
setActionError(null);
posthog.capture("connected_share_mode_selected", {