Skip to content

Commit 0ec2911

Browse files
author
Achyut Kumar M
committed
show text toasts whereever required
1 parent 5d6976c commit 0ec2911

File tree

2 files changed

+116
-40
lines changed

2 files changed

+116
-40
lines changed

GoInfoGame/GoInfoGame/UI/Map/MapView.swift

Lines changed: 30 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -95,30 +95,38 @@ struct MapView: View {
9595
.edgesIgnoringSafeArea(.all)
9696
ActivityView(activityText: "Looking for quests...")
9797
}
98-
if showAlert {
99-
VStack {
100-
Image(systemName: alertIcon)
101-
.resizable()
102-
.aspectRatio(contentMode: .fit)
103-
.frame(width: 50, height: 50)
104-
.foregroundColor(.green)
105-
.padding(.bottom, 50)
106-
Text(alertMessage)
107-
.foregroundColor(.white)
108-
.padding()
109-
.background(Color.orange)
110-
.cornerRadius(10)
111-
}
112-
.padding([.all], 50)
113-
.background(Color.white)
114-
.accessibilityElement(children: .combine)
115-
.accessibilityLabel(alertMessage)
116-
.onAppear {
117-
DispatchQueue.main.asyncAfter(deadline: .now() + 2) {
118-
showAlert = false // Dismiss notification box after 1 second
98+
if showAlert {
99+
VStack(spacing: 20) {
100+
Image(systemName: alertIcon)
101+
.resizable()
102+
.scaledToFit()
103+
.frame(width: 40, height: 40)
104+
.foregroundColor(.green)
105+
106+
Text(alertMessage)
107+
.foregroundColor(.white)
108+
.font(.system(size: 16, weight: .medium))
109+
.multilineTextAlignment(.center)
110+
.padding()
111+
.frame(maxWidth: .infinity) // stretch text inside fixed card
112+
.background(Color.orange)
113+
.cornerRadius(12)
114+
}
115+
.padding(24)
116+
.frame(maxWidth: 350) // increased card width
117+
.background(
118+
RoundedRectangle(cornerRadius: 20)
119+
.fill(Color.white)
120+
.shadow(color: .black.opacity(0.1), radius: 10, x: 0, y: 4)
121+
)
122+
.accessibilityElement(children: .combine)
123+
.accessibilityLabel(alertMessage)
124+
.onAppear {
125+
DispatchQueue.main.asyncAfter(deadline: .now() + 2) {
126+
showAlert = false
127+
}
119128
}
120129
}
121-
}
122130

123131

124132
FloatingActionButtonStack(mapButtonAction: {

GoInfoGame/GoInfoGame/quests/LongQuests/View/LongForm.swift

Lines changed: 86 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,12 @@ struct LongForm: View, QuestForm {
4848
@State private var showNotesBox = false
4949

5050
@State private var noteText = ""
51+
52+
@State private var alertMessage = ""
53+
54+
@State private var showCreateNoteMessage = false
55+
56+
@StateObject private var noteViewModel = NotesViewModel()
5157

5258
var body: some View {
5359
ZStack {
@@ -89,6 +95,17 @@ struct LongForm: View, QuestForm {
8995
.padding([.trailing], 20)
9096
}
9197

98+
if showCreateNoteMessage {
99+
Text(alertMessage)
100+
.foregroundColor(alertMessage == "Note submitted successfully" ? Color.green : Color.red)
101+
.padding(.horizontal, 20)
102+
.onAppear {
103+
DispatchQueue.main.asyncAfter(deadline: .now() + 3) {
104+
showCreateNoteMessage = false
105+
}
106+
}
107+
}
108+
92109
if showNotesBox {
93110
VStack(alignment: .leading, spacing: 10) {
94111
TextEditor(text: $noteText)
@@ -97,27 +114,44 @@ struct LongForm: View, QuestForm {
97114
.border(Color(red: 135/255, green: 62/255, blue: 242/255))
98115

99116
HStack {
100-
Button("Submit") {
101-
submitNote()
102-
showNotesBox = false
117+
Button(action: {
118+
Task {
119+
do {
120+
try await submitNote()
121+
} catch {
122+
showCreateNoteMessage = true
123+
showNotesBox = false
124+
125+
}
126+
}
127+
}) {
128+
if noteViewModel.isLoading {
129+
ProgressView()
130+
} else {
131+
Text("Submit")
132+
.font(.custom("Lato-Bold", size: 16))
133+
.foregroundColor(.white)
134+
.padding()
135+
.frame(maxWidth: .infinity)
136+
.background(noteText != "" ? Color(red: 135/255, green: 62/255, blue: 242/255) : Color.gray)
137+
.cornerRadius(9)
138+
}
103139
}
104-
.padding()
105-
.frame(maxWidth: .infinity)
106-
.background(Color.blue)
107-
.foregroundColor(.white)
108-
.cornerRadius(8)
109-
.padding(.horizontal, 20)
110-
111-
Button("Cancel") {
140+
.disabled(noteText == "")
141+
142+
Button (action: {
112143
showNotesBox = false
144+
}) {
145+
Text("Cancel")
146+
.font(.custom("Lato-Bold", size: 16))
147+
.foregroundColor(.white)
148+
.padding()
149+
.frame(maxWidth: .infinity)
150+
.background(Color.red)
151+
.cornerRadius(9)
113152
}
114-
.padding()
115-
.frame(maxWidth: .infinity)
116-
.background(Color.red)
117-
.foregroundColor(.white)
118-
.cornerRadius(8)
119-
.padding(.horizontal, 20)
120153
}
154+
.padding(.horizontal, 20)
121155
}
122156
.padding(.top, 10)
123157
}
@@ -138,6 +172,17 @@ struct LongForm: View, QuestForm {
138172
}
139173
}
140174
VStack {
175+
if showSubmitAlert {
176+
Text(submitAlert)
177+
.font(.custom("Lato-Bold", size: 16))
178+
.foregroundColor(.red)
179+
.background(Color.white)
180+
.onAppear {
181+
DispatchQueue.main.asyncAfter(deadline: .now() + 2) {
182+
showSubmitAlert = false
183+
}
184+
}
185+
}
141186
Button(action: {
142187
if !viewModel.answersToBeSubmitted.isEmpty {
143188
if let action = action {
@@ -219,8 +264,31 @@ struct LongForm: View, QuestForm {
219264
}
220265
}
221266

222-
func submitNote() {
267+
func submitNote() async throws {
223268
print("Note to be submitted: \(noteText)")
269+
270+
do {
271+
let notesResult = try await noteViewModel.createNote(note: noteText, lat: 0.0, long: 0.0)
272+
273+
if notesResult {
274+
print("Notes composed successfully")
275+
alertMessage = "Note submitted successfully"
276+
showCreateNoteMessage = true
277+
278+
} else {
279+
alertMessage = "Error creating note"
280+
showCreateNoteMessage = true
281+
}
282+
} catch {
283+
alertMessage = "Error creating note: \(error.localizedDescription)"
284+
print("Error creating note: \(error.localizedDescription)")
285+
throw error
286+
}
287+
288+
await MainActor.run {
289+
noteViewModel.isLoading = false
290+
showNotesBox = false
291+
}
224292
}
225293

226294
func uploadImageToKartaView() {

0 commit comments

Comments
 (0)