Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
73 changes: 73 additions & 0 deletions berkeley-mobile/Resources/ResourcesView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,28 @@ import SwiftUI
struct ResourcesView: View {
@StateObject private var resourcesViewModel = ResourcesViewModel()
@State private var tabSelectedValue = 0
@State private var searchText = ""

var isSearching: Bool {
!searchText.trimmingCharacters(in: .whitespaces).isEmpty
}

var searchResults: [(categoryName: String, section: BMResourceSection)] {
let query = searchText.trimmingCharacters(in: .whitespaces)
guard !query.isEmpty else { return [] }

return resourcesViewModel.resourceCategories.flatMap { category in
category.sections.filter { section in
let titleMatch = section.title?.localizedCaseInsensitiveContains(query) ?? false
let resourceMatch = section.resources.contains {
$0.name.localizedCaseInsensitiveContains(query)
}
return titleMatch || resourceMatch
}
.map { (categoryName: category.name, section: $0) }
}
}


init() {
// Use this if NavigationBarTitle is with Large Font
Expand Down Expand Up @@ -49,9 +71,60 @@ struct ResourcesView: View {
}
.background(Color(BMColor.cardBackground))
.presentAlert(alert: $resourcesViewModel.alert)
.searchable(
text: $searchText,
placement: .navigationBarDrawer(displayMode: .always),
prompt: "Search resources..."
)
.animation(.default, value: isSearching)

}
}

// MARK: - Search Results View

@ViewBuilder
private var searchResultsView: some View {
if searchResults.isEmpty {
BMContentUnavailableView(
iconName: "magnifyingglass",
title: "No Results",
subtitle: "No resources found for \"\(searchText.trimmingCharacters(in: .whitespaces))\""
)
.frame(maxWidth: .infinity, maxHeight: .infinity, alignment: .center)
.transition(.opacity)
} else {
ScrollView {
VStack(spacing: 10) {
ForEach(searchResults, id: \.section) { result in
if let sectionTitle = result.section.title {
VStack(alignment: .leading, spacing: 4) {
// Category label above each matched section
Text(result.categoryName)
.font(Font(BMFont.regular(12)))
.foregroundStyle(.secondary)
.padding(.horizontal)

ResourcesSectionDropdown(title: sectionTitle, accentColor: .orange) {
VStack(spacing: 0) {
ForEach(result.section.resources, id: \.id) { resource in
ResourceItemView(resource: resource)
}
}
}
}
}
}
}
.padding(.top, 8)
}
.background(Color(BMColor.cardBackground))
.transition(.opacity)
}
}

// MARK: - Empty State

private var noResourcesAvailableView: some View {
BMContentUnavailableView(
iconName: "exclamationmark.triangle",
Expand Down
21 changes: 6 additions & 15 deletions berkeley-mobile/Safety/SafetyMapView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -18,21 +18,12 @@ struct SafetyMapView: View {
var isPresentingDetailView: Bool

var body: some View {
if #available(iOS 17.0, *) {
SafetyNewMapView(selectedSafetyLog: $selectedSafetyLog,
isShowingLegend: $isShowingLegend,
drawerViewState: $drawerViewState,
isPresentingDetailView: isPresentingDetailView)
} else {
oldMapView
}
}

private var oldMapView: some View {
Map(coordinateRegion: .constant(BMConstants.mapBoundsRegion), showsUserLocation: true, annotationItems: safetyViewModel.filteredSafetyLogs) { safetyLog in
MapPin(coordinate: safetyLog.coordinate)
}
.edgesIgnoringSafeArea(.all)
SafetyNewMapView(selectedSafetyLog: $selectedSafetyLog,
isShowingLegend: $isShowingLegend,
drawerViewState: $drawerViewState,
isPresentingDetailView: isPresentingDetailView)


}
}

Expand Down