Skip to content

Commit

Permalink
Attempted fix for items that should extend across entire grid.
Browse files Browse the repository at this point in the history
  • Loading branch information
charles-b-stb committed Aug 18, 2024
1 parent 16262aa commit 441bcc0
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 6 deletions.
4 changes: 4 additions & 0 deletions app-ios/Sources/TimetableFeature/TimetableDataItems.swift
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,10 @@ public struct TimetableTimeGroupItems: Identifiable, Equatable, Hashable {
$0.timetableItem.room.type == room //TODO: roomIj handling not decided?
}.first
}

func matchTopItem(for room: RoomType) -> Bool {
return items[0].timetableItem.room.type == room
}
}

// This exists only for previews now.
Expand Down
5 changes: 4 additions & 1 deletion app-ios/Sources/TimetableFeature/TimetableGridCard.swift
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,16 @@ import class shared.TimetableItem
public struct TimetableGridCard: View {
let timetableItem: TimetableItem?
let onTap: (TimetableItem) -> Void
let cellCount: Int

public init(
timetableItem: TimetableItem?,
cellCount: Int? = 1,
onTap: @escaping (TimetableItem) -> Void
) {
self.timetableItem = timetableItem
self.onTap = onTap
self.cellCount = cellCount ?? 1
}

public var body: some View {
Expand Down Expand Up @@ -58,7 +61,7 @@ public struct TimetableGridCard: View {
}
.frame(maxWidth: .infinity)
.padding(12)
.frame(width: 192, height: 153)
.frame(width: 192*CGFloat(cellCount)+CGFloat(12*(cellCount-1)), height: 153)
.background(timetableItem.room.roomTheme.containerColor, in: RoundedRectangle(cornerRadius: 4))
.overlay(RoundedRectangle(cornerRadius: 4).stroke(timetableItem.room.roomTheme.primaryColor, lineWidth: 1))
}
Expand Down
22 changes: 17 additions & 5 deletions app-ios/Sources/TimetableFeature/TimetableListView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,7 @@ struct TimetableGridView: View {
.frame(width: 192)
}
}

ForEach(store.timetableItems, id: \.self) { timeBlock in
GridRow {
VStack {
Expand All @@ -135,11 +136,22 @@ struct TimetableGridView: View {

}.frame(height: 153)

ForEach(rooms, id: \.self) { room in
if (timeBlock.items.count == 1 && timeBlock.matchTopItem(for: RoomType.roomJ)) {

timeBlock.getCellForRoom(room: room, onTap: { item in
timeBlock.getCellForRoom(
room: RoomType.roomJ,
cellCount: 5,
onTap: { item in
store.send(.view(.timetableItemTapped(item)))
})
}).gridCellColumns(5)


} else {
ForEach(rooms, id: \.self) { room in
timeBlock.getCellForRoom(room: room, cellCount: 1, onTap: { item in
store.send(.view(.timetableItemTapped(item)))
})
}
}
}
}
Expand Down Expand Up @@ -248,9 +260,9 @@ extension RoomType {
}

extension TimetableTimeGroupItems {
func getCellForRoom(room: RoomType, onTap: @escaping (TimetableItemWithFavorite) -> Void) -> TimetableGridCard {
func getCellForRoom(room: RoomType, cellCount: Int?=1, onTap: @escaping (TimetableItemWithFavorite) -> Void) -> TimetableGridCard {
return if let cell = getItem(for: room) {
TimetableGridCard(timetableItem: cell.timetableItem) { timetableItem in
TimetableGridCard(timetableItem: cell.timetableItem, cellCount: cellCount ?? 1) { timetableItem in
onTap(cell)
}
} else {
Expand Down

0 comments on commit 441bcc0

Please sign in to comment.