// // NewPostFromSessionSheet.swift // Museion // // #30 (S2.7): the New Post from Session ask — extracted from // SessionsPaneView (Round-1 polish: the pane file rides its 400-line // lint ceiling). Behavior unchanged. // import SwiftUI /// #30 (S2.7): the New Post from Session ask — the draft candidate /// (the session's last mentor reply) prefills and stays editable. /// Confirm materializes the piece stamped `origin: ai` — never /// stats-eligible — and opens it in Posts; Cancel writes nothing. /// The error line is SHEET-LOCAL state: it dies with the presentation, /// so a re-opened ask never shows a stale refusal. struct NewPostFromSessionSheet: View { @Binding var draft: String /// The confirm's failure reason — a failed write keeps the sheet up, /// draft intact; dismissal itself is the cancel. @State private var createError: String? let create: () -> String? var body: some View { VStack(alignment: .leading, spacing: 12) { Text("New Post from Session") .font(.system(size: 15, weight: .semibold, design: DesignTokens.serif)) Text( "The draft starts from the session's last mentor reply. It lands in your library stamped origin: ai — never counted as your writing.", ) .font(.callout) .foregroundStyle(DesignTokens.muted) TextEditor(text: $draft) .font(.system(size: 13, design: DesignTokens.serif)) .frame(width: 380, height: 160) .overlay( RoundedRectangle(cornerRadius: DesignTokens.radius) .strokeBorder(DesignTokens.border), ) if let createError { Text(createError) .font(.system(size: 11, design: DesignTokens.mono)) .foregroundStyle(.orange) } HStack { Spacer() // Dismissal itself is the cancel (binding set(false) → // sessionDraft = nil) — Esc and ⌘. land here too. Button("Cancel", role: .cancel) {} .keyboardShortcut(.cancelAction) Button("Create Post", action: confirm) .keyboardShortcut(.defaultAction) .disabled(draft.trimmingCharacters(in: .whitespacesAndNewlines).isEmpty) } } .padding(20) .frame(width: 420) } /// No dismiss() here — success closes the sheet via the pane's /// `sessionDraft = nil` (the binding); failure keeps it up with the /// inline reason and the edited draft intact. private func confirm() { createError = create() } }