Skip to content

Commit

Permalink
✨ Added input for adding tasks
Browse files Browse the repository at this point in the history
  • Loading branch information
Eppu committed Nov 23, 2022
1 parent bd1632b commit c4e999f
Showing 1 changed file with 54 additions and 14 deletions.
68 changes: 54 additions & 14 deletions Poet/ContentView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,34 +8,74 @@
import SwiftUI


struct ContentView: View {
struct Task: Hashable, Identifiable {
var id = UUID()
var title: String
var completed = false
}

struct TaskView: View {
@State var task: Task

var body: some View {
Button(action: { task.completed.toggle() }) {
HStack(alignment: .firstTextBaseline, spacing: 8) {
Image(systemName: task.completed ? "largecircle.fill.circle" : "circle")
.foregroundColor(.secondary)
Text(task.title)
.strikethrough(task.completed)
.foregroundColor(task.completed ? .secondary : .primary)
Spacer()
}
}
.buttonStyle(PlainButtonStyle())
if(task.completed) {
// Button(action: { tasks.filter() {$0.id != task.id}})
}
}
}

struct ContentView: View {
// TODO: Add AppStorage for persisting task state
@State private var todoInput: String = ""
@FocusState private var todoInputIsFocused: Bool
@State var tasks: [Task] = [
Task(title: "Here's to the crazy ones"),
Task(title: "Another task"),
Task(title: "A long task name that will need to be rendered on separate rows")
]


var body: some View {
VStack(alignment: .leading) {
Image(systemName: "globe")
.imageScale(.large)
.foregroundColor(.accentColor)
Text("Hello, world!")
// Image(systemName: "globe")
// .imageScale(.large)
// .foregroundColor(.accentColor)
// Text("Things to get done").font(Font.headline).bold()

// Populate list with todos
ScrollView {
VStack(alignment: .leading, spacing: 10) {
ForEach(tasks, id: \.id) { task in
TaskView(task: task)
}
}
}.padding(.top, 5)




// // Populate list with todos
// List() { todo in
// HStack(alignment: .center) {
//
// }

// }
TextField(
"Todo",
"What do you need to get done?",
text: $todoInput
)
.focused($todoInputIsFocused)
.disableAutocorrection(true)
.onSubmit {
print("Submitted")
print("Added \(todoInput) to tasks")
tasks.append(Task(title: "\(todoInput)"))
todoInput = ""
print("tasks count is ", tasks.count)
}
}
.padding()
Expand Down

0 comments on commit c4e999f

Please sign in to comment.