Skip to content

Commit 9718f2b

Browse files
authored
Merge pull request #250 from TaskarCenterAtUW/fix-undo-details-ui
Fix undo details UI
2 parents 18b3a67 + f76350f commit 9718f2b

File tree

3 files changed

+106
-75
lines changed

3 files changed

+106
-75
lines changed

GoInfoGame/GoInfoGame/UI/Map/MapView.swift

Lines changed: 18 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,22 @@ struct MapView: View {
134134
VStack {
135135
Spacer()
136136
HStack {
137-
UndoButton()
137+
UndoButton(
138+
onPreview: { id, type in
139+
140+
141+
// if let element = DatabaseConnector.shared.getElement(withId: id, type: type) {
142+
// let annotation = DisplayUnitAnnotation(element: element)
143+
// mapViewRef?.addAnnotation(annotation)
144+
// mapViewRef?.setCenter(annotation.coordinate, animated: true)
145+
// }
146+
},
147+
onRemovePreview: {
148+
},
149+
onRevert: { id, type in
150+
151+
}
152+
)
138153
.padding(.bottom, 24)
139154
.padding(.leading, 16)
140155
.frame(maxWidth: .infinity, maxHeight: .infinity, alignment: .bottomLeading)
@@ -144,24 +159,7 @@ struct MapView: View {
144159
}, useBingMaps: useBingMaps)
145160
}
146161
}
147-
148-
// if showUndoSidebar {
149-
// UndoSidebarView(
150-
// onUndo: { id, type in
151-
// MapUndoManager.shared.undo(for: Int64(id), type: type)
152-
// // undoItems = MapUndoManager.shared.getUndoItems() // refresh
153-
// },
154-
// onClose: {
155-
// withAnimation {
156-
// showUndoSidebar = false
157-
// }
158-
// }
159-
// )
160-
// .transition(.move(edge: .leading))
161-
// .padding(.top, 20)
162-
// }
163-
164-
162+
165163
if !viewModel.selectedAnnotaions.isEmpty,
166164
let selectedAnnotationType = viewModel.selectedAnnotationType,
167165
let image = viewModel.selectedAnnotaions.first?.displayUnit.parent?.icon {
@@ -196,23 +194,7 @@ struct MapView: View {
196194
.navigationBarHidden(isPresented)
197195
.navigationBarItems(leading: EmptyView())
198196
.toolbar {
199-
ToolbarItem(placement: .navigationBarLeading) {
200-
NavigationLink(destination: UserProfileView()) {
201-
Image(systemName: "person.crop.circle.fill")
202-
.foregroundStyle(Color(red: 135/255, green: 62/255, blue: 242/255))
203-
}
204-
}
205-
// ToolbarItem(placement: .navigationBarTrailing) {
206-
// Button(action: {
207-
// print("Refresh icon tapped")
208-
// viewModel.fetchOSMDataFor(from: .currentLocation(location: viewModel.userlocation))
209-
// }) {
210-
// Image(systemName: "arrow.2.circlepath")
211-
// .frame(width: 20, height: 20)
212-
// .foregroundStyle(Color(red: 135/255, green: 62/255, blue: 242/255))
213-
// }
214-
// }
215-
197+
216198
ToolbarItem(placement: .navigationBarTrailing) {
217199
Button(action: {
218200
print("Settings icon tapped")

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)
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)
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()
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()
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)
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)