Skip to content

Instantly share code, notes, and snippets.

@davidbalbert
Created June 10, 2021 14:44
Show Gist options
  • Save davidbalbert/a6b2b58224ae7a029b9041cfddc64a74 to your computer and use it in GitHub Desktop.
Save davidbalbert/a6b2b58224ae7a029b9041cfddc64a74 to your computer and use it in GitHub Desktop.
//
// ContentView.swift
// FastNote
//
// Created by David Albert on 6/9/21.
//
import SwiftUI
struct Note: Identifiable {
var id = UUID()
var title: String
var body: String
var updatedAt = Date()
}
struct ContentView: View {
@State var notes = [
Note(title: "Note one", body: "Hello, world"),
Note(title: "Note two", body: "My name is Dave"),
Note(title: "Note three", body: "I am tired"),
Note(title: "Note four", body: "waking up is hard to do")
]
@State var selection = Set<Note.ID>()
@State var searchText = ""
var body: some View {
VSplitView {
Table(notes, selection: $selection) {
TableColumn("Title", value: \.title)
TableColumn("Date Modified") { note in
Text(note.updatedAt.formatted())
}
}
Divider()
if selection.count == 1 {
TextEditor(text: $notes.first { $0.id == selection.first }!.body)
} else {
VStack {
Spacer()
HStack {
Spacer()
if selection.count == 0 {
Text("No note selected")
} else {
Text("\(selection.count) notes selected")
}
Spacer()
}
Spacer()
}
}
}.searchable(text: $searchText, placement: .automatic)
}
}
struct ContentView_Previews: PreviewProvider {
static var previews: some View {
ContentView()
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment