diff --git a/MiniSlice.swiftpm/Sources/MiniSliceApp.swift b/MiniSlice.swiftpm/Sources/MiniSliceApp.swift index b8382d0..6eb8802 100644 --- a/MiniSlice.swiftpm/Sources/MiniSliceApp.swift +++ b/MiniSlice.swiftpm/Sources/MiniSliceApp.swift @@ -6,8 +6,8 @@ private var editor = EditorViewModel(preview: preview) @main struct MiniSliceApp: App { var body: some Scene { - WindowGroup { - ContentView() + DocumentGroup(newDocument: RecipeDocument()) { configuration in + ContentView(document: configuration.$document) .environmentObject(preview) .environmentObject(editor) } diff --git a/MiniSlice.swiftpm/Sources/View/ContentView.swift b/MiniSlice.swiftpm/Sources/View/ContentView.swift index cec29bb..fbdf935 100644 --- a/MiniSlice.swiftpm/Sources/View/ContentView.swift +++ b/MiniSlice.swiftpm/Sources/View/ContentView.swift @@ -1,10 +1,20 @@ import SwiftUI struct ContentView: View { + @Binding var document: RecipeDocument + @EnvironmentObject private var editor: EditorViewModel + var body: some View { HStack { EditorView() PreviewView() } + .onAppear { + // TODO: Is this sufficient? The user should be able to open documents, which might not cause the ContentView to 're-appear' but only update? We don't listen to document changes directly to prevent a listener cycle. + editor.rawRecipe = document.raw + } + .onChange(of: editor.rawRecipe) { raw in + document.raw = raw + } } }