feat(library): projects & archive UI — S2 (#108)
CI / ci (push) Canceled after 0s
CI / ci (push) Canceled after 0s
Variant B per the #104 prototype verdict: the library column groups pieces by project (serif lowercase heads, collapse toggle, Pass-State groups inside, 2px edge-bar selection shared with the new Archive pane via LibraryPostRow). Move to Project / Archive / Move Back / whole-project Unarchive are folder moves — post.md bytes untouched, never clobbering, ids globally unique. File ▸ New Post ⌘N and New Project… ⌥⌘N (CommandGroup, never CommandMenu per #84). Every folder move flushes pending edits first and aborts when the write failed — nothing moves without its text. Project membership and the archived-refusal derive from freshly resolved disk paths, never the scan snapshot. Slug and project-name comparisons fold through one canonical key (NFC + lowercase). Two reviewer fanouts this session; their findings are all fixed or visibly parked. 144/144 tests green (run twice), swiftformat/swiftlint clean. Closes #108
This commit is contained in:
1 parent
9da3a07f4a
commit
e55747e7fe
15 files changed
+1205
-68
No files matched your search
+183
-37
@@ -6,6 +6,9 @@
|
||||
// projects/ (and archive/) on disk. #18: lifecycle — New Post draft, ⌘S first-write/save, rename,
|
||||
// trash. #19: the TextKit2 editor core (PostEditorView) replaces the stub;
|
||||
// mentor column (#14).
|
||||
// #108 (variant B, ref/prototypes/wf104-library-ui-prototype.html): sections
|
||||
// per project (serif-15 head + mono count), Pass-State groups inside, and a
|
||||
// 2px accent edge bar on the selected row.
|
||||
//
|
||||
|
||||
import SwiftUI
|
||||
@@ -124,12 +127,23 @@ struct PostsPaneView: View {
|
||||
}
|
||||
|
||||
/// #21: the library column, shared by the unfocused layout and the focus-mode
|
||||
/// left reveal overlay — one implementation, both surfaces. Owns the rename
|
||||
/// sheet + context menu (they travel with the post rows).
|
||||
/// left reveal overlay — one implementation, both surfaces. Owns the rename +
|
||||
/// move sheets and the context menu (they travel with the post rows).
|
||||
/// #108 variant B: sections per project, Pass-State groups inside.
|
||||
struct PostsLibraryColumn: View {
|
||||
let home: URL
|
||||
var model: PostsModel
|
||||
@State private var renamingPost: Post?
|
||||
@State private var movingPost: Post?
|
||||
/// #108: collapsed project sections — per-view state, not persisted (a
|
||||
/// fresh open shows everything; the prototype behaved the same).
|
||||
@State private var collapsed: Set<String> = []
|
||||
|
||||
/// Non-archived pieces keyed by project (scan order = title order holds
|
||||
/// inside each group — filter preserves it).
|
||||
private var activeByProject: [String: [Post]] {
|
||||
Dictionary(grouping: model.posts.filter { !$0.isArchived }, by: \.project)
|
||||
}
|
||||
|
||||
var body: some View {
|
||||
VStack(spacing: 0) {
|
||||
@@ -144,32 +158,51 @@ struct PostsLibraryColumn: View {
|
||||
.help("New Post")
|
||||
.accessibilityLabel("New Post")
|
||||
}
|
||||
if model.posts.isEmpty {
|
||||
if activeByProject.isEmpty {
|
||||
emptyState
|
||||
} else {
|
||||
ScrollView {
|
||||
LazyVStack(alignment: .leading, spacing: 4) {
|
||||
ForEach(Post.PassState.allCases, id: \.self) { state in
|
||||
let grouped = model.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 == model.selectedPostID) {
|
||||
model.select(post.id, home: home)
|
||||
}
|
||||
.contextMenu {
|
||||
Button("Rename…") { renamingPost = post }
|
||||
Button("Move to Trash", role: .destructive) {
|
||||
model.trash(post, home: home)
|
||||
}
|
||||
// #108 audit: Finder order (scan's own sort), not Unicode-scalar
|
||||
// order — the heads render lowercased, "Beta" must not read before "apple".
|
||||
ForEach(activeByProject.keys.sorted { $0.localizedStandardCompare($1) == .orderedAscending }, id: \.self) { project in
|
||||
let pieces = activeByProject[project] ?? []
|
||||
// #108: the head is the prototype's toggle — click
|
||||
// collapses the project's pieces (chevron rotates).
|
||||
Button {
|
||||
withAnimation {
|
||||
if collapsed.contains(project) {
|
||||
collapsed.remove(project)
|
||||
} else {
|
||||
collapsed.insert(project)
|
||||
}
|
||||
}
|
||||
} label: {
|
||||
HStack(alignment: .firstTextBaseline, spacing: 8) {
|
||||
Image(systemName: "chevron.down")
|
||||
.font(.system(size: 9, weight: .semibold))
|
||||
.rotationEffect(.degrees(collapsed.contains(project) ? -90 : 0))
|
||||
.foregroundStyle(DesignTokens.muted)
|
||||
Text(project)
|
||||
.font(.system(size: 15, weight: .semibold, design: DesignTokens.serif))
|
||||
.textCase(.lowercase) // #108: display-only — the folder name keeps its case
|
||||
.lineLimit(1)
|
||||
.truncationMode(.tail)
|
||||
Text("· \(pieces.count)")
|
||||
.font(.system(size: 11, design: DesignTokens.mono))
|
||||
.foregroundStyle(DesignTokens.muted)
|
||||
Spacer(minLength: 0)
|
||||
}
|
||||
}
|
||||
.buttonStyle(.plain)
|
||||
.foregroundStyle(DesignTokens.foreground)
|
||||
.accessibilityLabel("\(project), \(pieces.count) pieces")
|
||||
.accessibilityHint(collapsed.contains(project) ? "Collapsed" : "Expanded")
|
||||
.padding(.top, 16)
|
||||
.padding(.horizontal, 14)
|
||||
.padding(.bottom, 6)
|
||||
if !collapsed.contains(project) {
|
||||
passStateGroups(pieces)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -183,6 +216,47 @@ struct PostsLibraryColumn: View {
|
||||
model.rename(post, to: title, home: home)
|
||||
}
|
||||
}
|
||||
.sheet(item: $movingPost) { post in
|
||||
// #108 audit 2: disk-derived list, localized-sorted — same order
|
||||
// the library renders (Unicode-scalar sort split them), and it
|
||||
// includes empty projects (a fresh New Project has no pieces yet —
|
||||
// it must already be a move target).
|
||||
MoveToProjectSheet(post: post, projects: model.moveTargets(home: home)) { project in
|
||||
model.moveToProject(post, project: project, home: home)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// Pass-State groups inside one project (`.vB .group-label`: smaller,
|
||||
/// softer, indented under the section head).
|
||||
private func passStateGroups(_ pieces: [Post]) -> some View {
|
||||
ForEach(Post.PassState.allCases, id: \.self) { state in
|
||||
let grouped = pieces.filter { $0.passState == state }
|
||||
if !grouped.isEmpty {
|
||||
Text(state.rawValue.uppercased())
|
||||
.font(.system(size: 10, design: DesignTokens.mono))
|
||||
.kerning(0.6)
|
||||
.foregroundStyle(DesignTokens.muted.opacity(0.8))
|
||||
.padding(.horizontal, 22)
|
||||
.padding(.top, 8)
|
||||
.padding(.bottom, 5)
|
||||
ForEach(grouped) { post in
|
||||
LibraryPostRow(post: post, selected: post.id == model.selectedPostID) {
|
||||
model.select(post.id, home: home)
|
||||
}
|
||||
.contextMenu {
|
||||
Button("Rename…") { renamingPost = post }
|
||||
Button("Move to Project…") { movingPost = post }
|
||||
Button("Move to Archive") {
|
||||
model.archivePost(post, home: home)
|
||||
}
|
||||
Button("Move to Trash", role: .destructive) {
|
||||
model.trash(post, home: home)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private var emptyState: some View {
|
||||
@@ -199,8 +273,54 @@ struct PostsLibraryColumn: View {
|
||||
}
|
||||
}
|
||||
|
||||
/// #108: Move to Project ask — radio list of the non-archived projects,
|
||||
/// default = the piece's current project. Matches RenamePostSheet's shape.
|
||||
struct MoveToProjectSheet: View {
|
||||
let post: Post
|
||||
let projects: [String]
|
||||
let move: (String) -> Void
|
||||
@Environment(\.dismiss) private var dismiss
|
||||
@State private var target: String
|
||||
|
||||
init(post: Post, projects: [String], move: @escaping (String) -> Void) {
|
||||
self.post = post
|
||||
self.projects = projects
|
||||
self.move = move
|
||||
_target = State(initialValue: post.project)
|
||||
}
|
||||
|
||||
var body: some View {
|
||||
VStack(alignment: .leading, spacing: 12) {
|
||||
Text("Move to Project")
|
||||
.font(.system(size: 15, weight: .semibold, design: DesignTokens.serif))
|
||||
Text("“\(post.title)” moves into the chosen project. The file stays post.md.")
|
||||
.font(.callout)
|
||||
.foregroundStyle(DesignTokens.muted)
|
||||
Picker("Project", selection: $target) {
|
||||
ForEach(projects, id: \.self) { name in
|
||||
Text(name).tag(name)
|
||||
}
|
||||
}
|
||||
.pickerStyle(.radioGroup)
|
||||
HStack {
|
||||
Spacer()
|
||||
Button("Cancel", role: .cancel) { dismiss() }
|
||||
.keyboardShortcut(.cancelAction)
|
||||
Button("Move") {
|
||||
move(target)
|
||||
dismiss()
|
||||
}
|
||||
.keyboardShortcut(.defaultAction)
|
||||
.disabled(target == post.project)
|
||||
}
|
||||
}
|
||||
.padding(20)
|
||||
.frame(width: 360)
|
||||
}
|
||||
}
|
||||
|
||||
/// #60: Explicit Rename dialog — asks the new Title (not a slug).
|
||||
private struct RenamePostSheet: View {
|
||||
struct RenamePostSheet: View {
|
||||
let rename: (String) -> Void
|
||||
@Environment(\.dismiss) private var dismiss
|
||||
@State private var title: String
|
||||
@@ -242,44 +362,70 @@ private struct RenamePostSheet: View {
|
||||
}
|
||||
|
||||
/// One post row per the export: title, Pass State + Origin in mono 11.
|
||||
private struct PostRow: View {
|
||||
/// #108 (variant B): 2px accent edge bar on the leading side when selected
|
||||
/// (`.vB .post-row[aria-current] { border-left-color: var(--accent) }`,
|
||||
/// radius 0 8 8 0), and a muted ✳ suffix on outline pieces. Internal: the
|
||||
/// Archive pane reuses it.
|
||||
struct LibraryPostRow: 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)
|
||||
// `.vB .post-row { border-left: 2px solid transparent;
|
||||
// border-radius: 0 8px 8px 0 }` — every row: leading corners square
|
||||
// (the 2px strip below), trailing rounded 8. Only the strip's COLOR
|
||||
// changes on selection.
|
||||
let shape = UnevenRoundedRectangle(cornerRadii: .init(bottomTrailing: 8, topTrailing: 8))
|
||||
return Button(action: select) {
|
||||
HStack(spacing: 0) {
|
||||
// `.vB .post-row { border-left: 2px solid transparent }` —
|
||||
// the leading strip is always 2px wide so hover/selection
|
||||
// never shifts the title.
|
||||
Rectangle()
|
||||
.fill(selected ? DesignTokens.accent : .clear)
|
||||
.frame(width: 2)
|
||||
VStack(alignment: .leading, spacing: 5) {
|
||||
HStack(alignment: .firstTextBaseline, spacing: 0) {
|
||||
Text(post.title)
|
||||
if post.type == .outline {
|
||||
Text(" ✳")
|
||||
.foregroundStyle(DesignTokens.muted)
|
||||
}
|
||||
}
|
||||
.font(.callout.weight(.semibold))
|
||||
.lineLimit(1)
|
||||
.truncationMode(.tail)
|
||||
.frame(maxWidth: .infinity, alignment: .leading)
|
||||
HStack {
|
||||
Text(post.passState.rawValue)
|
||||
Text(post.origin.rawValue)
|
||||
HStack {
|
||||
Text(post.passState.rawValue)
|
||||
Text(post.origin.rawValue)
|
||||
}
|
||||
.font(.system(size: 11, design: DesignTokens.mono))
|
||||
.foregroundStyle(DesignTokens.muted)
|
||||
.frame(maxWidth: .infinity, alignment: .leading)
|
||||
}
|
||||
.font(.system(size: 11, design: DesignTokens.mono))
|
||||
.foregroundStyle(DesignTokens.muted)
|
||||
.frame(maxWidth: .infinity, alignment: .leading)
|
||||
.padding(10)
|
||||
}
|
||||
.padding(10)
|
||||
.clipShape(shape)
|
||||
}
|
||||
.buttonStyle(.plain)
|
||||
.foregroundStyle(DesignTokens.foreground)
|
||||
.background {
|
||||
if selected || hover {
|
||||
RoundedRectangle(cornerRadius: DesignTokens.radius)
|
||||
shape
|
||||
.fill(selected ? DesignTokens.surface : DesignTokens.foreground.opacity(0.06))
|
||||
.overlay(
|
||||
RoundedRectangle(cornerRadius: DesignTokens.radius)
|
||||
.strokeBorder(selected ? DesignTokens.border : .clear),
|
||||
shape.strokeBorder(selected ? DesignTokens.border : .clear),
|
||||
)
|
||||
}
|
||||
}
|
||||
.padding(.horizontal, 8)
|
||||
.onHover { hover = $0 }
|
||||
// help sits on the row — the ✳ span isn't individually hoverable in
|
||||
// SwiftUI (prototype: `title="outline"` on the star).
|
||||
.help(post.type == .outline ? "\(post.title) — outline" : post.title)
|
||||
.accessibilityLabel("\(post.title), \(post.passState.rawValue), origin \(post.origin.rawValue)")
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user