This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Foundation | |
class NoteListViewModel: ObservableObject { | |
@Published var notes = [ | |
Note.init(id: "0", title: "Note 0", createdTime: .init(), content: "Content of note 0", userId: "0", deleted: nil, parentId: nil, tags: ["tag 1"]), | |
Note.init(id: "1", title: "Note 1", createdTime: .init(), content: "Content of note 1", userId: "0", deleted: nil, parentId: nil, tags: ["Tag 1"]) | |
] | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Resolver | |
import SwiftUI | |
struct NoteListView: View { | |
@ObservedObject var vm = NoteListViewModel() | |
var body: some View { | |
NavigationView { | |
list | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var body: some View { | |
Group { | |
if (authenticationService.user == nil) { | |
LoginView() | |
} else { | |
NoteListView() | |
} | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import SwiftUI | |
import UIKit | |
struct NoteDetailView: View { | |
@State var note: Note | |
var body: some View { | |
ScrollView { | |
VStack { | |
TextField("Title", text: $note.title) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import SwiftUI | |
/// SwiftUI doesn't support multiline text fields, this is workaround using UIKiit | |
/// From: https://stackoverflow.com/questions/56471973/how-do-i-create-a-multiline-textfield-in-swiftui | |
/// Copyrights Asperi | |
fileprivate struct UITextViewWrapper: UIViewRepresentable { | |
typealias UIViewType = UITextView | |
@Binding var text: String | |
@Binding var calculatedHeight: CGFloat |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
VStack { | |
NavigationLink(destination: NoteDetailView(note: note)){ | |
NoteRow(note: note) | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Foundation | |
extension NoteDetailView { | |
class ViewModel: ObservableObject { | |
@Published var note: Note | |
init(note: Note) { | |
self.note = note | |
} | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Resolver | |
import SwiftUI | |
struct NoteListView: View { | |
@ObservedObject var vm = NoteListViewModel() | |
var body: some View { | |
NavigationView { | |
list | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Foundation | |
class NoteListViewModel: ObservableObject { | |
@Published var notes = [ | |
NoteDetailView.ViewModel.init(note: Note.init(id: "0", title: "Note 0", createdTime: .init(), content: "Content of note 0", userId: "0", deleted: nil, parentId: nil, tags: ["tag 1"])), | |
NoteDetailView.ViewModel.init(note: Note.init(id: "1", title: "Note 1", createdTime: .init(), content: "Content of note 1", userId: "0", deleted: nil, parentId: nil, tags: ["Tag 1"])) | |
] | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import SwiftUI | |
import UIKit | |
struct NoteDetailView: View { | |
@State var vm: Self.ViewModel // CHANGE | |
var body: some View { | |
ScrollView { | |
VStack { | |
TextField("Title", text: $vm.note.title) // CHANGE |