@@ -22,13 +22,13 @@ public struct ScheduleList: Reducer {
22
22
23
23
let categoryTag : String ?
24
24
25
- var racesState = APIClient< Race > . State( endpoint: " next-race " )
25
+ public var racesState = APIClient< ScheduleListResponse > . State( endpoint: " next-race " )
26
26
}
27
27
28
28
public enum Action : Equatable {
29
29
case onAppear
30
30
31
- case racesRequest( APIClient < Race > . Action )
31
+ case racesRequest( APIClient < ScheduleListResponse > . Action )
32
32
}
33
33
34
34
public var body : some ReducerOf < Self > {
@@ -45,6 +45,16 @@ public struct ScheduleList: Reducer {
45
45
APIClient ( )
46
46
}
47
47
}
48
+
49
+ public struct ScheduleListResponse : Codable , Equatable {
50
+ public init ( categoryComment: String , nextRace: Race ) {
51
+ self . categoryComment = categoryComment
52
+ self . nextRace = nextRace
53
+ }
54
+
55
+ public let categoryComment : String
56
+ public let nextRace : Race
57
+ }
48
58
}
49
59
50
60
public struct ScheduleListView : View {
@@ -56,18 +66,17 @@ public struct ScheduleListView: View {
56
66
57
67
public var body : some View {
58
68
WithViewStore ( store, observe: { $0 } ) { viewStore in
59
- ScrollView {
60
- VStack {
61
- switch viewStore. racesState. response {
62
- case . idle:
63
- Text ( " idle " )
64
- case . loading:
65
- Text ( " loading " )
66
- case . reloading( let race) , . finished( . success( let race) ) :
67
- Text ( " finished or reloading - \( race. title) " )
68
- case . finished( . failure( let error) ) :
69
- APIErrorView ( error: error)
70
- }
69
+ List {
70
+ switch viewStore. racesState. response {
71
+ case . idle:
72
+ EmptyView ( )
73
+ case . loading:
74
+ ProgressView ( )
75
+ case . reloading( let response) , . finished( . success( let response) ) :
76
+ ScheduleListItem ( response)
77
+ . padding ( . vertical)
78
+ case . finished( . failure( let error) ) :
79
+ APIErrorView ( error: error)
71
80
}
72
81
}
73
82
}
@@ -77,3 +86,41 @@ public struct ScheduleListView: View {
77
86
}
78
87
}
79
88
89
+ // TODO: This should not take in an 'internal' model
90
+ public struct ScheduleListItem : View {
91
+ public init ( _ response: ScheduleList . ScheduleListResponse ) {
92
+ self . response = response
93
+ }
94
+
95
+ let response : ScheduleList . ScheduleListResponse
96
+
97
+ public var body : some View {
98
+ VStack ( alignment: . leading) {
99
+ Text ( " Category title " )
100
+ . font ( . callout)
101
+
102
+ Text ( response. nextRace. title)
103
+ . font ( . title3)
104
+
105
+ HStack {
106
+ RoundedRectangle ( cornerRadius: 25.0 , style: . continuous)
107
+ . frame ( maxWidth: 100 )
108
+
109
+ Spacer ( )
110
+ VStack ( alignment: . leading) {
111
+
112
+
113
+ ForEach ( response. nextRace. events) { event in
114
+ HStack {
115
+ Text ( event. title)
116
+ Text ( event. date. formatted ( ) )
117
+ }
118
+ . font ( . caption)
119
+ }
120
+ }
121
+ }
122
+ }
123
+ }
124
+ }
125
+
126
+
0 commit comments