Skip to content
Merged
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
87 changes: 70 additions & 17 deletions ios/Buildings/Sources/BuildingViews/BuildingsTabView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,12 @@ public struct BuildingsTabView<BuildingDestination: View, RoomDestination: View>
public init(
path: Binding<NavigationPath>,
viewModel: BuildingViewModel,
selectedView: Binding<RoomOrientation>, // TODO: rename RoomOrientation?
_ roomsDestinationBuilderView: @escaping (Building) -> BuildingDestination,
_ roomDestinationBuilderView: @escaping (Room) -> RoomDestination)
{
_path = path
_selectedView = selectedView
self.viewModel = viewModel
self.roomsDestinationBuilderView = roomsDestinationBuilderView
self.roomDestinationBuilderView = roomDestinationBuilderView
Expand All @@ -33,13 +35,7 @@ public struct BuildingsTabView<BuildingDestination: View, RoomDestination: View>

public var body: some View {
NavigationStack(path: $path) {
List {
buildingsView(for: "Upper campus", from: viewModel.filteredBuildings.upper)

buildingsView(for: "Middle campus", from: viewModel.filteredBuildings.middle)

buildingsView(for: "Lower campus", from: viewModel.filteredBuildings.lower)
}
buildingsView
.refreshable {
Task {
await viewModel.reloadBuildings()
Expand All @@ -64,14 +60,18 @@ public struct BuildingsTabView<BuildingDestination: View, RoomDestination: View>
.resizable()
.frame(width: 25, height: 20)
}

Button {
// action
} label: {
Image(systemName: "list.bullet")
.resizable()
.frame(width: 22, height: 20)
}

Button {
if selectedView == RoomOrientation.Card {
selectedView = RoomOrientation.List
} else {
selectedView = RoomOrientation.Card
}
} label: {
Image(systemName: selectedView == RoomOrientation.List ? "square.grid.2x2" : "list.bullet")
.resizable()
.frame(width: 22, height: 20)
}
}
.padding(5)
.foregroundStyle(theme.label.tertiary)
Expand Down Expand Up @@ -135,12 +135,63 @@ public struct BuildingsTabView<BuildingDestination: View, RoomDestination: View>
@State var viewModel: BuildingViewModel
@Binding var path: NavigationPath
@State var rowHeight: CGFloat?
@Binding var selectedView: RoomOrientation
@State var cardWidth: CGFloat?

let roomsDestinationBuilderView: (Building) -> BuildingDestination
let roomDestinationBuilderView: (Room) -> RoomDestination

@ViewBuilder
private var buildingsView: some View {
if selectedView == RoomOrientation.List {
List {
buildingsListSegment(for: "Upper campus", from: viewModel.filteredBuildings.upper)
buildingsListSegment(for: "Middle campus", from: viewModel.filteredBuildings.middle)
buildingsListSegment(for: "Lower campus", from: viewModel.filteredBuildings.lower)
}
} else {
ScrollView {
buildingsCardSegment(for: "Upper campus", from: viewModel.filteredBuildings.upper)
buildingsCardSegment(for: "Middle campus", from: viewModel.filteredBuildings.middle)
buildingsCardSegment(for: "Lower campus", from: viewModel.filteredBuildings.lower)
}
.padding(.horizontal, 16)
}
}

@ViewBuilder
func buildingsCardSegment(for campus: String, from buildings: [Building]) -> some View {
Section {
LazyVGrid(columns: columns, spacing: 24) {
ForEach(buildings) { building in
GenericCardView(
path: $path,
cardWidth: $cardWidth,
building: building,
buildings: buildings,
imageProvider: { roomID in
BuildingImage[roomID]
})
}
}
} header: {
HStack {
Text(campus)
.foregroundStyle(theme.label.primary)
.padding(.leading, 10)
Spacer()
}
.padding(.top, 10)
}
}

private let columns = [
GridItem(.flexible()),
GridItem(.flexible()),
]

@ViewBuilder
func buildingsView(for campus: String, from buildings: [Building]) -> some View {
func buildingsListSegment(for campus: String, from buildings: [Building]) -> some View {
if buildings.isEmpty {
EmptyView()
} else {
Expand Down Expand Up @@ -172,11 +223,13 @@ public struct BuildingsTabView<BuildingDestination: View, RoomDestination: View>

struct PreviewWrapper: View {
@State var path = NavigationPath()
@State var selectedView = RoomOrientation.List

var body: some View {
BuildingsTabView(
path: $path,
viewModel: PreviewBuildingViewModel())
viewModel: PreviewBuildingViewModel(),
selectedView: $selectedView)
{ _ in
EmptyView() // Buildings destination
} _: { _ in
Expand Down
23 changes: 16 additions & 7 deletions ios/CommonUI/Sources/CommonUI/GenericCardViewItem.swift
Original file line number Diff line number Diff line change
Expand Up @@ -54,13 +54,20 @@ public struct GenericCardViewItem<T: Equatable & Hashable & Identifiable & HasNa

Spacer()
if let overallRating = item.overallRating {
Text(overallRating.formatted())
.foregroundStyle(.white)
.font(.system(size: 12, weight: .semibold))
.padding(.leading, 2)
Image(systemName: "star.fill")
.font(.system(size: 10, weight: .semibold))
.padding(.trailing)
HStack(spacing: 0) {
Text(overallRating.formatted())
.foregroundStyle(.white)
.font(.system(size: 12, weight: .semibold))
.padding(.leading, 2)
Image(systemName: "star.fill")
.font(.system(size: 10, weight: .semibold))
.foregroundStyle(.white)
}
.padding(.horizontal, 4)
.padding(.vertical, 2)
.background(
RoundedRectangle(cornerRadius: 12)
.fill(theme.label.tertiary))
} else {
HStack(spacing: 0) {
Text("0")
Expand Down Expand Up @@ -92,6 +99,8 @@ public struct GenericCardViewItem<T: Equatable & Hashable & Identifiable & HasNa
.fill(room.statusBackgroundColor))
} else if let building = item as? Building {
Text("^[\(building.numberOfAvailableRooms ?? 0) room](inflect: true) available")
.font(.system(size: 14, weight: .light))
.frame(maxWidth: .infinity, alignment: .leading)
}
}
}
Expand Down
9 changes: 5 additions & 4 deletions ios/Freerooms/ContentView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,13 @@ struct ContentView: View {
@Environment(\.mapViewModel) var mapViewModel
@Environment(\.roomViewModel) var roomViewModel
@State var selectedTab = "Buildings"
@State var selectedView = RoomOrientation.List
@State var selectedRoomsView = RoomOrientation.List
@State var selectedBuildingsView = RoomOrientation.List

var body: some View {
TabView(selection: $selectedTab) {
BuildingsTabView(path: $buildingPath, viewModel: buildingViewModel) { building in
RoomsListView(roomViewModel: roomViewModel, building: building, path: $buildingPath, imageProvider: {
BuildingsTabView(path: $buildingPath, viewModel: buildingViewModel, selectedView: $selectedBuildingsView) { building in
RoomsListView(roomViewModel: roomViewModel, building: building, path: $buildingPath,imageProvider: {
BuildingImage[$0]
})
.task { await roomViewModel.onAppear() }
Expand All @@ -50,7 +51,7 @@ struct ContentView: View {
roomViewModel: roomViewModel,
buildingViewModel: buildingViewModel,
selectedTab: $selectedTab,
selectedView: $selectedView)
selectedView: $selectedRoomsView)
{ room in
RoomDetailsView(room: room, roomViewModel: roomViewModel)
.task { await roomViewModel.onAppear() }
Expand Down
2 changes: 1 addition & 1 deletion ios/Rooms/Sources/RoomViews/RoomsTabView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ public struct RoomsTabView<Destination: View>: View {
@Binding var selectedTab: String

@Binding var selectedView: RoomOrientation
@State var cardWidth: CGFloat? // TODO:
@State var cardWidth: CGFloat?
@State var searchText = ""
@Binding var path: NavigationPath
@State var rowHeight: CGFloat?
Expand Down