Files
museion/Museion/PromoteAskSheet.swift
T
AlexKucera 06283b6287
CI / ci (push) Canceled after 0s
refactor(posts): route every library write through the write rail (#179)
One internal seam (PostsModelRail.swift) now pairs every library
verb store write with exactly one library rescan and owns the error
strip: saveDraft, newPostFromSession, rename, trash, createProject,
moveToProject, archivePost, restorePost, unarchiveProject,
importFiles, convertToPost, and runPass pass-state advance (12 sites
on this base; the pass snapshot/stats writes, the publish stamp, and
the editor flush stay outside by design).

The model owns the Home: boundHome is set by bind() alone (app
construction + Settings repoint); every public verb lost its home:
parameter (create post/outline/session-born, rename, move, archive,
restore, trash, convert, project creation, import, select, cards,
passes, blind read, publish).

The three rail entries are railWrite/railWriteReturningReason/
railWriteKeepingStrip — deliberately NOT overloads: a shared base
name let unlabeled trailing-closure calls resolve into the labeled
non-generic entry (Swift binds trailing closures to labeled first
parameters), silently bypassing the strip and the pairing.

Views + 11 test files swept to the homeless signatures (160 sites).
RED suite green: 3/3. Full unit suite: 654/654. Fixes #179
2026-11-10 03:05:48 +01:00

119 lines
3.6 KiB
Swift

//
// PromoteAskSheet.swift
// Museion
//
// #26 (S4.1): the promotion ask, extracted from FixCardsWindow.swift
// (file was past its length ceiling; OutlineRowTextView precedent).
//
import SwiftUI
/// #26 (S4.1): the promotion ask — ONE explicit confirmation writes ONE
/// plain markdown Learning (never a repetition counter; the store refuses
/// the second). The design contract's #promoteDialog: title, the consulted-
/// on-future-Passes body, a learning preview, Cancel/Promote. Promote is
/// the sheet's only write path; Cancel writes nothing; a refusal shows its
/// reason with the buttons kept (ApplyAskSheet posture).
struct PromoteAskSheet: View {
let card: FixCardStore.StoredFixCard
let posts: PostsModel
let home: URL
@Environment(\.dismiss) private var dismiss
@State private var refusal: String?
var body: some View {
VStack(alignment: .leading, spacing: 12) {
ScrollView {
VStack(alignment: .leading, spacing: 12) {
Text("Promote to Learnings?")
.font(.headline)
Text(
"This pattern will be consulted on future Passes for \(typePlural). "
+ "Museion will write one plain markdown Learning.",
)
.font(.callout)
// The Learning preview: pattern, problem, provenance —
// the file the confirm writes.
VStack(alignment: .leading, spacing: 6) {
Text(card.pattern)
.font(.callout.weight(.semibold))
if !card.problem.isEmpty {
Text(card.problem).font(.callout)
}
// The preview shows what lands: the diagnostic
// and, on demonstration lanes, the example the
// Learning will carry.
if !card.diagnosticQuestion.isEmpty {
Text(card.diagnosticQuestion).font(.callout)
}
if card.lane == .demonstration, !card.fix.isEmpty {
Text("Example: \(card.fix)").font(.callout)
}
if !provenanceLine.isEmpty {
Text(provenanceLine)
.font(.system(size: 11, design: DesignTokens.mono))
.foregroundStyle(DesignTokens.muted)
}
}
.padding(8)
.frame(maxWidth: .infinity, alignment: .leading)
.background(.quaternary.opacity(0.3), in: RoundedRectangle(cornerRadius: 6))
if let refusal {
Text(refusal)
.font(.callout)
.foregroundStyle(.orange)
}
}
.frame(maxWidth: .infinity, alignment: .leading)
}
HStack(spacing: 8) {
Button("Promote") { promote() }
.buttonStyle(.borderedProminent)
Button("Cancel") { dismiss() }
.buttonStyle(.bordered)
}
.frame(maxWidth: .infinity, alignment: .trailing)
}
.padding(16)
.frame(width: 320, alignment: .leading)
}
/// The open piece's content type, pluralized; "pieces" when unknown.
private var typePlural: String {
guard let id = posts.session?.postID,
let type = posts.posts.first(where: { $0.id == id })?.type
else { return "pieces" }
return type == .post ? "Posts" : "Outlines"
}
/// "<piece title> · Pass N · <engine> · <date>" — provenance.piece is
/// the piece id, resolved through the model's title lookup (fallback:
/// the id); missing parts drop out, date falls back to promotedAt.
private var provenanceLine: String {
var parts: [String] = []
if let pieceID = card.provenance?.piece {
parts.append(posts.title(of: pieceID))
}
if let pass = card.provenance?.pass {
parts.append("Pass \(pass)")
}
if let engine = card.provenance?.engine {
parts.append(engine)
}
if let date = card.provenance?.date {
parts.append(date)
}
return parts.joined(separator: " · ")
}
private func promote() {
switch posts.promoteCard(card) {
case .promoted:
dismiss()
case let .refused(reason):
refusal = reason
}
}
}