Skip to content

Commit 549ca65

Browse files
author
Achyut Kumar M
committed
move details from sidebar to a popup
1 parent 18b3a67 commit 549ca65

File tree

3 files changed

+130
-40
lines changed

3 files changed

+130
-40
lines changed

GoInfoGame/GoInfoGame/UI/Map/MapView.swift

Lines changed: 42 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,48 @@ struct MapView: View {
134134
VStack {
135135
Spacer()
136136
HStack {
137-
UndoButton()
137+
UndoButton(
138+
onPreview: { id, type in
139+
140+
switch type {
141+
case .node:
142+
print("NODE")
143+
case .way:
144+
print("WAY")
145+
146+
//get item based on id
147+
let item = viewModel.items.first(where: { $0.id == id })
148+
mapViewRef?.addAnnotation(item!.annotation)
149+
mapViewRef!.setCenter(item!.annotation.coordinate, animated: true)
150+
151+
//build display unit
152+
// mapViewRef?.addAnnotation(item)
153+
154+
// if let item = item {
155+
// let annotation = DisplayUnitAnnotation(element: item)
156+
// mapViewRef?.addAnnotation(annotation)
157+
// mapViewRef?.setCenter(annotation.coordinate, animated: true)
158+
// }
159+
160+
case .relation:
161+
print("RELATION")
162+
163+
}
164+
165+
// if let element = DatabaseConnector.shared.getElement(withId: id, type: type) {
166+
// let annotation = DisplayUnitAnnotation(element: element)
167+
// mapViewRef?.addAnnotation(annotation)
168+
// mapViewRef?.setCenter(annotation.coordinate, animated: true)
169+
// }
170+
},
171+
onRemovePreview: {
172+
// mapViewRef?.removeAnnotations(where: { $0.isPreview }) // however you tag temp annotations
173+
},
174+
onRevert: { id, type in
175+
// Do actual undo + keep annotation
176+
// Optionally, remove "preview" flag if needed
177+
}
178+
)
138179
.padding(.bottom, 24)
139180
.padding(.leading, 16)
140181
.frame(maxWidth: .infinity, maxHeight: .infinity, alignment: .bottomLeading)

GoInfoGame/GoInfoGame/UI/Utils/UndoButton.swift

Lines changed: 70 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -6,36 +6,41 @@
66
//
77

88
import SwiftUI
9+
import osmparser
910

1011
struct UndoButton: View {
12+
var onPreview: (Int, ElementType) -> Void
13+
var onRemovePreview: () -> Void
14+
var onRevert: (Int, ElementType) -> Void
15+
1116
@State private var showSidebar = false
1217
@State private var undoItems: [UndoItem] = []
18+
@State private var selectedUndoItem: UndoItem? = nil
19+
@State private var showUndoPopup = false
1320

1421
var body: some View {
1522
ZStack(alignment: .leading) {
1623
if showSidebar {
1724
UndoSidebarView(
1825
onUndo: { id, type in
1926
MapUndoManager.shared.undo(for: Int64(id), type: type)
27+
onRevert(id, type) // Permanently keep annotation
2028
undoItems = MapUndoManager.shared.getUndoItems()
21-
withAnimation {
22-
showSidebar = false
23-
}
29+
withAnimation { showSidebar = false }
2430
},
25-
onClose: {
26-
withAnimation {
27-
showSidebar = false
28-
}
31+
onClose: { withAnimation { showSidebar = false } },
32+
onItemSelected: { item in
33+
selectedUndoItem = item
34+
showUndoPopup = true
35+
onPreview(item.elementId, item.type) // Show temp annotation
2936
}
3037
)
3138
.transition(.move(edge: .leading))
3239
.padding(.top, 20)
3340
} else {
3441
Button(action: {
35-
// undoItems = fetchUndoItems()
36-
withAnimation {
37-
showSidebar = true
38-
}
42+
undoItems = MapUndoManager.shared.getUndoItems()
43+
withAnimation { showSidebar = true }
3944
}) {
4045
ZStack {
4146
Circle()
@@ -51,10 +56,60 @@ struct UndoButton: View {
5156
.padding(.leading, 12)
5257
.padding(.top, 20)
5358
}
59+
60+
if showUndoPopup, let item = selectedUndoItem {
61+
Color.black.opacity(0.3)
62+
.ignoresSafeArea()
63+
.onTapGesture {
64+
showUndoPopup = false
65+
onRemovePreview() // Remove temp annotation
66+
}
67+
68+
VStack(spacing: 16) {
69+
Text("\(item.type == .way ? "Way" : "Node") #\(item.elementId)")
70+
.font(.headline)
71+
72+
if !item.changedKeys.isEmpty {
73+
VStack(alignment: .leading, spacing: 4) {
74+
Text("Changed keys:")
75+
.font(.subheadline)
76+
.foregroundColor(.gray)
77+
ForEach(item.changedKeys, id: \.self) { key in
78+
Text("\(key)")
79+
.font(.caption)
80+
}
81+
}
82+
}
83+
84+
HStack {
85+
Button("Cancel") {
86+
showUndoPopup = false
87+
onRemovePreview() // Remove temp annotation
88+
}
89+
90+
Spacer()
91+
92+
Button("Revert") {
93+
MapUndoManager.shared.undo(for: Int64(item.elementId), type: item.type)
94+
onRevert(item.elementId, item.type) // Keep annotation
95+
showUndoPopup = false
96+
showSidebar = false
97+
}
98+
.foregroundColor(.white)
99+
.padding(.horizontal, 12)
100+
.padding(.vertical, 6)
101+
.background(Color.red)
102+
.cornerRadius(8)
103+
}
104+
}
105+
.padding()
106+
.frame(maxWidth: 300)
107+
.background(Color.white)
108+
.cornerRadius(12)
109+
.shadow(radius: 10)
110+
}
54111
}
55112
}
56-
57-
// func fetchUndoItems() -> [UndoItem] {
58-
// let changesets = DatabaseConnector.shared.getChangesets()
59-
// }
60113
}
114+
115+

GoInfoGame/GoInfoGame/UI/Utils/UndoSidebarView.swift

Lines changed: 18 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ struct UndoSidebarView: View {
1414
@State private var undoItems: [UndoItem] = []
1515
var onUndo: (Int, ElementType) -> Void
1616
var onClose: () -> Void
17+
var onItemSelected: (UndoItem) -> Void
1718

1819
var body: some View {
1920
VStack(alignment: .leading, spacing: 12) {
@@ -26,39 +27,30 @@ struct UndoSidebarView: View {
2627
.foregroundColor(.gray)
2728
}
2829
}
29-
30+
3031
ScrollView {
3132
ForEach(undoItems) { item in
32-
VStack(alignment: .leading, spacing: 4) {
33-
Text("\(item.type == .way ? "Way" : "Node") #\(String(item.elementId))")
34-
.font(.subheadline)
35-
.bold()
36-
37-
if !item.changedKeys.isEmpty {
38-
Text("Changed:")
39-
.font(.caption)
40-
.foregroundColor(.gray)
33+
Button(action: {
34+
onItemSelected(item)
35+
}) {
36+
VStack(alignment: .leading, spacing: 4) {
37+
Text("\(item.type == .way ? "Way" : "Node") #\(String(item.elementId))")
38+
.font(.subheadline)
39+
.bold()
4140

42-
ForEach(item.changedKeys, id: \.self) { key in
43-
Text("\(key)")
41+
if !item.changedKeys.isEmpty {
42+
Text("Tap to view changes")
4443
.font(.caption)
44+
.foregroundColor(.gray)
4545
}
4646
}
47-
48-
Button("Revert") {
49-
onUndo(item.elementId, item.type)
50-
}
51-
.font(.caption)
52-
.padding(6)
53-
.background(Color.orange)
54-
.foregroundColor(.white)
55-
.cornerRadius(6)
47+
.padding(8)
48+
.background(Color(.systemGray6))
49+
.cornerRadius(10)
5650
}
57-
.padding(8)
58-
.background(Color(.systemGray6))
59-
.cornerRadius(10)
6051
}
6152
}
53+
6254
Spacer()
6355
}
6456
.onAppear {
@@ -71,3 +63,5 @@ struct UndoSidebarView: View {
7163
.shadow(radius: 5)
7264
}
7365
}
66+
67+

0 commit comments

Comments
 (0)