forked from BasedHardware/omi
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDailyTaskCreationSheet.swift
More file actions
164 lines (143 loc) · 4.89 KB
/
Copy pathDailyTaskCreationSheet.swift
File metadata and controls
164 lines (143 loc) · 4.89 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
import OmiTheme
import SwiftUI
struct DailyTaskCreationSheet: View {
@Environment(\.dismiss) private var dismiss
@State private var taskDescription = ""
@State private var priority = "medium"
@State private var isCreating = false
@FocusState private var isTextFieldFocused: Bool
let onCreate: (String, String) -> Void
var body: some View {
VStack(alignment: .leading, spacing: OmiSpacing.xl) {
// Header
VStack(alignment: .leading, spacing: OmiSpacing.sm) {
HStack {
Image(systemName: "repeat.circle.fill")
.scaledFont(size: OmiType.heading)
.foregroundColor(Ink.primary)
Text("Create Daily Task")
.scaledFont(size: OmiType.heading, weight: .semibold)
.foregroundColor(Ink.primary)
Spacer()
Button("Cancel") {
dismiss()
}
.buttonStyle(.plain)
.scaledFont(size: OmiType.body)
.foregroundColor(Ink.secondary)
}
Text("This task will repeat every day until completed")
.scaledFont(size: OmiType.body)
.foregroundColor(Ink.secondary)
}
// Task description
VStack(alignment: .leading, spacing: OmiSpacing.sm) {
Text("Task Description")
.scaledFont(size: OmiType.body, weight: .medium)
.foregroundColor(Ink.primary)
TextField("What needs to be done daily?", text: $taskDescription)
.textFieldStyle(.roundedBorder)
.scaledFont(size: OmiType.body)
.focused($isTextFieldFocused)
.onSubmit {
createTask()
}
}
// Priority selection
VStack(alignment: .leading, spacing: OmiSpacing.sm) {
Text("Priority")
.scaledFont(size: OmiType.body, weight: .medium)
.foregroundColor(Ink.primary)
HStack(spacing: OmiSpacing.md) {
ForEach(["high", "medium", "low"], id: \.self) { level in
let isSelected = priority == level
Button {
priority = level
} label: {
HStack(spacing: OmiSpacing.xs) {
Image(systemName: level == "high" ? "flag.fill" : "flag")
.scaledFont(size: OmiType.caption)
.foregroundColor(isSelected ? Ink.surface : priorityColor(level))
Text(level.capitalized)
.scaledFont(size: OmiType.body)
.foregroundColor(isSelected ? Ink.surface : Ink.primary)
}
.padding(.horizontal, OmiSpacing.md)
.padding(.vertical, OmiSpacing.sm)
.background(
RoundedRectangle(cornerRadius: OmiChrome.elementRadius)
.fill(isSelected ? priorityColor(level) : Ink.rowFill)
)
}
.buttonStyle(.plain)
}
Spacer()
}
}
Spacer()
// Create button
HStack {
Spacer()
Button {
createTask()
} label: {
HStack(spacing: OmiSpacing.sm) {
if isCreating {
ProgressView()
.scaleEffect(0.8)
} else {
Image(systemName: "plus.circle.fill")
}
Text(isCreating ? "Creating..." : "Create Daily Task")
}
.scaledFont(size: OmiType.body, weight: .medium)
.foregroundColor(Ink.surface)
.padding(.horizontal, OmiSpacing.xl)
.padding(.vertical, OmiSpacing.sm)
.background(
RoundedRectangle(cornerRadius: OmiChrome.elementRadius)
.fill(
taskDescription.trimmingCharacters(in: .whitespacesAndNewlines).isEmpty
? Ink.secondary : Ink.primary)
)
}
.buttonStyle(.plain)
.disabled(taskDescription.trimmingCharacters(in: .whitespacesAndNewlines).isEmpty || isCreating)
}
}
.padding(OmiSpacing.xxl)
.frame(width: 450, height: 320)
.background(Ink.surface)
.glassContent()
.onAppear {
DispatchQueue.main.asyncAfter(deadline: .now() + 0.1) {
isTextFieldFocused = true
}
}
}
private func priorityColor(_ level: String) -> Color {
switch level {
case "high": return Ink.errorRed
case "medium": return PageGlass.warning
case "low": return Ink.secondary
default: return Ink.secondary
}
}
private func createTask() {
let trimmedDescription = taskDescription.trimmingCharacters(in: .whitespacesAndNewlines)
guard !trimmedDescription.isEmpty, !isCreating else { return }
isCreating = true
onCreate(trimmedDescription, priority)
// Dismiss after a brief delay
DispatchQueue.main.asyncAfter(deadline: .now() + 0.3) {
dismiss()
}
}
}
#if canImport(PreviewsMacros)
#Preview {
DailyTaskCreationSheet { description, priority in
print("Create daily task: \(description) with priority: \(priority)")
}
}
#endif