Linger is An Open-Source Personal Agent That Runs Fully on Your PC. We aim to break Big Tech’s grip on AI by bringing powerful local AI to everyday computers through efficient model–harness co-design, so everyone can run their own.
feat(web): add mail attachments from a + tile and show the draft state
muterC590fcef147a3
diff --git a/apps/web/src/features/rooms/chat/message-mail-canvas.tsx b/apps/web/src/features/rooms/chat/message-mail-canvas.tsxindex 76250a14..ff683b18 100644--- a/apps/web/src/features/rooms/chat/message-mail-canvas.tsx+++ b/apps/web/src/features/rooms/chat/message-mail-canvas.tsx@@ -153,9 +153,6 @@ function MailCanvasEditor({session={model.session}/>) : null}- <div className="flex justify-end">- <span ref={model.setMailAttachmentsPortalTarget} />- </div><div className="room-document-main flex max-h-[520px] min-h-0 flex-col [&_.room-document-content-lane]:px-1 [&_.room-document-layout]:pb-2"><UnifiedDocumentBodydocumentContentRef={contentRef}diff --git a/apps/web/src/features/rooms/documents/AGENTS.md b/apps/web/src/features/rooms/documents/AGENTS.mdindex 12fe8156..f424eef7 100644--- a/apps/web/src/features/rooms/documents/AGENTS.md+++ b/apps/web/src/features/rooms/documents/AGENTS.md@@ -30,11 +30,12 @@IndexedDB internals from component tests.- Gmail canvases use the Mail sidebar header, an editable 15px semibold Subject abovethe From/To/Cc fields and collaborative body, without the generic Document title or- author row. Save status still comes from the durable session snapshot.- Formatting uses the existing editor controls. The Mail header paperclip uploads- file attachments (15 MiB total) through the existing Document Asset flow.- File blocks stay authoritative; the client presents them below the body with- sizes and remove controls, and reports their count in the header. Canvas has no+ author row. The header reads Drafting while an edit is not durable yet,+ Saved once it is, and Sent once delivered; connection and save problems+ keep the shared save indicator. Formatting uses the existing editor+ controls. Attachments (15 MiB total) upload through the existing Document+ Asset flow from a dashed + tile below the body; file blocks stay+ authoritative and show as tiles with sizes and remove controls. Canvas has nosending toolbar; the email's chat card sends it, and once its deliveryreports sent the editor writes `status: sent` into the header. Sent canvases stay read-only, suppress the editing indicator, and showempty recipient fields as None. Attachment list spacing stays inside thediff --git a/apps/web/src/features/rooms/documents/canvas/canvas-mail-attachments.test.tsx b/apps/web/src/features/rooms/documents/canvas/canvas-mail-attachments.test.tsxindex b09c2f47..6743c25a 100644--- a/apps/web/src/features/rooms/documents/canvas/canvas-mail-attachments.test.tsx+++ b/apps/web/src/features/rooms/documents/canvas/canvas-mail-attachments.test.tsx@@ -68,9 +68,7 @@ function setup(initialFiles: RoomDocumentPartialBlock[] = [], size = 1024) {}),resolveFileUrl: vi.fn(async () => "blob:attachment"),};- const portal = document.createElement("span");const host = document.createElement("div");- host.append(portal);document.body.append(host);const view = (editable = true) => (<QueryClientProvider client={queryClient}>@@ -79,7 +77,6 @@ function setup(initialFiles: RoomDocumentPartialBlock[] = [], size = 1024) {documentId="document_1"editor={editor as unknown as RoomDocumentEditor}editable={editable}- portalTarget={portal}scope="test"/></QueryClientProvider>@@ -91,7 +88,6 @@ function setup(initialFiles: RoomDocumentPartialBlock[] = [], size = 1024) {return {...result,editor,- portal,view,remote: (files: RoomDocumentPartialBlock[]) =>act(() => {@@ -119,27 +115,23 @@ function storedFile(function choose(file = new File(["brief"], "brief.pdf", { type: "application/pdf" }),) {- fireEvent.change(- screen.getByLabelText("Email attachments", { selector: "input" }),- { target: { files: [file] } },- );+ fireEvent.change(screen.getByLabelText("Choose attachments"), {+ target: { files: [file] },+ });}describe("Mail attachments", () => {- it("uploads durable file blocks, counts them in the header, and removes them without changing the body", async () => {+ it("adds files from the + tile as durable file blocks and removes them without changing the body", async () => {vi.mocked(uploadRoomDocumentAsset).mockResolvedValue("document-asset:asset_new",);- const { editor, portal } = setup();- const input = screen.getByLabelText("Email attachments", {- selector: "input",- });+ const { editor } = setup();+ const input = screen.getByLabelText("Choose attachments");const pick = vi.spyOn(input as HTMLInputElement, "click");fireEvent.click(screen.getByRole("button", { name: "Add attachments" }));expect(pick).toHaveBeenCalledOnce();choose();await screen.findByRole("button", { name: "Remove brief.pdf" });- expect(portal).toHaveTextContent("1");expect(editor.document.at(-1)).toMatchObject({type: "file",props: { name: "brief.pdf", url: "document-asset:asset_new" },@@ -147,7 +139,7 @@ describe("Mail attachments", () => {expect(await screen.findByText("1 KB")).toBeVisible();fireEvent.click(screen.getByRole("button", { name: "Remove brief.pdf" }));expect(editor.document.map((block) => block.id)).toEqual(["body"]);- expect(portal).not.toHaveTextContent("1");+ expect(screen.queryByRole("button", { name: "brief.pdf" })).toBeNull();});it("keeps an image chosen as an attachment in a file block", async () => {@@ -184,10 +176,9 @@ describe("Mail attachments", () => {});it("reflects collaborative file changes and hides mutations in read-only mode", async () => {- const { remote, portal, rerender, view } = setup();+ const { remote, rerender, view } = setup();remote([storedFile()]);await screen.findByRole("button", { name: "Remove brief.pdf" });- expect(portal).toHaveTextContent("1");rerender(view(false));expect(screen.queryByRole("button", { name: "Add attachments" }),diff --git a/apps/web/src/features/rooms/documents/canvas/canvas-mail-attachments.tsx b/apps/web/src/features/rooms/documents/canvas/canvas-mail-attachments.tsxindex f1836147..ce4dde65 100644--- a/apps/web/src/features/rooms/documents/canvas/canvas-mail-attachments.tsx+++ b/apps/web/src/features/rooms/documents/canvas/canvas-mail-attachments.tsx@@ -1,5 +1,5 @@import {- Attachment01Icon,+ Add01Icon,Cancel01Icon,File01Icon,} from "@hugeicons/core-free-icons";@@ -10,11 +10,11 @@ import {useQueryClient,} from "@tanstack/react-query";import { useLayoutEffect, useRef, useState } from "react";-import { createPortal } from "react-dom";import { AutoHeight } from "@/components/ui/auto-height";import { Button } from "@/components/ui/button";import { Icon } from "@/components/ui/icon";+import { Spinner } from "@/components/ui/spinner";import { teamHubData } from "@/features/teamhub/teamhub-api";import type { TeamHubClient } from "@/features/teamhub/teamhub-client";import { formatBytes } from "@/lib/format-bytes";@@ -59,14 +59,12 @@ export function CanvasMailAttachments({documentId,editable,editor,- portalTarget,scope,}: {client: TeamHubClient;documentId: string;editable: boolean;editor: RoomDocumentEditor;- portalTarget?: HTMLElement | null;scope: string;}) {const queryClient = useQueryClient();@@ -174,85 +172,88 @@ export function CanvasMailAttachments({.join("\n")}</style>) : null}- {editable && portalTarget- ? createPortal(- <>- <input- ref={input}- aria-label="Email attachments"- className="hidden"- type="file"- multiple- onChange={(event) => {- const files = Array.from(event.currentTarget.files ?? []);- event.currentTarget.value = "";- void add(files);- }}- />- <Button- aria-label="Add attachments"- title="Add attachments"- tone="ghost"- size={attachments.length ? "compact" : "compactIcon"}- loading={uploading}- onClick={() => input.current?.click()}- >- {!uploading ? <Icon icon={Attachment01Icon} size={16} /> : null}- {attachments.length > 0 ? (- <span>{attachments.length}</span>- ) : null}- </Button>- </>,- portalTarget,- )- : null}<AutoHeight>- {attachments.length > 0 || uploading || error ? (- <section aria-label="Email attachments" className="space-y-2 pt-5">- {attachments.map((file, index) => (- <div- key={file.id}- className="flex min-w-0 items-center gap-2 rounded-md bg-app-surface-soft px-3 py-2 text-sm"- >- <Icon- icon={File01Icon}- size={16}- className="shrink-0 text-app-muted"- />+ {attachments.length > 0 || editable ? (+ <section aria-label="Email attachments" className="pt-5">+ <input+ ref={input}+ aria-label="Choose attachments"+ className="hidden"+ type="file"+ multiple+ onChange={(event) => {+ const files = Array.from(event.currentTarget.files ?? []);+ event.currentTarget.value = "";+ void add(files);+ }}+ />+ <div className="flex flex-wrap gap-2">+ {attachments.map((file, index) => (+ <div+ key={file.id}+ className="flex h-16 min-w-0 max-w-60 items-center gap-2 rounded-lg border border-app-border bg-app-surface-soft py-2 pr-1 pl-3 text-sm"+ >+ <Icon+ icon={File01Icon}+ size={18}+ className="shrink-0 text-app-muted"+ />+ <span className="min-w-0 flex-1">+ <button+ type="button"+ className="block w-full truncate text-left text-app-ink hover:underline focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring"+ onClick={() => void download(file)}+ title={file.name || undefined}+ >+ {file.name ||+ metadata[index]?.data?.filename ||+ "Attachment"}+ </button>+ {metadata[index]?.data ? (+ <span className="block text-xs text-app-muted">+ {formatBytes(metadata[index].data.size_bytes)}+ </span>+ ) : null}+ </span>+ {editable ? (+ <Button+ aria-label={`Remove ${file.name || "attachment"}`}+ tone="ghost"+ size="compactIcon"+ onClick={() => {+ if (canEdit.current && editor.getBlock(file.id))+ editor.removeBlocks([file.id]);+ }}+ >+ <Icon icon={Cancel01Icon} size={14} />+ </Button>+ ) : null}+ </div>+ ))}+ {editable ? (<buttontype="button"- className="min-w-0 flex-1 text-left [overflow-wrap:anywhere] hover:underline focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring"- onClick={() => void download(file)}+ aria-label="Add attachments"+ title="Add attachments"+ disabled={uploading}+ onClick={() => input.current?.click()}+ className="flex size-16 shrink-0 items-center justify-center rounded-lg border border-dashed border-app-border text-app-muted transition-colors duration-150 hover:border-app-muted hover:bg-accent hover:text-app-ink focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring disabled:opacity-60 motion-reduce:transition-none">- {file.name || metadata[index]?.data?.filename || "Attachment"}+ {uploading ? (+ <Spinner size={16} />+ ) : (+ <Icon icon={Add01Icon} size={20} />+ )}</button>- {metadata[index]?.data ? (- <span className="shrink-0 text-xs text-app-muted">- {formatBytes(metadata[index].data.size_bytes)}- </span>- ) : null}- {editable ? (- <Button- aria-label={`Remove ${file.name || "attachment"}`}- tone="ghost"- size="compactIcon"- onClick={() => {- if (canEdit.current && editor.getBlock(file.id))- editor.removeBlocks([file.id]);- }}- >- <Icon icon={Cancel01Icon} size={14} />- </Button>- ) : null}- </div>- ))}+ ) : null}+ </div>{uploading ? (- <p role="status" className="text-xs text-app-muted">+ <p role="status" className="pt-2 text-xs text-app-muted">Uploading attachments…</p>) : null}{error ? (- <p role="alert" className="text-xs text-destructive">+ <p role="alert" className="pt-2 text-xs text-destructive">{error}</p>) : null}diff --git a/apps/web/src/features/rooms/documents/canvas/canvas-mail-status.test.tsx b/apps/web/src/features/rooms/documents/canvas/canvas-mail-status.test.tsxnew file mode 100644index 00000000..c977abc7--- /dev/null+++ b/apps/web/src/features/rooms/documents/canvas/canvas-mail-status.test.tsx@@ -0,0 +1,35 @@+import { render, screen } from "@testing-library/react";+import { describe, expect, it } from "vitest";++import type { RoomDocumentCollaborationSession } from "../room-document-collaboration";+import type { RoomDocumentSaveSnapshot } from "../room-document-save-tracker";+import { MailCanvasStatus } from "./canvas-mail-status";++function session(status: RoomDocumentSaveSnapshot["status"]) {+ const snapshot = { canEdit: true, status } as RoomDocumentSaveSnapshot;+ return {+ getSaveSnapshot: () => snapshot,+ readOnly: false,+ subscribeSaveState: () => () => {},+ } as unknown as RoomDocumentCollaborationSession;+}++describe("Mail canvas status", () => {+ it.each([+ ["Local pending", "Drafting"],+ ["Synced", "Drafting"],+ ["Saved", "Saved"],+ ] as const)("reads %s as %s", (status, label) => {+ render(+ <MailCanvasStatus isEditing sent={false} session={session(status)} />,+ );+ expect(screen.getByRole("status")).toHaveTextContent(label);+ });++ it("reads Sent once delivered, whatever the save state", () => {+ render(+ <MailCanvasStatus isEditing sent session={session("Local pending")} />,+ );+ expect(screen.getByRole("status")).toHaveTextContent("Sent");+ });+});diff --git a/apps/web/src/features/rooms/documents/canvas/canvas-mail-status.tsx b/apps/web/src/features/rooms/documents/canvas/canvas-mail-status.tsxnew file mode 100644index 00000000..9ebb15bc--- /dev/null+++ b/apps/web/src/features/rooms/documents/canvas/canvas-mail-status.tsx@@ -0,0 +1,53 @@+import { useSyncExternalStore } from "react";++import type { RoomDocumentCollaborationSession } from "../room-document-collaboration";+import { RoomDocumentSaveIndicator } from "../unified-document-body";++/**+ * The email's state in its header: Drafting while an edit is not durable+ * yet, Saved once it is, Sent for good once delivered. Connection and save+ * problems keep the shared save indicator.+ */+export function MailCanvasStatus({+ isEditing,+ sent,+ session,+}: {+ isEditing: boolean;+ sent: boolean;+ session: RoomDocumentCollaborationSession;+}) {+ const save = useSyncExternalStore(+ session.subscribeSaveState,+ session.getSaveSnapshot,+ session.getSaveSnapshot,+ );+ if (sent)+ return (+ <span aria-label="Email status" role="status">+ Sent+ </span>+ );+ if (save.protocolError === undefined) {+ if (save.status === "Saved")+ return (+ <span aria-label="Email status" role="status">+ Saved+ </span>+ );+ if (save.status === "Local pending" || save.status === "Synced")+ return (+ <span aria-label="Email status" role="status">+ Drafting+ </span>+ );+ if (save.status === "Connecting") return null;+ }+ return (+ <RoomDocumentSaveIndicator+ alwaysVisible+ isEditing={isEditing}+ session={session}+ />+ );+}diff --git a/apps/web/src/features/rooms/documents/room-document-blocknote-editor.tsx b/apps/web/src/features/rooms/documents/room-document-blocknote-editor.tsxindex 013fb872..42ad7155 100644--- a/apps/web/src/features/rooms/documents/room-document-blocknote-editor.tsx+++ b/apps/web/src/features/rooms/documents/room-document-blocknote-editor.tsx@@ -96,7 +96,6 @@ export interface RoomDocumentBlockNoteEditorProps {client: TeamHubClient;commentsOpen?: boolean;commentsPortalTarget?: HTMLElement | null;- mailAttachmentsPortalTarget?: HTMLElement | null;canComment: boolean;currentActorId: string;documentId: string;@@ -127,7 +126,6 @@ export function RoomDocumentBlockNoteEditor({canComment,commentsOpen,commentsPortalTarget,- mailAttachmentsPortalTarget,currentActorId,documentId,editable,@@ -566,7 +564,6 @@ export function RoomDocumentBlockNoteEditor({documentId={documentId}editable={editable && !canvasSent}editor={editor}- portalTarget={mailAttachmentsPortalTarget}scope={knowledge.scope}/>) : null}diff --git a/apps/web/src/features/rooms/documents/unified-document-body.tsx b/apps/web/src/features/rooms/documents/unified-document-body.tsxindex 65eda557..1e4b4f3a 100644--- a/apps/web/src/features/rooms/documents/unified-document-body.tsx+++ b/apps/web/src/features/rooms/documents/unified-document-body.tsx@@ -135,7 +135,6 @@ function UnifiedDocumentEditorLayout({client,commentsOpen,commentsPortalTarget,- mailAttachmentsPortalTarget,consumeAutoFocusTitle,editorRef,isEditing,@@ -196,7 +195,6 @@ function UnifiedDocumentEditorLayout({client={client}commentsOpen={commentsOpen}commentsPortalTarget={commentsPortalTarget}- mailAttachmentsPortalTarget={mailAttachmentsPortalTarget}currentActorId={actorId}documentId={document.id}editorRef={editorRef}@@ -384,7 +382,6 @@ function ActiveRoomDocumentEditor({client,commentsOpen,commentsPortalTarget,- mailAttachmentsPortalTarget,currentActorId,documentId,isEditing,@@ -403,7 +400,6 @@ function ActiveRoomDocumentEditor({client: ReturnType<typeof useTeamHubRuntime>["client"];commentsOpen: boolean;commentsPortalTarget: HTMLDivElement | null;- mailAttachmentsPortalTarget: HTMLSpanElement | null;currentActorId: string;documentId: string;isEditing: boolean;@@ -429,7 +425,6 @@ function ActiveRoomDocumentEditor({client={client}commentsOpen={commentsOpen}commentsPortalTarget={commentsPortalTarget}- mailAttachmentsPortalTarget={mailAttachmentsPortalTarget}currentActorId={currentActorId}documentId={documentId}editable={isEditing && save.canEdit}diff --git a/apps/web/src/features/rooms/documents/unified-document-header.tsx b/apps/web/src/features/rooms/documents/unified-document-header.tsxindex d04fa465..b20fe31e 100644--- a/apps/web/src/features/rooms/documents/unified-document-header.tsx+++ b/apps/web/src/features/rooms/documents/unified-document-header.tsx@@ -43,7 +43,7 @@ import { RoomDocumentPresence } from "./room-document-presence";import { collaborationColor } from "./room-document-presence-model";import { DocumentActionsMenu } from "./room-document-actions-menu";import type { UnifiedDocumentPageModel } from "./use-unified-document-page-model";-import { RoomDocumentSaveIndicator } from "./unified-document-body";+import { MailCanvasStatus } from "./canvas/canvas-mail-status";interface UnifiedDocumentPageHeaderProps {documentContentRef: MutableRefObject<HTMLDivElement | null>;@@ -97,7 +97,6 @@ export function UnifiedDocumentPageHeader({exportPending={exportPending}canvasSent={canvasSent}mailCanvas={model.canvasTarget === "gmail"}- setMailAttachmentsPortalTarget={model.setMailAttachmentsPortalTarget}isEditing={isEditing}onComments={() => setCommentsOpen((value) => !value)}onCopyLink={() =>@@ -175,7 +174,6 @@ function UnifiedDocumentHeader({exportPending,canvasSent,mailCanvas,- setMailAttachmentsPortalTarget,isEditing,onComments,onCopyLink,@@ -204,7 +202,6 @@ function UnifiedDocumentHeader({exportPending: boolean;canvasSent: boolean;mailCanvas: boolean;- setMailAttachmentsPortalTarget: (element: HTMLSpanElement | null) => void;isEditing: boolean;onComments: () => void;onCopyLink: () => void;@@ -297,21 +294,15 @@ function UnifiedDocumentHeader({<div className="room-document-header-actions">{mailCanvas && session ? (<span className="mr-2 text-xs text-app-muted">- <RoomDocumentSaveIndicator- alwaysVisible+ <MailCanvasStatusisEditing={isEditing}+ sent={canvasSent}session={session}/></span>) : !isWikiPage ? (presence) : null}- {mailCanvas ? (- <span- className="inline-flex items-center"- ref={setMailAttachmentsPortalTarget}- />- ) : null}{document && !isWikiPage ? (<Buttonaria-label="Share"diff --git a/apps/web/src/features/rooms/documents/use-unified-document-page-model.ts b/apps/web/src/features/rooms/documents/use-unified-document-page-model.tsindex d6c4a1dc..4217c9ea 100644--- a/apps/web/src/features/rooms/documents/use-unified-document-page-model.ts+++ b/apps/web/src/features/rooms/documents/use-unified-document-page-model.ts@@ -52,8 +52,6 @@ export function useUnifiedDocumentPageModel(sidebar?: {documentId: string;target?: string;}>();- const [mailAttachmentsPortalTarget, setMailAttachmentsPortalTarget] =- useState<HTMLSpanElement | null>(null);const canvasTarget =canvasIdentity?.documentId === documentId? canvasIdentity.target@@ -75,8 +73,6 @@ export function useUnifiedDocumentPageModel(sidebar?: {autoFocusTitle: route.autoFocusTitle,canvasSent,canvasTarget,- mailAttachmentsPortalTarget,- setMailAttachmentsPortalTarget,client,commentsOpen: panels.commentsOpen,commentsPortalTarget: panels.commentsPortalTarget,