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
17 changes: 11 additions & 6 deletions app-ios/Sources/TimetableFeature/TimetableGridCard.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,16 @@ import CommonComponents
public struct TimetableGridCard: View {
let timetableItem: TimetableItem
let onTap: (TimetableItem) -> Void
let cellCount: Int

public init(
timetableItem: TimetableItem,
cellCount: Int? = 1,
Copy link
Contributor

Choose a reason for hiding this comment

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

I think this argument is no needed an optional 🤔
and required property is no needed a default value 👍

Suggested change
cellCount: Int? = 1,
cellCount: Int,

onTap: @escaping (TimetableItem) -> Void
) {
self.timetableItem = timetableItem
self.onTap = onTap
self.cellCount = cellCount ?? 1
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 @@ public struct TimetableGridCard: View {
} 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)
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
.foregroundStyle(cellCount>1 ? AssetColors.Surface.onSurfaceVariant.swiftUIColor : timetableItem.room.roomTheme.primaryColor)
.foregroundStyle(cellCount > 1 ? AssetColors.Surface.onSurfaceVariant.swiftUIColor : timetableItem.room.roomTheme.primaryColor)

I want add spaces for any operators left and right😅

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,9 +63,9 @@ public struct TimetableGridCard: View {
}
.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))
}
}
}
Expand Down
41 changes: 26 additions & 15 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 @@ -198,7 +209,7 @@ fileprivate var bottomTabBarPadding: some View {
}

extension RoomType {
func toRoom() -> TimetableRoom {
public func toRoom() -> TimetableRoom {
Copy link
Contributor

Choose a reason for hiding this comment

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

Why did you add this public🤔?
I seem this PR doesn't reference this method.

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 was using it elsewhere, but on closer inspection it was in the same file so public was not needed.

switch self {
case .roomI:
return TimetableRoom(
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