GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — fix(mobile): a share sent while a new-task draft is open joins that d… · pingdotgg/t3code@282a1fa

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options
  • apps/mobile/src/features
    • sharing
      • IncomingShareProvider.tsx
    • threads
      • NewTaskDraftScreen.tsx
Expand file treeCollapse file tree
Open diff view settings
Collapse file

‎apps/mobile/src/features/sharing/IncomingShareProvider.tsx‎

Copy file name to clipboardExpand all lines: apps/mobile/src/features/sharing/IncomingShareProvider.tsx
+49-2Lines changed: 49 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import {
1212
type SharePayload,
1313
} from "expo-sharing";
1414
import { msg } from "gt-react-native";
15+
import { Atom } from "effect/reactivity";
1516
import { useSyncExternalStore } from "react";
1617
import { Platform } from "react-native";
1718
import { CommonActions } from "@react-navigation/native";
@@ -32,7 +33,7 @@ import { rootNavigationRef } from "../../lib/rootNavigation";
3233
import { selectWorkspaceDetail } from "../layout/workspace/workspace-detail-selection";
3334
import { isDraftThreadRoute } from "../threads/thread-route-state";
3435
import { makeIncomingShareImports } from "../threads/incomingShareImport";
35-
import { liveNewTaskFlowKeys } from "../threads/new-task-flow-state";
36+
import { liveNewTaskFlowKeys, newTaskFlowKey } from "../threads/new-task-flow-state";
3637
import { appAtomRegistry } from "../../state/atom-registry";
3738
import { serverEnvironment } from "../../state/server";
3839
import {
@@ -222,6 +223,42 @@ let snapshot: IncomingShareSnapshot = { drafts: [], isLoading: true };
222223
const snapshotListeners = new Set<() => void>();
223224
let presentation = EMPTY_INCOMING_SHARE_PRESENTATION_STATE;
224225

226+
// A share that arrives while a new-task draft is on screen goes into that draft, by its flow key.
227+
const handedSharesAtom = Atom.make<Readonly<Record<string, string>>>({}).pipe(
228+
Atom.keepAlive,
229+
Atom.withLabel("mobile:incoming-share-handed"),
230+
);
231+
232+
/** The share handed to the open draft of `flowKey`, if any. */
233+
export const handedShareIdAtom = Atom.family((flowKey: string) =>
234+
Atom.make((get) => get(handedSharesAtom)[flowKey] ?? null).pipe(
235+
Atom.withLabel("mobile:incoming-share-handed:flow"),
236+
),
237+
);
238+
239+
export const noHandedShareIdAtom = Atom.make<string | null>(null).pipe(
240+
Atom.withLabel("mobile:incoming-share-handed:none"),
241+
);
242+
243+
function isPendingShare(shareId: string | undefined): boolean {
244+
return shareId !== undefined && snapshot.drafts.some((draft) => draft.id === shareId);
245+
}
246+
247+
/** Hands the oldest pending share to the draft on screen once that draft's own imports finished. */
248+
function handPendingShareToOpenDraft(route: { readonly key: string; readonly params?: object }) {
249+
const pendingShareId = snapshot.drafts[0]?.id;
250+
const flowKey = newTaskFlowKey(route);
251+
if (pendingShareId === undefined || flowKey === undefined) return;
252+
const draft = (route.params as { draft?: { incomingShareId?: string | string[] } }).draft;
253+
const routeShareId = Array.isArray(draft?.incomingShareId)
254+
? draft.incomingShareId[0]
255+
: draft?.incomingShareId;
256+
const handed = appAtomRegistry.get(handedSharesAtom);
257+
if (isPendingShare(routeShareId) || isPendingShare(handed[flowKey])) return;
258+
if (Object.values(handed).includes(pendingShareId)) return;
259+
appAtomRegistry.set(handedSharesAtom, { ...handed, [flowKey]: pendingShareId });
260+
}
261+
225262
function publish(drafts: ReadonlyArray<IncomingShareDraft>) {
226263
snapshot = { drafts, isLoading: false };
227264
for (const listener of snapshotListeners) listener();
@@ -274,6 +311,8 @@ export function presentPendingIncomingShare(): void {
274311
if (!rootNavigationRef.isReady()) return;
275312
const state = rootNavigationRef.getRootState();
276313
if (!state) return;
314+
const route = state.routes[state.index];
315+
if (route && isDraftThreadRoute(route)) handPendingShareToOpenDraft(route);
277316
const transition = transitionIncomingSharePresentation(presentation, {
278317
isShareSheetPresented: isDraftThreadRoute(state.routes[state.index]),
279318
pendingShareId: snapshot.drafts[0]?.id ?? null,
@@ -373,7 +412,15 @@ export const incomingShareImports = makeIncomingShareImports({
373412

374413
/** Abandons the share imports of draft routes that left the stack. */
375414
export function pruneIncomingShareImports(state: Parameters<typeof liveNewTaskFlowKeys>[0]) {
376-
void incomingShareImports.prune(liveNewTaskFlowKeys(state));
415+
const live = liveNewTaskFlowKeys(state);
416+
void incomingShareImports.prune(live);
417+
const handed = appAtomRegistry.get(handedSharesAtom);
418+
if (Object.keys(handed).some((flowKey) => !live.has(flowKey))) {
419+
appAtomRegistry.set(
420+
handedSharesAtom,
421+
Object.fromEntries(Object.entries(handed).filter(([flowKey]) => live.has(flowKey))),
422+
);
423+
}
377424
}
378425

379426
export function useIncomingShare() {
Collapse file

‎apps/mobile/src/features/threads/NewTaskDraftScreen.tsx‎

Copy file name to clipboardExpand all lines: apps/mobile/src/features/threads/NewTaskDraftScreen.tsx
+33-6Lines changed: 33 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,12 @@ import {
9292
resolveNewTaskBranchLabel,
9393
resolveNewTaskWorkspaceLabel,
9494
} from "./new-task-context-presentation";
95-
import { incomingShareImports, useIncomingShare } from "../sharing/IncomingShareProvider";
95+
import {
96+
handedShareIdAtom,
97+
incomingShareImports,
98+
noHandedShareIdAtom,
99+
useIncomingShare,
100+
} from "../sharing/IncomingShareProvider";
96101
import { idleShareFlagAtom, idleShareImportPhaseAtom } from "./incomingShareImport";
97102
import { newTaskFlowKey } from "./new-task-flow-state";
98103
import { EnvironmentMachineSymbol } from "../../components/EnvironmentMachineSymbol";
@@ -321,12 +326,19 @@ export function NewTaskDraftScreen(props: {
321326
!incomingShare &&
322327
!hasImportedIncomingShare,
323328
);
324-
const shareImportTarget = (() => {
325-
if (!props.incomingShareId || flowKey === undefined || !flow.draftKey) return null;
326-
if (!selectedProject || !incomingShare || isIncomingShareAwaitingServerConfig) return null;
329+
// The route's share was prepared for the draft's initial project; a handed share joins whichever project is selected.
330+
const importTargetFor = (share: typeof incomingShare, requireInitialProject: boolean) => {
331+
if (flowKey === undefined || !flow.draftKey || !selectedProject || !share) return null;
332+
if (
333+
share.attachments.some((attachment) => attachment.type === "file") &&
334+
selectedEnvironmentServerConfig === null
335+
) {
336+
return null;
337+
}
327338
const initialEnvironmentId = props.initialProjectRef?.environmentId;
328339
const initialProjectId = props.initialProjectRef?.projectId;
329340
if (
341+
requireInitialProject &&
330342
initialEnvironmentId &&
331343
initialProjectId &&
332344
(selectedProject.environmentId !== initialEnvironmentId ||
@@ -342,9 +354,24 @@ export function NewTaskDraftScreen(props: {
342354
environmentId: String(selectedProject.environmentId),
343355
projectId: String(selectedProject.id),
344356
},
345-
shareId: incomingShare.id,
357+
shareId: share.id,
346358
};
347-
})();
359+
};
360+
const shareImportTarget = props.incomingShareId ? importTargetFor(incomingShare, true) : null;
361+
const handedShareId = useAtomValue(
362+
flowKey === undefined ? noHandedShareIdAtom : handedShareIdAtom(flowKey),
363+
);
364+
// A share handed to this open draft merges in once the route's own share has finished. Not while
365+
// submitting: the post-submit clear would drop content the queued message doesn't contain.
366+
const handedShareImportTarget =
367+
handedShareId && handedShareId !== props.incomingShareId && !incomingShare && !flow.submitting
368+
? importTargetFor(getShare(handedShareId), false)
369+
: null;
370+
useAtomValue(
371+
handedShareImportTarget === null
372+
? idleShareImportPhaseAtom
373+
: incomingShareImports.phaseAtom(handedShareImportTarget),
374+
);
348375
const shareImportPhase = useAtomValue(
349376
shareImportTarget === null
350377
? idleShareImportPhaseAtom

0 commit comments

Comments
0 (0)
You are visitor 01402792 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.