Files
museion/Museion/PostsPaneView.swift
T
AlexKucera 765d32d4d4 refactor(workspace): finish-audit fixes — off-main scan, parser edges, dead code out
Reviewers' findings on 804b588: scan moved off MainActor (Task.detached),
PostLibrary struct folded into Post.scan, hidden dirs and symlinked dirs
now actually skipped (test de-vacuated), unterminated frontmatter no longer
leaks as the Title, quoted YAML values unquoted, leading blank line before
--- tolerated, #-only body reads untitled, persisted Home validated
isFileURL. Dead code deleted: radiusLarge, editorMinWidth, homeKey,
PaneHeader trailing slot, Settings ScrollView, PostRow fill dance.
Tests 56/56, lint 0.

[Generated by AI]
2026-10-01 13:43:25 +02:00

169 lines
4.6 KiB
Swift
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
//
// PostsPaneView.swift
// Museion
//
// #17 (S1.1): the Posts pane — library column mirroring the Home's posts/
// on disk, editor placeholder until #19–#21, mentor column (#14).
//
import SwiftUI
/// The Posts destination: the workspace's full four-column layout
/// library 232 | editor ≥420 | mentor 356 (design contract grid).
struct PostsPaneView: View {
let home: URL
/// #14: the app-scoped mentor model + the gate's winning binary (no re-probe).
var mentor: MentorSessionModel
var mentorBinaryPath: String?
/// Width budget after the rail — drives column collapse (export media queries:
/// library hides ≤1100, mentor hides ≤920).
var availableWidth: CGFloat
@State private var posts: [Post] = []
@State private var selectedPostID: String?
private var showsLibrary: Bool {
availableWidth >= 1100 - DesignTokens.railWidth
}
private var showsMentor: Bool {
availableWidth >= 920 - DesignTokens.railWidth
}
var body: some View {
HStack(spacing: 0) {
if showsLibrary {
libraryColumn
paneBorder
}
editorPlaceholder
if showsMentor {
paneBorder
mentorColumn
}
}
.task(id: home) {
// Scan off-main: .task inherits MainActor; a big Home must not freeze the UI.
posts = await Task.detached(priority: .userInitiated) { Post.scan(home: home) }.value
}
}
private var paneBorder: some View {
Rectangle()
.fill(DesignTokens.border)
.frame(width: 1)
}
// MARK: Library column
private var libraryColumn: some View {
VStack(spacing: 0) {
// New Post arrives with #18 (Post lifecycle: lazy folder + slug).
PaneHeader(title: "Posts")
if posts.isEmpty {
emptyState
} else {
ScrollView {
LazyVStack(alignment: .leading, spacing: 4) {
ForEach(Post.PassState.allCases, id: \.self) { state in
let grouped = posts.filter { $0.passState == state }
if !grouped.isEmpty {
Text(state.rawValue.uppercased())
.font(.system(size: 11, design: DesignTokens.mono))
.kerning(0.6)
.foregroundStyle(DesignTokens.muted)
.padding(.horizontal, 14)
.padding(.top, 18)
.padding(.bottom, 7)
ForEach(grouped) { post in
PostRow(post: post, selected: post.id == selectedPostID) {
selectedPostID = post.id
}
}
}
}
}
.padding(.bottom, 12)
}
}
}
.frame(width: DesignTokens.libraryWidth)
}
private var emptyState: some View {
VStack(spacing: 8) {
Text("No posts yet")
.font(.system(size: 16, weight: .semibold, design: DesignTokens.serif))
Text("Posts in this Home's posts/ folder appear here.")
.font(.callout)
.foregroundStyle(DesignTokens.muted)
.multilineTextAlignment(.center)
}
.padding(38)
.frame(maxWidth: .infinity, maxHeight: .infinity)
}
// MARK: Editor + mentor columns
private var editorPlaceholder: some View {
VStack(spacing: 10) {
if let post = posts.first(where: { $0.id == selectedPostID }) {
Text(post.title)
.font(.system(size: 16, weight: .semibold, design: DesignTokens.serif))
}
Text("The editor arrives with S1.2 (#19–#21).")
.font(.callout)
.foregroundStyle(DesignTokens.muted)
}
.frame(maxWidth: .infinity, maxHeight: .infinity)
.background(DesignTokens.surface)
}
private var mentorColumn: some View {
MentorPaneView(model: mentor, binaryPath: mentorBinaryPath)
.frame(width: DesignTokens.mentorWidth)
}
}
/// One post row per the export: title, Pass State + Origin in mono 11.
private struct PostRow: View {
let post: Post
let selected: Bool
let select: () -> Void
@State private var hover = false
var body: some View {
Button(action: select) {
VStack(alignment: .leading, spacing: 5) {
Text(post.title)
.font(.callout.weight(.semibold))
.lineLimit(1)
.truncationMode(.tail)
.frame(maxWidth: .infinity, alignment: .leading)
HStack {
Text(post.passState.rawValue)
Text(post.origin.rawValue)
}
.font(.system(size: 11, design: DesignTokens.mono))
.foregroundStyle(DesignTokens.muted)
.frame(maxWidth: .infinity, alignment: .leading)
}
.padding(10)
}
.buttonStyle(.plain)
.foregroundStyle(DesignTokens.foreground)
.background {
if selected || hover {
RoundedRectangle(cornerRadius: DesignTokens.radius)
.fill(selected ? DesignTokens.surface : DesignTokens.foreground.opacity(0.06))
.overlay(
RoundedRectangle(cornerRadius: DesignTokens.radius)
.strokeBorder(selected ? DesignTokens.border : .clear),
)
}
}
.padding(.horizontal, 8)
.onHover { hover = $0 }
.accessibilityLabel("\(post.title), \(post.passState.rawValue), origin \(post.origin.rawValue)")
}
}