Files
museion/Museion/ArchivePaneView.swift
T
AlexKucera 6aa31a419a feat(microblog): show Micro.blog publish status
The publish sheet flipped a draft live and remembered nothing, so
nothing on disk said a piece was out and the library could not show
it. A successful Publish now stamps `micropub_published` in the
piece's frontmatter; the row and the sheet read `published <date>`
or `draft on Micro.blog`, and a published piece's menu opens the
live post.

Sending a piece again no longer creates a second post: a piece that
remembers its post updates it in place (name and content only, so
categories set on Micro.blog survive). An image whose bytes are
unchanged rides its earlier upload through a per-piece memo. When
Micro.blog answers 404 the piece forgets both keys and the sheet
offers a fresh draft; a clear that cannot land says so instead of
claiming the link is gone.

Museion's micropub keys are dropped at the import boundary. An
imported `micropub_url` passes the format gate and would aim the
in-place update at one of the writer's own posts under their token,
so the keys are treated like `origin`: ours to set, never a foreign
file's to carry in. Publish is model-owned and trust-gates its URL
before anything is stamped.

Tests read recorded requests through an optional accessor: an
out-of-range subscript after a failed count expectation trapped the
hosted runner and reported every queued test as crashed.

+16 tests net (17 new pins in MicropubStatusTests, one retired whose
premise the in-place design voids); every new pin was watched fail
on its own guard. Rail 752/752; SwiftFormat and SwiftLint clean.
Reviews: standards + spec during the build, then a three-reviewer
finish audit. Docs: AGENTS.md bullets and learnings, GLOSSARY
terms, CHANGELOG [Unreleased], README, and the devlog.

Closes #206
2026-12-04 17:45:35 +01:00

180 lines
6.8 KiB
Swift

//
// ArchivePaneView.swift
// Museion
//
// #193: the #108 Archive pane, moved from WorkspaceView.swift
// (file-length ceiling), code unchanged (private → internal:
// WorkspaceView instantiates it cross-file now).
//
import SwiftUI
/// #108: the Archive pane — archive/ as a rail destination (prototype
/// verdict: a destination, not a library disclosure). List-only: clicking a
/// piece selects it and hops to Posts, where the editor column lives.
struct ArchivePaneView: View {
var model: PostsModel
/// Fired after a row select — the pane can't reach WorkspaceView's
/// selection itself.
let onOpenPiece: () -> Void
@State private var renamingPost: Post?
/// #108: collapsed project sections — per-view state, not persisted
/// (mirrors the library column).
@State private var collapsed: Set<String> = []
private var archivedByProject: [String: [Post]] {
Dictionary(grouping: model.posts.filter(\.isArchived), by: \.project)
}
/// #108: the prototype's toggle — click the project name (or chevron).
private func toggle(_ project: String) {
if collapsed.contains(project) {
collapsed.remove(project)
} else {
collapsed.insert(project)
}
}
var body: some View {
VStack(spacing: 0) {
// No New button — things arrive here by being moved, not created.
// r8 (argon#9, mercury#18/19): the hairline is bounded to the SAME
// fixed 720pt column the rows live in — one framed block.
PaneHeader(title: "Archive", hairlineMaxWidth: 720)
if archivedByProject.isEmpty {
emptyState
} else {
ScrollView {
LazyVStack(alignment: .leading, spacing: 4) {
// #108 audit: Finder order, matching the library's sort.
ForEach(archivedByProject.keys.sorted { $0.localizedStandardCompare($1) == .orderedAscending }, id: \.self) { project in
let pieces = archivedByProject[project] ?? []
// Same section-head shape as the library (#108
// variant B), plus the project-level way out.
// r7 (mercury#55, argon#41 — FINAL, supersedes the
// r6 D24 ladder): the content column is a FIXED
// 720pt frame (width, not maxWidth — the r6
// content-hugging bound let the pill define the
// right edge), left-anchored. TWO axes only, the
// library's r7 ladder: the head row leads at x14
// (chevron in a 14pt slot) with its label at x28 —
// the ONE indent, shared with the entry rows'
// inner text via the shared LibraryPostRow (cards
// lead at x14); the 'Unarchive Group' pill rides
// the header row's trailing edge INSIDE the frame
// (14 → 706), and the row hairlines are bounded by
// the same frame. Nothing spans past it.
HStack(alignment: .firstTextBaseline, spacing: 0) {
Image(systemName: "chevron.down")
.font(.system(size: 10, weight: .semibold))
.frame(width: 14, alignment: .leading)
.rotationEffect(.degrees(collapsed.contains(project) ? -90 : 0))
.foregroundStyle(DesignTokens.muted)
.onTapGesture {
withAnimation { toggle(project) }
}
.accessibilityLabel("Toggle \(project)")
.accessibilityHint(collapsed.contains(project) ? "Collapsed" : "Expanded")
Text(project)
.font(.system(size: 11, weight: .medium, design: DesignTokens.mono))
.kerning(0.6)
.textCase(.uppercase) // #108: display-only — the folder name keeps its case
.foregroundStyle(DesignTokens.muted) // r6: full ink — contrast final
.lineLimit(1)
.truncationMode(.tail)
.onTapGesture {
withAnimation { toggle(project) }
}
Text("· \(pieces.count)")
.font(.system(size: 11, design: DesignTokens.mono))
.foregroundStyle(DesignTokens.muted)
.padding(.leading, 8)
Spacer(minLength: 8)
// The 'New Post · Fork · Compact' language — a
// bordered mono-11 secondary pill at the
// trailing edge INSIDE the fixed 720pt frame.
// r7 (mercury#55, argon#41): relabeled
// 'Unarchive Group' — it moves the whole
// project, not one piece.
Button("Unarchive Group") {
model.unarchiveProject(project)
}
.buttonStyle(BorderedSecondaryButtonStyle(minHeight: 24))
.help("Move the whole project back to projects/")
.accessibilityLabel("Unarchive \(project)")
}
.padding(.top, 12)
.padding(.horizontal, 14)
.padding(.bottom, 2)
if !collapsed.contains(project) {
ForEach(pieces) { post in
// r7: the shared LibraryPostRow ladder —
// card leads at x14 (PRIMARY), title text
// at x28 (the one indent). The hairline is
// BOUNDED to the fixed frame: x14 → 706.
LibraryPostRow(post: post, selected: post.id == model.selectedPostID) {
model.select(post.id)
onOpenPiece()
}
.overlay(alignment: .bottom) {
Rectangle()
.fill(DesignTokens.border)
.frame(height: 1)
.padding(.horizontal, 14)
}
.contextMenu {
Button("Move Back to \(post.project)") {
model.restorePost(post)
}
Button("Rename…") { renamingPost = post }
// #114 (S4): works archived too — the piece
// stays where it is, only type + body flip.
if post.type == .outline {
Button("Convert to Post…") {
model.stageConversion(post)
}
}
Divider()
MicroblogHandOffButton(post: post)
FinderHandOffButtons(model: model, post: post)
}
}
}
}
}
// r7 (mercury#55, argon#41): the FIXED 720pt reading
// column — width, not maxWidth (the r6 content-hugging
// bound let the pill define the right edge); rows,
// hairlines, and the pill all live inside it.
// ponytail: fixed width clips on panes narrower than
// 720 — a width-floored variant if a small-window
// Archive ever matters.
.frame(width: 720, alignment: .leading)
.frame(maxWidth: .infinity, alignment: .leading)
.padding(.bottom, 12)
}
}
}
.frame(maxWidth: .infinity, maxHeight: .infinity)
.background(DesignTokens.background)
.sheet(item: $renamingPost) { post in
RenamePostSheet(post: post) { title in
model.rename(post, to: title)
}
}
}
private var emptyState: some View {
VStack(spacing: 8) {
Text("Nothing archived")
.font(.system(size: 16, weight: .semibold, design: DesignTokens.serif))
Text("Finished projects and pieces fold away here. Move things here from their context menu; they stay openable and editable.")
.font(.callout)
.foregroundStyle(DesignTokens.muted)
.multilineTextAlignment(.center)
}
.padding(38)
.frame(maxWidth: .infinity, maxHeight: .infinity)
}
}