Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import { useAtomCommand } from "../../state/use-atom-command";
import { ListChoiceRow as SettingsChoiceRow } from "../../components/ui/ListChoiceRow";
import { SettingsSection } from "./components/SettingsSection";
import { SettingsScreen } from "./components/SettingsScreen";
import { ShareTemplatesSection } from "./ShareTemplatesSection";

const FOLLOW_UP_OPTIONS: ReadonlyArray<{
readonly behavior: FollowUpBehavior;
Expand Down Expand Up @@ -70,6 +71,7 @@ export function SettingsFollowUpRouteScreen() {
keyboard, hold <Var>{Platform.OS === "android" ? "Ctrl" : "Command"}</Var> while sending.
</T>
</Text>
<ShareTemplatesSection />
</ScrollView>
);

Expand Down
100 changes: 100 additions & 0 deletions apps/mobile/src/features/settings/ShareTemplatesSection.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
import { useGT } from "gt-react-native";
import { useAtomValue } from "@effect/atom-react";
import { AsyncResult } from "effect/reactivity";
import { useState } from "react";
import { TextInput, View } from "react-native";

import * as Dialog from "../../components/ui/Dialog";
import { IconButton } from "../../components/ui/IconButton";
import { ListActionRow } from "../../components/ui/ListActionRow";
import { uuidv4 } from "../../lib/uuid";
import { mobilePreferencesAtom, saveMobilePreferences } from "../../state/preferences";
import { useAtomCommand } from "../../state/use-atom-command";
import { SHARE_TEMPLATE_PLACEHOLDER, type ShareTemplate } from "../sharing/share-templates";
import { SettingsSection } from "./components/SettingsSection";

export function ShareTemplatesSection() {
const gt = useGT();
const preferencesResult = useAtomValue(mobilePreferencesAtom);
const savePreferences = useAtomCommand(saveMobilePreferences);
const [addedTemplateId, setAddedTemplateId] = useState<string | null>(null);
const templates = AsyncResult.isSuccess(preferencesResult)
? (preferencesResult.value.shareTemplates ?? [])
: null;

const updateTemplates = (
transform: (templates: ReadonlyArray<ShareTemplate>) => ReadonlyArray<ShareTemplate>,
) => {
void savePreferences({
transform: (current) => ({ shareTemplates: transform(current.shareTemplates ?? []) }),
});
};
const addTemplate = () => {
const id = uuidv4();
setAddedTemplateId(id);
updateTemplates((current) => [...current, { id, prompt: "" }]);
};
const removeTemplate = (template: ShareTemplate) => {
const remove = () =>
updateTemplates((current) => current.filter(({ id }) => id !== template.id));
if (!template.prompt.trim()) {
remove();
return;
}
Dialog.confirm({
title: gt("Delete this template?"),
confirmText: gt("Delete"),
destructive: true,
onConfirm: remove,
});
};

return (
<SettingsSection
title={gt("Share templates")}
footer={gt(
"When you share to T3 Code from another app, choose a template to wrap what you shared. Write {placeholder} where the shared text goes, or it goes at the end.",
{ placeholder: SHARE_TEMPLATE_PLACEHOLDER },
)}
>
{(templates ?? []).map((template) => (
<View
key={template.id}
className="flex-row items-start gap-1 border-b border-border-subtle py-1 pl-4"
>
{/* Uncontrolled so saving each keystroke never moves the cursor. */}
<TextInput
accessibilityLabel={gt("Template prompt")}
className="min-h-12 flex-1 py-2 text-base text-foreground"
placeholderTextColorClassName="accent-foreground-muted"
placeholder={gt("Review this for bugs:\n\n{placeholder}", {
placeholder: SHARE_TEMPLATE_PLACEHOLDER,
})}
multiline
autoFocus={template.id === addedTemplateId}
defaultValue={template.prompt}
onChangeText={(prompt) =>
updateTemplates((current) =>
current.map((candidate) =>
candidate.id === template.id ? { ...candidate, prompt } : candidate,
),
)
}
/>
<IconButton
accessibilityLabel={gt("Delete template")}
icon="trash"
tintColorClassName="accent-danger-foreground"
onPress={() => removeTemplate(template)}
/>
</View>
))}
<ListActionRow
icon="plus"
label={gt("Add template")}
disabled={templates === null}
onPress={addTemplate}
/>
</SettingsSection>
);
}
2 changes: 2 additions & 0 deletions apps/mobile/src/features/settings/settings-search.ts
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,8 @@ const SETTINGS_SEARCH_TERMS = {
msg("queue", { $context: "settings search keyword" }),
msg("steer", { $context: "settings search keyword" }),
msg("while the agent is running", { $context: "settings search keyword" }),
msg("share templates", { $context: "settings search keyword" }),
msg("share sheet", { $context: "settings search keyword" }),
],
SettingsArchive: [
msg("archive", { $context: "settings search keyword" }),
Expand Down
1 change: 1 addition & 0 deletions apps/mobile/src/features/sharing/IncomingShareProvider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,7 @@ const incomingShareInbox = new IncomingShareInbox({
? await resolvedPayloadsForFiles()
: [];
const draft = await buildIncomingShareDraft({
attachmentIdPrefix: Crypto.randomUUID(),
payloads,
resolvedPayloads,
fileReader: {
Expand Down
83 changes: 69 additions & 14 deletions apps/mobile/src/features/sharing/incoming-share-model.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import type { ResolvedSharePayload, SharePayload } from "expo-sharing";

import {
buildIncomingShareDraft,
decodeIncomingShareDraft,
hasIncomingShareContent,
isShareFileUriUnderOwnedRoots,
selectIncomingShareAttachments,
Expand Down Expand Up @@ -46,11 +47,17 @@ describe("incoming native shares", () => {
value: "file:///shared/Screenshot.png",
mimeType: "image/png",
};
const file: SharePayload = {
shareType: "file",
value: "file:///shared/report.pdf",
mimeType: "application/pdf",
};
const payloads: SharePayload[] = [
{ shareType: "text", value: "Please explain this error" },
{ shareType: "url", value: "https://example.com/issue/1" },
{ shareType: "text", value: "Please explain this error" },
image,
file,
];
const resolvedImage: ResolvedSharePayload = {
...image,
Expand All @@ -63,23 +70,44 @@ describe("incoming native shares", () => {
const removeOwnedFile = vi.fn(() => Promise.resolve());
const readBase64 = vi.fn(async () => "YWJj");
const persistedUri = "file:///documents/t3-composer-attachments/Screenshot.png";
const persistFile = vi.fn(async () => persistedUri);
const persistFile = vi.fn(
async (_uri: string, name: string) => `file:///documents/t3-composer-attachments/${name}`,
);

const result = await buildIncomingShareDraft({
id: "share-1",
createdAt: "2026-07-15T10:00:00.000Z",
payloads,
resolvedPayloads: [resolvedImage],
fileReader: {
readBase64,
persistFile,
readSize: async (uri) => (uri === persistedUri ? 3 : null),
removeOwnedFile,
},
});
const build = (attachmentIdPrefix: string) =>
buildIncomingShareDraft({
attachmentIdPrefix,
id: "share-1",
createdAt: "2026-07-15T10:00:00.000Z",
payloads,
resolvedPayloads: [
resolvedImage,
{
...file,
contentUri: file.value,
contentType: "file",
contentMimeType: "application/pdf",
contentSize: 3,
originalName: "report.pdf",
},
],
fileReader: {
readBase64,
persistFile,
readSize: async () => 3,
removeOwnedFile,
},
});

const result = await build("share-1");
const repeated = await build("second-handoff");
expect(
new Set([...result.attachments, ...repeated.attachments].map((attachment) => attachment.id))
.size,
).toBe(4);

expect(result).toEqual({
schemaVersion: 1,
schemaVersion: 2,
id: "share-1",
createdAt: "2026-07-15T10:00:00.000Z",
text: "Please explain this error\n\nhttps://example.com/issue/1",
Expand All @@ -93,9 +121,22 @@ describe("incoming native shares", () => {
fileUri: persistedUri,
previewUri: persistedUri,
},
{
id: "share-1-file-4",
type: "file",
name: "report.pdf",
mimeType: "application/pdf",
sizeBytes: 3,
fileUri: "file:///documents/t3-composer-attachments/report.pdf",
},
],
warnings: [],
});
expect(decodeIncomingShareDraft(result)).toEqual(result);
expect(decodeIncomingShareDraft({ ...result, schemaVersion: 1 })).toEqual({
...result,
schemaVersion: 1,
});
expect(removeOwnedFile).toHaveBeenCalledWith(image.value);
expect(removeOwnedFile).not.toHaveBeenCalledWith(persistedUri);
expect(hasIncomingShareContent(result)).toBe(true);
Expand All @@ -112,6 +153,7 @@ describe("incoming native shares", () => {
const removeOwnedFile = vi.fn(async (_uri: string) => undefined);

const draft = await buildIncomingShareDraft({
attachmentIdPrefix: "share-resize",
id: "share-resize",
createdAt: "2026-07-15T10:00:00.000Z",
payloads: [
Expand Down Expand Up @@ -152,6 +194,7 @@ describe("incoming native shares", () => {
const persistedUri = "file:///documents/t3-composer-attachments/photo.png";
const removeOwnedFile = vi.fn(async (_uri: string) => undefined);
const result = await buildIncomingShareDraft({
attachmentIdPrefix: "share-unmeasured",
id: "share-unmeasured",
createdAt: "2026-07-15T10:00:00.000Z",
payloads: [image],
Expand Down Expand Up @@ -189,6 +232,7 @@ describe("incoming native shares", () => {
const removeOwnedFile = vi.fn(() => Promise.resolve());

const result = await buildIncomingShareDraft({
attachmentIdPrefix: "share-2",
id: "share-2",
createdAt: "2026-07-15T10:00:00.000Z",
payloads: [image],
Expand Down Expand Up @@ -223,6 +267,7 @@ describe("incoming native shares", () => {
const removeOwnedFile = vi.fn(async (_uri: string) => undefined);

const result = await buildIncomingShareDraft({
attachmentIdPrefix: "share-report",
id: "share-report",
createdAt: "2026-07-15T10:00:00.000Z",
payloads: [file],
Expand Down Expand Up @@ -265,6 +310,7 @@ describe("incoming native shares", () => {
const removeOwnedFile = vi.fn(async () => undefined);

const result = await buildIncomingShareDraft({
attachmentIdPrefix: "share-video",
id: "share-video",
createdAt: "2026-08-30T10:00:00.000Z",
payloads: [{ ...video, shareType: "video" }],
Expand Down Expand Up @@ -310,6 +356,7 @@ describe("incoming native shares", () => {
};

const result = await buildIncomingShareDraft({
attachmentIdPrefix: "share-empty",
id: "share-empty",
createdAt: "2026-07-15T10:00:00.000Z",
payloads: [file],
Expand All @@ -335,6 +382,7 @@ describe("incoming native shares", () => {
const readSize = vi.fn(async (uri: string) => (uri.startsWith("content:") ? null : 42));

const result = await buildIncomingShareDraft({
attachmentIdPrefix: "share-android-report",
id: "share-android-report",
createdAt: "2026-07-15T10:00:00.000Z",
payloads: [file],
Expand Down Expand Up @@ -373,6 +421,7 @@ describe("incoming native shares", () => {
const removeOwnedFile = vi.fn(async (_uri: string) => undefined);

const result = await buildIncomingShareDraft({
attachmentIdPrefix: "share-empty-copy",
id: "share-empty-copy",
createdAt: "2026-07-15T10:00:00.000Z",
payloads: [file],
Expand All @@ -395,6 +444,7 @@ describe("incoming native shares", () => {
const removeOwnedFile = vi.fn(async () => undefined);

const result = await buildIncomingShareDraft({
attachmentIdPrefix: "share-no-copy",
id: "share-no-copy",
createdAt: "2026-07-15T10:00:00.000Z",
payloads: [{ shareType: "file", value: sourceUri, mimeType: "application/pdf" }],
Expand All @@ -417,6 +467,7 @@ describe("incoming native shares", () => {
const removeOwnedFile = vi.fn(async (_uri: string) => undefined);

const result = await buildIncomingShareDraft({
attachmentIdPrefix: "share-copy",
id: "share-copy",
createdAt: "2026-07-15T10:00:00.000Z",
payloads: [{ shareType: "file", value: payloadUri, mimeType: "application/pdf" }],
Expand Down Expand Up @@ -499,6 +550,7 @@ describe("incoming native shares", () => {
const readBase64 = vi.fn(async () => "YWJj");

const result = await buildIncomingShareDraft({
attachmentIdPrefix: "share-3",
id: "share-3",
createdAt: "2026-07-15T10:00:00.000Z",
payloads,
Expand Down Expand Up @@ -544,6 +596,7 @@ describe("incoming native shares", () => {
const removeOwnedFile = vi.fn(async () => undefined);

const result = await buildIncomingShareDraft({
attachmentIdPrefix: "share-duplicates",
id: "share-duplicates",
createdAt: "2026-07-16T08:00:00.000Z",
payloads: [duplicate, duplicate],
Expand Down Expand Up @@ -571,6 +624,7 @@ describe("incoming native shares", () => {
};

const result = await buildIncomingShareDraft({
attachmentIdPrefix: "share-cleanup-failure",
id: "share-cleanup-failure",
createdAt: "2026-07-16T08:00:00.000Z",
payloads: [image],
Expand All @@ -597,6 +651,7 @@ describe("incoming native shares", () => {
const removeOwnedFile = vi.fn(async (_uri: string) => undefined);

const result = await buildIncomingShareDraft({
attachmentIdPrefix: "share-persist-leak",
id: "share-persist-leak",
createdAt: "2026-07-16T08:00:00.000Z",
payloads: [file],
Expand Down
Loading
Loading