import AppKit import SwiftUI import ShotdeckCore /// "Past submissions…" window: every retained session and what was sent for it. /// Read-and-reveal only — keeping/starting sessions is driven from the menu rows /// (and the button on the current-session row below). struct PastSubmissionsView: View { @Environment(AppModel.self) private var model var body: some View { VStack(alignment: .leading, spacing: 8) { currentSessionRow Divider() if model.pastSessions.isEmpty { Text("No past sessions yet. Use “Start new session” to keep the current captures.") .font(.caption) .foregroundStyle(.secondary) .fixedSize(horizontal: false, vertical: true) } else { ScrollView { VStack(alignment: .leading, spacing: 6) { ForEach(model.pastSessions) { session in PastSessionRow(session: session) } } } .frame(maxHeight: 320) } Divider() footer } .padding(10) .frame(width: 420, alignment: .leading) .controlSize(.small) .task { if let problem = await model.reloadFromSpool() { model.setStatus(problem) } } } private var currentSessionRow: some View { HStack(alignment: .center, spacing: 8) { VStack(alignment: .leading, spacing: 2) { Text("Current session") .font(.caption) .foregroundStyle(.secondary) Text(currentSessionSummary) .fixedSize(horizontal: false, vertical: true) } Spacer(minLength: 8) Button("Start new session") { Task { await model.startNewSession() } } .disabled(!model.canStartNewSession) .help("Keeps these captures as a past session and starts a fresh one.") } } private var currentSessionSummary: String { let count = model.session.captures.count if count == 0 { return "Nothing captured yet." } return "\(count) capture\(count == 1 ? "" : "s") · started \(DubaiTime.stamp(model.session.createdAt))" } private var footer: some View { HStack(spacing: 8) { Text("Sessions are kept in one folder — the newest \(SpoolStore.defaultRetainedSessionCount).") .font(.caption) .foregroundStyle(.secondary) .fixedSize(horizontal: false, vertical: true) Spacer(minLength: 8) Button("Open sessions folder") { model.openSessionsFolder() } } } } private struct PastSessionRow: View { @Environment(AppModel.self) private var model let session: CaptureSession var body: some View { HStack(alignment: .center, spacing: 8) { VStack(alignment: .leading, spacing: 2) { Text(DubaiTime.stamp(session.createdAt)) Text(submissionLabel) .font(.caption) .foregroundStyle(session.pdfFileName == nil ? .secondary : .primary) .lineLimit(1) } Spacer(minLength: 8) Button("PDF") { model.revealSentPDF(session) } .disabled(model.sentPDFURL(for: session) == nil) .help(session.pdfFileName.map { "Reveal \($0)" } ?? "This session was never sent.") Button("Captures") { model.revealSessionCaptures(session) } .help("Reveal this session's screenshots") } } private var submissionLabel: String { let pages = "\(session.captures.count) page\(session.captures.count == 1 ? "" : "s")" guard let name = session.pdfFileName else { return "\(pages) · not sent" } return "\(pages) · sent as \(name)" } } extension AppModel: SubmissionsWindowPresenting { private static var submissionsWindowController: NSWindowController? public func presentSubmissionsWindow() { if let existing = Self.submissionsWindowController { existing.window?.makeKeyAndOrderFront(nil) NSApp.activate() return } let hosting = NSHostingController(rootView: PastSubmissionsView().environment(self)) let window = NSWindow(contentViewController: hosting) window.title = "Redline — Past submissions" window.styleMask = [.titled, .closable] window.isReleasedWhenClosed = false window.center() let controller = NSWindowController(window: window) Self.submissionsWindowController = controller controller.showWindow(nil) NSApp.activate() } }