Files
Outpost/Outpost/Features/Collections/DocumentPresentSheet.swift
T
Puranjay Savar Mattas f6852897b9 fix(collections): document context menu targeting + off-main AppKit calls
Sidebar document rows lived inside the collection's single List row —
on macOS, a List row's own context menu wins over any nested
.contextMenu deeper in that row's content, so right-clicking a
document always showed the collection's menu. Swapped List for a
plain ScrollView/LazyVStack (every row already does its own selection
highlighting, so List wasn't buying anything here).

Also pins the new document-action views to @MainActor: Download/Print
call NSSavePanel/NSPrintOperation/NSPasteboard after an await, and
without a fixed actor those functions could resume on a background
executor — off-main AppKit calls, which is what was producing the
ViewBridge/nw_connection console spam.
2026-08-14 02:23:42 +01:00

84 lines
2.8 KiB
Swift

#if os(macOS)
import SwiftUI
import MarkdownEngine
import OutlineKit
/// Distraction-free reading view — no toolbar/sidebar chrome, larger type.
/// Presentation is just a bigger render of the same markdown, not a real
/// slide-by-slide deck (Outline's own "Present" isn't slide-based either).
@MainActor
struct DocumentPresentSheet: View {
@Environment(\.dismiss) private var dismiss
let apiClient: OutlineAPIClient
let document: OutlineDocument
@State private var text: String
@State private var isLoading = false
@State private var errorMessage: String?
init(apiClient: OutlineAPIClient, document: OutlineDocument) {
self.apiClient = apiClient
self.document = document
_text = State(initialValue: document.text)
}
var body: some View {
ZStack(alignment: .topTrailing) {
if isLoading && text.isEmpty {
ProgressView().frame(maxWidth: .infinity, maxHeight: .infinity)
} else if let errorMessage {
ContentUnavailableView {
Label("Couldn't Load Document", systemImage: "exclamationmark.triangle")
} description: {
Text(errorMessage)
}
} else {
ScrollView {
VStack(alignment: .leading) {
if let emoji = document.emoji {
Text(emoji).font(.system(size: 48))
}
Text(document.title.isEmpty ? "Untitled" : document.title)
.font(.system(size: 34, weight: .bold))
.padding(.bottom, 8)
NativeTextViewWrapper(
text: $text,
configuration: .init(heightBehavior: .fitsContent),
isEditable: false
)
.font(.system(size: 18))
}
.frame(maxWidth: 720, alignment: .leading)
.padding(48)
.frame(maxWidth: .infinity)
}
}
Button {
dismiss()
} label: {
Image(systemName: "xmark.circle.fill")
.font(.title2)
.foregroundStyle(.secondary)
}
.buttonStyle(.plain)
.padding(20)
}
.frame(minWidth: 800, minHeight: 600)
.background(.background)
.task { await load() }
}
private func load() async {
isLoading = true
defer { isLoading = false }
do {
text = try await apiClient.documentInfo(id: document.id).text
} catch {
errorMessage = outlineErrorMessage(error, fallback: "Couldn't load this document.")
}
}
}
#endif