Skip to content
Open
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
63 changes: 38 additions & 25 deletions berkeley-mobile/Home/BMHomeSectionListView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
//

import SwiftUI
import CoreLocation

struct BMHomeSectionListView: View {
var sectionType: HomeDrawerViewType
Expand All @@ -15,14 +16,21 @@ struct BMHomeSectionListView: View {

var selectionHandler: ((SearchItem & HasLocation & HasImage) -> Void)?

private var sortedItems: [SearchItem & HasLocation & HasImage] {
items.sorted { a, b in
let d1 = a.distanceToUser ?? .greatestFiniteMagnitude
let d2 = b.distanceToUser ?? .greatestFiniteMagnitude
return d1 < d2
}
}

var body: some View {
if items.isEmpty {
if sortedItems.isEmpty {
Text("No Available Items")
.font(Font(BMFont.bold(20)))
.foregroundStyle(.gray)
Spacer()
}
else {
} else {
VStack {
if #unavailable(iOS 26.0) {
sectionHeaderView
Expand Down Expand Up @@ -57,29 +65,28 @@ struct BMHomeSectionListView: View {
@ViewBuilder
private var listView: some View {
if #available(iOS 26.0, *) {
List {
Section {
ForEach(items, id: \.name) { item in
Button(action: {
mapViewController.choosePlacemark(item: item)
selectionHandler?(item)
}) {
HomeSectionListRowView(rowItem: item)
.frame(width: 290)
}
.listRowSeparator(.hidden)
.listRowBackground(Color(BMColor.cardBackground))
List {
Section {
ForEach(sortedItems, id: \.name) { item in
Button(action: {
mapViewController.choosePlacemark(item: item)
selectionHandler?(item)
}) {
HomeSectionListRowView(rowItem: item)
.frame(width: 290)
}
} header: {
sectionHeaderView
.listRowSeparator(.hidden)
.listRowBackground(Color(BMColor.cardBackground))
}
} header: {
sectionHeaderView
}
.listStyle(.plain)
.scrollContentBackground(.hidden)
.clipShape(RoundedRectangle(cornerRadius: 10))
}
else {
List(items, id: \.name) { item in
.listStyle(.plain)
.scrollContentBackground(.hidden)
.clipShape(RoundedRectangle(cornerRadius: 10))
} else {
List(sortedItems, id: \.name) { item in
Button(action: {
mapViewController.choosePlacemark(item: item)
selectionHandler?(item)
Expand All @@ -96,11 +103,17 @@ struct BMHomeSectionListView: View {
}

#Preview {
let homeViewModel = HomeViewModel()
let diningHalls = [
BMDiningHall(name: "Cafe 3", address: "2436 Durant Ave, Berkeley, CA 94704", phoneNumber: nil, imageLink: "https://firebasestorage.googleapis.com/v0/b/berkeley-mobile.appspot.com/o/images%2FCafe3.jpg?alt=media&token=f1062476-2cb0-4ce9-9ac1-6109bf588aaa", hours: [], latitude: nil, longitude: nil)
BMDiningHall(
name: "Cafe 3",
address: "2436 Durant Ave, Berkeley, CA 94704",
phoneNumber: nil,
imageLink: "https://firebasestorage.googleapis.com/v0/b/berkeley-mobile.appspot.com/o/images%2FCafe3.jpg?alt=media&token=f1062476-2cb0-4ce9-9ac1-6109bf588aaa",
hours: [],
latitude: 37.8688,
longitude: -122.2590
)
]

BMHomeSectionListView(sectionType: .dining, items: diningHalls, mapViewController: MapViewController())
}