Sources/Orgstar/FlashcardWindow.swift
27 lines · 1014 bytes
1import OrgApp
2import SwiftUI
3
4/// Window ▸ Review Flashcards: the cards due across the workspace, reviewed one at a time.
5/// Opening a card shows its heading in the main window.
6struct FlashcardWindow: View {
7 let commands: AppCommands
8 @State private var review: FlashcardReview
9 @Environment(\.openWindow) private var openWindow
10
11 init(workspace: WorkspaceModel, session: DocumentSession, commands: AppCommands) {
12 self.commands = commands
13 _review = State(initialValue: FlashcardReview(workspace: workspace, session: session))
14 }
15
16 var body: some View {
17 FlashcardReviewView(review: review) { path, offset in
18 if !commands.mainWindowOpen { openWindow(id: "main") }
19 commands.jump(path: path, offset: offset)
20 }
21 .frame(minWidth: 420, minHeight: 360)
22 .navigationTitle("Review Flashcards")
23 .toolbar {
24 Button("Start Again", systemImage: "arrow.clockwise") { Task { await review.start() } }
25 }
26 }
27}