Skip to content

Commit 1713cc6

Browse files
authored
Merge pull request #169 from TaskarCenterAtUW/feature-store-hidden-elements
Store hidden elements to userdefaults
2 parents 1930bdb + c8b3088 commit 1713cc6

File tree

3 files changed

+47
-24
lines changed

3 files changed

+47
-24
lines changed

GoInfoGame/GoInfoGame/AppQuestManager.swift

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -177,6 +177,9 @@ class AppQuestManager {
177177

178178
print(nodeElements.filter({ $0.id == 1026105 }))
179179

180-
return displayUnits
180+
let hiddenElements = UserDefaults.standard.array(forKey: "hiddenElements") as? [Int64] ?? []
181+
182+
let unitsToBeDisplayed = displayUnits.filter { !hiddenElements.contains($0.id) }
183+
return unitsToBeDisplayed
181184
}
182185
}

GoInfoGame/GoInfoGame/UI/Map/MapView.swift

Lines changed: 33 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -122,34 +122,44 @@ struct MapView: View {
122122
.toolbarBackground(.visible, for: .navigationBar)
123123

124124
.popover(isPresented: $showPopover) {
125-
VStack {
126-
Button("Hide Quest") {
127-
128-
viewModel.hideQuest(elementId: viewModel.selectedQuest!.parent!.displayUnit.id)
129-
showPopover = false
130-
shouldShowPolyline = false
131-
}
132-
.padding()
133-
134-
Button("Answer Quest") {
135-
showPopover = false
136-
isPresented = true
137-
}
138-
.padding()
139-
}
140-
.onAppear {
141-
shouldShowPolyline = true
142-
}
143-
.frame(width: 200, height: 100)
144-
.presentationDetents([.fraction(0.5)])
145-
}
146-
147-
125+
VStack {
126+
Button("Hide Quest") {
127+
viewModel.hideQuest(elementId: viewModel.selectedQuest!.parent!.displayUnit.id)
128+
showPopover = false
129+
shouldShowPolyline = false
130+
}
131+
.padding()
132+
133+
Button("Answer Quest") {
134+
showPopover = false
135+
isPresented = true
136+
}
137+
.padding()
138+
}
139+
.frame(maxHeight: 50)
140+
.onAppear {
141+
shouldShowPolyline = true
142+
}
143+
.presentationDetents([.fraction(0.5)])
144+
}
145+
.onChange(of: showPopover) { newValue in
146+
if !newValue {
147+
shouldShowPolyline = false
148+
}
149+
}
150+
.onChange(of: isPresented) { newValue in
151+
if !newValue {
152+
shouldShowPolyline = false
153+
}
154+
}
148155
.sheet(isPresented: $isPresented, content: {
149156
let selectedQuest = self.viewModel.selectedQuest
150157
CustomSheetView {
151158
selectedQuest?.parent?.form
152159
}
160+
.onAppear {
161+
shouldShowPolyline = true
162+
}
153163
.presentationDetents([.fraction(0.8), .fraction(0.5), .fraction(0.1)], selection: $selectedDetent)
154164
.scrollDisabled(false)
155165
.interactiveDismissDisabled()

GoInfoGame/GoInfoGame/UI/Map/MapViewModel.swift

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,17 @@ class MapViewModel: ObservableObject {
102102
if let toBeHidden = self.items.first(where: {$0.id == Int(questId)!}) {
103103
let index = self.items.firstIndex(where: {$0.id == Int(questId)!})
104104
items[index!].isHidden = true
105+
106+
var hiddenElementIds = UserDefaults.standard.array(forKey: "hiddenElements") as? [Int64] ?? []
107+
108+
if !hiddenElementIds.contains(toBeHidden.id) {
109+
hiddenElementIds.append(toBeHidden.id)
110+
UserDefaults.standard.set(hiddenElementIds, forKey: "hiddenElements")
111+
}
112+
105113
}
114+
115+
106116
}
107117

108118
private func boundingBoxAroundLocation(location: CLLocationCoordinate2D, distance: CLLocationDistance) -> BBox {

0 commit comments

Comments
 (0)