Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/445 stretchfield #603

Merged
merged 10 commits into from
Aug 25, 2024
5 changes: 5 additions & 0 deletions app-ios/Sources/TimetableFeature/TimetableDataItems.swift
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,11 @@ public struct TimetableTimeGroupItems: Identifiable, Equatable, Hashable {
$0.timetableItem.room.type == room //TODO: roomIj handling not decided?
}.first
}

func isTopLunch() -> Bool {
return (items[0].timetableItem.title.enTitle.lowercased().contains("lunch")
&& items[0].timetableItem.startsTimeString.contains("13:00"))
}
}

// This exists only for previews now.
Expand Down
19 changes: 12 additions & 7 deletions app-ios/Sources/TimetableFeature/TimetableGridCard.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,16 @@
public struct TimetableGridCard: View {
let timetableItem: TimetableItem
let onTap: (TimetableItem) -> Void
let cellCount: Int

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

Check warning on line 19 in app-ios/Sources/TimetableFeature/TimetableGridCard.swift

View workflow job for this annotation

GitHub Actions / build-test-ios

left side of nil coalescing operator '??' has non-optional type 'Int', so the right side is never used
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you have ?? 1 is never used used warning yet.
you should remove it👍

}

public var body: some View {
Expand All @@ -22,17 +25,19 @@
} label: {
VStack(alignment: .leading, spacing: 8) {
HStack(spacing: 4) {
RoomTypeShape(roomType: .init(enTitle: timetableItem.room.name.enTitle))
if cellCount == 1 {
RoomTypeShape(roomType: .init(enTitle: timetableItem.room.name.enTitle))
.foregroundStyle(timetableItem.room.roomTheme.primaryColor)
}
Text("\(timetableItem.startsTimeString) - \(timetableItem.endsTimeString)")
.textStyle(.labelMedium)
.foregroundStyle(timetableItem.room.roomTheme.primaryColor)
.foregroundStyle(cellCount > 1 ? AssetColors.Surface.onSurfaceVariant.swiftUIColor : timetableItem.room.roomTheme.primaryColor)
Spacer()
}

Text(timetableItem.title.currentLangTitle)
.textStyle(.titleMedium)
.foregroundStyle(timetableItem.room.roomTheme.primaryColor)
.foregroundStyle(cellCount > 1 ? AssetColors.Surface.onSurface.swiftUIColor : timetableItem.room.roomTheme.primaryColor)
.multilineTextAlignment(.leading)

Spacer()
Expand All @@ -58,17 +63,17 @@
}
.frame(maxWidth: .infinity)
.padding(12)
.frame(width: 192, height: 153)
.background(timetableItem.room.roomTheme.containerColor, in: RoundedRectangle(cornerRadius: 4))
.overlay(RoundedRectangle(cornerRadius: 4).stroke(timetableItem.room.roomTheme.primaryColor, lineWidth: 1))
.frame(width: 192*CGFloat(cellCount)+CGFloat(12*(cellCount-1)), height: 153)
charles-b-stb marked this conversation as resolved.
Show resolved Hide resolved
.background(cellCount > 1 ? AssetColors.Surface.surfaceContainer.swiftUIColor : timetableItem.room.roomTheme.containerColor, in: RoundedRectangle(cornerRadius: 4))
.overlay(RoundedRectangle(cornerRadius: 4).stroke(cellCount > 1 ? AssetColors.Surface.onSurface.swiftUIColor : timetableItem.room.roomTheme.primaryColor, lineWidth: 1))
}
}
}

#Preview {
VStack {
TimetableGridCard(
timetableItem: TimetableItem.Session.companion.fake(),
timetableItem: TimetableItem.Session.companion.fake(), cellCount: 1,
onTap: { _ in }
)
.padding(.horizontal, 16)
Expand Down
39 changes: 25 additions & 14 deletions app-ios/Sources/TimetableFeature/TimetableListView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -95,9 +95,9 @@ struct TimetableListView: View {
ForEach(store.timetableItems, id: \.self) { item in
TimeGroupMiniList(contents: item, onItemTap: { item in
store.send(.view(.timetableItemTapped(item)))
}) {
}, onFavoriteTap: {
store.send(.view(.favoriteTapped($0)))
}
})
}
}.scrollContentBackground(.hidden)
.onAppear {
Expand Down Expand Up @@ -130,6 +130,7 @@ struct TimetableGridView: View {
.frame(width: 192)
}
}

ForEach(store.timetableItems, id: \.self) { timeBlock in
GridRow {
VStack {
Expand All @@ -138,17 +139,27 @@ struct TimetableGridView: View {

}.frame(height: 153)

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

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

if let cell = timeBlock.getCellForRoom(room: room, onTap: { item in
store.send(.view(.timetableItemTapped(item)))}) {
cell
} else {
Color.clear
.frame(maxWidth: .infinity)
.padding(12)
.frame(width: 192, height: 153)
.background(Color.clear, in: RoundedRectangle(cornerRadius: 4))
} else {
ForEach(rooms, id: \.self) { room in
if let cell = timeBlock.getCellForRoom(room: room, onTap: { item in
store.send(.view(.timetableItemTapped(item)))}) {
cell
} else {
Color.clear
.frame(maxWidth: .infinity)
.padding(12)
.frame(width: 192, height: 153)
.background(Color.clear, in: RoundedRectangle(cornerRadius: 4))
}
}
}
}
Expand Down Expand Up @@ -265,9 +276,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? {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
func getCellForRoom(room: RoomType, cellCount: Int?=1, onTap: @escaping (TimetableItemWithFavorite) -> Void) -> TimetableGridCard? {
func getCellForRoom(room: RoomType, cellCount: 1, onTap: @escaping (TimetableItemWithFavorite) -> Void) -> TimetableGridCard? {

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I might be wrong, but I think the intended change is removing "?=1" not the Int part... correct?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sorry it's wrong😅

func getCellForRoom(room: RoomType, cellCount: Int, onTap: @escaping (TimetableItemWithFavorite) -> Void) -> TimetableGridCard? {

is correct👍
@charles-b-stb

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
Loading