Files
museion/Museion/WorkspaceChrome.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

139 lines
4.5 KiB
Swift

//
// WorkspaceChrome.swift
// Museion
//
// #193: the shared workspace chrome, moved from WorkspaceView.swift
// (file-length ceiling) — SelectedRowStrip, BorderedSecondaryButtonStyle,
// PaneHeader; every pane reuses them, code unchanged. #205 adds
// FinderHandOffButtons, #206 MicroblogHandOffButton (both born here).
//
import AppKit
import SwiftUI
/// r6 (mercury#49/52, argon#13): the shared selected-row strip — a 2pt
/// accent capsule with radius-1 rounded ends, vertically inset 6pt from
/// the row's edges so it sits INSIDE the card/fill (Posts library rows,
/// Settings sidebar rows). Callers toggle it via opacity so the 2pt
/// reservation keeps layout constant.
struct SelectedRowStrip: View {
var body: some View {
RoundedRectangle(cornerRadius: 1)
.fill(DesignTokens.accent)
.frame(width: 2)
.padding(.vertical, 6)
}
}
/// ui-polish r2: the app's bordered secondary button — mono-11 ink on a
/// surface fill with a #E8E5DF hairline (Archive's Unarchive, Settings'
/// Choose…). 36pt tall by default — a real hit target, not a text-size
/// pill; pass a smaller `minHeight` where the row is compact.
struct BorderedSecondaryButtonStyle: ButtonStyle {
var minHeight: CGFloat = 36
func makeBody(configuration: Configuration) -> some View {
configuration.label
.font(.system(size: 11, design: DesignTokens.mono))
.foregroundStyle(DesignTokens.foreground)
.padding(.horizontal, 12)
.frame(minHeight: minHeight)
.background(
RoundedRectangle(cornerRadius: 8)
.fill(DesignTokens.surface)
.overlay(
RoundedRectangle(cornerRadius: 8)
.strokeBorder(DesignTokens.border),
),
)
.opacity(configuration.isPressed ? 0.7 : 1)
}
}
/// Pane-head row per the export (52pt, serif 15 semibold title, bottom border).
/// Trailing slot carries #18's New Post button (export `.pane-head .icon-btn`).
struct PaneHeader<Trailing: View>: View {
let title: String
/// Leading inset of the title row. Export default 14; the Learnings pane
/// passes 26 so its title shares one leading edge with headings + rows.
var titleInset: CGFloat = 14
/// r8 (argon#9, mercury#18/19 — convergent): when set, the bottom
/// hairline is bounded to the same column the pane's content sits in
/// (Archive/Learnings' 720pt reading column) — title, hairline, and
/// content read as one framed block instead of a full-width rule over
/// a bounded column. nil = full width (every other pane's default).
var hairlineMaxWidth: CGFloat?
@ViewBuilder var trailing: () -> Trailing
init(
title: String,
titleInset: CGFloat = 14,
hairlineMaxWidth: CGFloat? = nil,
@ViewBuilder trailing: @escaping () -> Trailing = { EmptyView() },
) {
self.title = title
self.titleInset = titleInset
self.hairlineMaxWidth = hairlineMaxWidth
self.trailing = trailing
}
var body: some View {
VStack(spacing: 0) {
HStack {
Text(title)
.font(.system(size: 15, weight: .semibold, design: DesignTokens.serif))
Spacer()
trailing()
}
.padding(.horizontal, titleInset)
.frame(minHeight: 52)
Rectangle()
.fill(DesignTokens.border)
.frame(height: 1)
// r8: the bound shares the content column's leading edge
// (x0) and width — leading-aligned, never centered.
.frame(maxWidth: hairlineMaxWidth ?? .infinity, alignment: .leading)
}
}
}
/// #205: the row menus' Finder hand-off — Reveal in Finder + Copy Path,
/// one fragment for every surface that lists pieces (the library column,
/// the Archive pane). Both act on `model.fileURL(for:)` — the resolved
/// `post.md`; a nil URL (the piece is gone) no-ops.
struct FinderHandOffButtons: View {
let model: PostsModel
let post: Post
var body: some View {
Button("Reveal in Finder") {
if let url = model.fileURL(for: post) {
NSWorkspace.shared.activateFileViewerSelecting([url])
}
}
Button("Copy Path") {
if let url = model.fileURL(for: post) {
NSPasteboard.general.clearContents()
NSPasteboard.general.setString(url.path, forType: .string)
}
}
}
}
/// #206: the row menus' Micro.blog hand-off — Open on Micro.blog, for a
/// piece that is published (a draft's final URL does not exist yet on
/// their side, so a draft shows no entry; neither does a never-sent
/// piece). The URL is the piece's remembered `micropub_url`, already
/// trust-gated at the scan.
struct MicroblogHandOffButton: View {
let post: Post
var body: some View {
if post.micropubPublished != nil, let url = post.micropubURL.flatMap({ URL(string: $0) }) {
Button("Open on Micro.blog") {
NSWorkspace.shared.open(url)
}
}
}
}