Skip to content

Commit

Permalink
Merge pull request #125 from DroidKaigi/feature/timetable-feature-topbar
Browse files Browse the repository at this point in the history
[iOS] Added some basic view data for topbar
  • Loading branch information
charles-b-stb authored Jul 25, 2024
2 parents 0769e11 + 43127d4 commit 04276d2
Show file tree
Hide file tree
Showing 4 changed files with 91 additions and 37 deletions.
17 changes: 11 additions & 6 deletions app-ios/Sources/TimetableFeature/SampleData.swift
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,14 @@ import Foundation
public enum DayTab: String, CaseIterable, Identifiable {
public var id : RawValue { rawValue }

case day1 = "Day1"
case day2 = "Day2"
case day3 = "Day3"
case workshopDay = "WorkshopDay"
case day1 = "Day 1"
case day2 = "Day 2"
}

public enum TimetableMode {
case list
case grid
}

public struct TimetableTimeGroupItems: Identifiable, Equatable, Hashable {
Expand Down Expand Up @@ -44,7 +49,7 @@ public struct TimetableItem: Equatable, Hashable {
}

struct SampleData {
let day1Results = [
let workdayResults = [
TimetableTimeGroupItems(startsTimeString:"12:00", endsTimeString:"13:00", items: [
TimetableItem(
id: "",
Expand Down Expand Up @@ -121,7 +126,7 @@ struct SampleData {
])
]

let day2Results = [
let day1Results = [
TimetableTimeGroupItems(startsTimeString:"12:00", endsTimeString:"13:00", items: [
TimetableItem(
id: "",
Expand Down Expand Up @@ -194,7 +199,7 @@ struct SampleData {
])
]

let day3Results = [
let day2Results = [
TimetableTimeGroupItems(startsTimeString:"12:00", endsTimeString:"13:00", items: [
TimetableItem(
id: "",
Expand Down
101 changes: 75 additions & 26 deletions app-ios/Sources/TimetableFeature/TimetableListView.swift
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import ComposableArchitecture
import SwiftUI
import Theme

public struct TimetableView: View {
private let store: StoreOf<TimetableReducer>
Expand All @@ -8,25 +9,73 @@ public struct TimetableView: View {
self.store = store
}

@State var timetableMode = TimetableMode.list
@State var switchModeIcon: String = "square.grid.2x2"

public var body: some View {
VStack {
HStack {
ForEach(DayTab.allCases) { tabItem in
Button(action: {
store.send(.view(.selectDay(tabItem)))
}, label: {
//TODO: Only selected button should be green and underlined
Text(tabItem.rawValue).foregroundStyle(Color(.greenSelectColorset))
.underline()
})
NavigationStack {
VStack {
HStack {
ForEach(DayTab.allCases) { tabItem in
Button(action: {
store.send(.view(.selectDay(tabItem)))
}, label: {
//TODO: Only selected button should be green and underlined
Text(tabItem.rawValue).foregroundStyle(
AssetColors.Custom.arcticFox.swiftUIColor)
.underline()
})
}
Spacer()
}.padding(5)
switch timetableMode {
case TimetableMode.list:
TimetableListView(store: store)
case TimetableMode.grid:
Text("Grid view placeholder")
.foregroundStyle(AssetColors.Surface.onSurface.swiftUIColor)
}
Spacer()
}.padding(5)
TimetableListView(store: store)
Spacer()
}

.background(AssetColors.Surface.surface.swiftUIColor)
.frame(maxWidth: .infinity)
.toolbar{
ToolbarItem(placement: .topBarLeading) {
Text("Timetable")
.textStyle(.headlineMedium)
.foregroundStyle(AssetColors.Surface.onSurface.swiftUIColor)

}
ToolbarItem(placement:.topBarTrailing) {
HStack {
Button {
// TODO: Search?
} label: {
Group {
Image(systemName:"magnifyingglass").foregroundStyle(AssetColors.Surface.onSurface.swiftUIColor)
}
.frame(width: 40, height: 40)
}

Button {
switch timetableMode {
case .list:
timetableMode = .grid
switchModeIcon = "list.bullet.indent"
case .grid:
timetableMode = .list
switchModeIcon = "square.grid.2x2"
}
} label: {
Image(systemName:switchModeIcon).foregroundStyle(AssetColors.Surface.onSurface.swiftUIColor)
.frame(width: 40, height: 40)
}
}
}

}
}
.background(Color(.backgroundColorset))
.frame(maxWidth: .infinity)
}
}

Expand All @@ -51,7 +100,7 @@ struct TimetableListView: View {

.onAppear {
store.send(.onAppear)
}.background(Color(.backgroundColorset))
}.background(AssetColors.Surface.surface.swiftUIColor)
}
}
}
Expand All @@ -66,7 +115,7 @@ struct TimeGroupMiniList: View {
Text("|")
Text(contents.endsTimeString)
Spacer()
}.padding(10).foregroundStyle(Color(.onSurfaceColorset))
}.padding(10).foregroundStyle(AssetColors.Surface.onSurface.swiftUIColor)
VStack {
ForEach(contents.items, id: \.self) { item in
ListViewItem(listItem: item)
Expand All @@ -88,7 +137,7 @@ struct ListViewItem: View {
TagView(tagText: lang, highlight: false)
}
Spacer()
Image(systemName: listItem.isFavorite ? "heart.fill" : "heart").foregroundStyle(Color(.onSurfaceColorset))
Image(systemName: listItem.isFavorite ? "heart.fill" : "heart").foregroundStyle(AssetColors.Surface.onSurface.swiftUIColor)
}
Text(listItem.title).font(.title)
ForEach(listItem.speakers, id: \.self){ speaker in
Expand All @@ -97,10 +146,10 @@ struct ListViewItem: View {
}


}.foregroundStyle(Color(.onSurfaceColorset)).padding(10)
}.foregroundStyle(AssetColors.Surface.onSurface.swiftUIColor).padding(10)
.overlay(
RoundedRectangle(cornerRadius: 5)
.stroke(Color(.onSurfaceColorset), lineWidth: 1)
.stroke(AssetColors.Surface.onSurface.swiftUIColor, lineWidth: 1)
)
}
}
Expand All @@ -111,14 +160,14 @@ struct TagView: View {
var body: some View {
HStack {
if highlight {
Image(systemName: "diamond.fill").resizable().frame(width: 11,height: 11).foregroundStyle(Color(.greenSelectColorset))
Image(systemName: "diamond.fill").resizable().frame(width: 11,height: 11).foregroundStyle(AssetColors.Custom.arcticFox.swiftUIColor)
.padding(-3)
}
Text(tagText).foregroundStyle(highlight ? Color(.greenSelectColorset) : Color(.onSurfaceColorset))
Text(tagText).foregroundStyle(highlight ? AssetColors.Custom.arcticFox.swiftUIColor : AssetColors.Surface.onSurface.swiftUIColor)
}
.padding(
EdgeInsets(top: 2,leading: 7, bottom: 2, trailing: 7))
.border(highlight ? Color(.greenSelectColorset) : Color(.onSurfaceColorset))
.border(highlight ? AssetColors.Custom.arcticFox.swiftUIColor : AssetColors.Surface.onSurface.swiftUIColor)
.padding(-2)
}
}
Expand All @@ -130,15 +179,15 @@ struct PhotoView: View {

var body: some View {
HStack {
Image(systemName:photo).resizable().frame(width: 32,height: 32).foregroundStyle(Color(.greenSelectColorset))
Image(systemName:photo).resizable().frame(width: 32,height: 32).foregroundStyle(AssetColors.Custom.arcticFox.swiftUIColor)
Text(name)
}
}
}

#Preview {
TimetableView(
store: .init(initialState: .init(timetableItems: SampleData.init().day1Results),
store: .init(initialState: .init(timetableItems: SampleData.init().workdayResults),
reducer: { TimetableReducer() })
)
}
Expand All @@ -147,7 +196,7 @@ struct PhotoView: View {
TimetableListView(
store: .init(
initialState:
.init(timetableItems: SampleData.init().day1Results),
.init(timetableItems: SampleData.init().workdayResults),
reducer: { TimetableReducer() }
)
)
Expand Down
8 changes: 4 additions & 4 deletions app-ios/Sources/TimetableFeature/TimetableReducer.swift
Original file line number Diff line number Diff line change
Expand Up @@ -30,23 +30,23 @@ public struct TimetableReducer {
Reduce { state, action in
switch action {
case .onAppear:
state.timetableItems = sampleData.day1Results
state.timetableItems = sampleData.workdayResults
return .none
case .view(.timetableItemTapped):
return .none
case .view(.selectDay(let dayTab)):
//TODO: Replace with real data

switch dayTab {
case .workshopDay:
state.timetableItems = sampleData.workdayResults
return .none
case .day1:
state.timetableItems = sampleData.day1Results
return .none
case .day2:
state.timetableItems = sampleData.day2Results
return .none
case .day3:
state.timetableItems = sampleData.day3Results
return .none
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion app-ios/Tests/TimetableTests/TimetableTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ final class TimetableTests: XCTestCase {
TimetableReducer()
}
await store.send(.onAppear) {
$0.timetableItems = SampleData().day1Results
$0.timetableItems = SampleData().workdayResults
}
}
}

0 comments on commit 04276d2

Please sign in to comment.