Skip to content

Commit

Permalink
removed viewmodel from noteView
Browse files Browse the repository at this point in the history
  • Loading branch information
ptrcc committed Jan 13, 2024
1 parent 1a5e1b0 commit fe2852f
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 15 deletions.
1 change: 0 additions & 1 deletion notes-ios/notes_iosApp.swift
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ struct notes_iosApp: App {

var viewModel = ViewModel(
repo: NotesRepositoryImpl()

)

var body: some Scene {
Expand Down
11 changes: 6 additions & 5 deletions notes-ios/ui/components/NoteList.swift
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,15 @@ struct NoteList: View {

@ObservedObject var viewModel: ViewModel

init(viewModel: ViewModel) {
self.viewModel = viewModel
}

var body: some View {
List($viewModel.notes) { $item in
NavigationLink {
NoteView(note: $item, viewModel: viewModel)
NoteView(note: $item)
.onDisappear {
Task {
await viewModel.persist()
}
}
} label: {
NoteRow(note: item)
.swipeActions(allowsFullSwipe: false) {
Expand Down
11 changes: 2 additions & 9 deletions notes-ios/ui/views/NoteView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,7 @@ import PhotosUI

struct NoteView: View {
@Binding var note: Note
@ObservedObject var viewModel: ViewModel


@State private var selectedPhotos = [PhotosPickerItem]()
@State private var selectedImage: UIImage?

Expand Down Expand Up @@ -62,12 +61,6 @@ struct NoteView: View {
}
}
}
.onDisappear {
Task {
print("PERSIST IN ON DISAPPEAR")
await self.viewModel.persist()
}
}
.toolbar {
ToolbarItem {
ShareLink(item: note.text)
Expand All @@ -93,7 +86,7 @@ struct NoteView: View {
case .success(let result):
print("Successfully retrieved quote: \(result[0].quote)")
var q = result[0].description
await viewModel.persist()
note.text = note.text + "\n\n" + q
case .failure(let error):
print("Error retrieving a quote: \(error)")
}
Expand Down

0 comments on commit fe2852f

Please sign in to comment.