@@ -45,6 +45,11 @@ public struct TopicScreen: View {
4545 return shouldShow && ( !isLiquidGlass || !isAnyFloatingNavigationEnabled)
4646 }
4747
48+ private var isPollAvailable : Bool {
49+ let topicLoaded = store. topic != nil && !store. isLoadingTopic
50+ return topicLoaded && store. topic!. poll != nil
51+ }
52+
4853 // MARK: - Init
4954
5055 public init ( store: StoreOf < TopicFeature > ) {
@@ -68,9 +73,12 @@ public struct TopicScreen: View {
6873 }
6974
7075 if !store. isLoadingTopic {
76+ Header ( )
77+
7178 if let poll = store. topic!. poll {
7279 Poll ( poll)
7380 }
81+
7482 PostList ( )
7583 }
7684
@@ -187,29 +195,50 @@ public struct TopicScreen: View {
187195 }
188196 }
189197
190- // MARK: - Poll
198+ // MARK: - Header
191199
192200 @ViewBuilder
193- private func Poll ( _ poll : Topic . Poll ) -> some View {
194- VStack ( spacing : 0 ) {
195- if store. shouldShowTopicPollButton {
201+ private func Header ( ) -> some View {
202+ HStack {
203+ if isPollAvailable , store. shouldShowTopicPollButton {
196204 Button {
197205 send ( . topicPollOpenButtonTapped)
198206 } label: {
199207 Text ( " Poll " , bundle: . module)
200208 . font ( . headline)
201209 . bold ( )
202- . padding ( 16 )
203210 }
204- } else {
211+ }
212+
213+ if store. shouldShowTopicHatButton {
214+ Button {
215+ send ( . topicHatOpenButtonTapped)
216+ } label: {
217+ Text ( " Topic Hat " , bundle: . module)
218+ . font ( . headline)
219+ . bold ( )
220+ }
221+ }
222+ }
223+ }
224+
225+ // MARK: - Poll
226+
227+ @ViewBuilder
228+ private func Poll( _ poll: Topic . Poll ) -> some View {
229+ VStack ( spacing: 0 ) {
230+ if !store. shouldShowTopicPollButton {
231+ if store. shouldShowTopicHatButton {
232+ PostSeparator ( )
233+ }
234+
205235 PollView ( poll: poll, onVoteButtonTapped: { selections in
206236 send ( . topicPollVoteButtonTapped( selections) )
207237 } )
238+ . padding ( . top, store. shouldShowTopicHatButton ? 16 : 0 )
208239 }
209240
210- Rectangle ( )
211- . foregroundStyle ( Color ( . Separator. post) )
212- . frame ( height: 10 )
241+ PostSeparator ( )
213242 }
214243 }
215244
@@ -219,30 +248,30 @@ public struct TopicScreen: View {
219248 private func PostList( ) -> some View {
220249 ForEach ( store. posts) { post in
221250 WithPerceptionTracking {
222- VStack ( spacing: 0 ) {
223- if store. shouldShowTopicHatButton && store. posts. first == post {
224- Button {
225- send ( . topicHatOpenButtonTapped)
226- } label: {
227- Text ( " Topic Hat " , bundle: . module)
228- . font ( . headline)
229- . bold ( )
230- . padding ( 16 )
231- }
232- } else {
251+ if store. shouldShowTopicHatButton && store. posts. first == post {
252+ if !isPollAvailable {
253+ PostSeparator ( )
254+ }
255+ } else {
256+ VStack ( spacing: 0 ) {
233257 Post ( post)
234258 . padding ( . horizontal, 16 )
235259 . padding ( . bottom, 16 )
260+
261+ PostSeparator ( )
236262 }
237-
238- Rectangle ( )
239- . foregroundStyle ( Color ( . Separator. post) )
240- . frame ( height: 10 )
241263 }
242264 }
243265 }
244266 }
245267
268+ @ViewBuilder
269+ private func PostSeparator( ) -> some View {
270+ Rectangle ( )
271+ . foregroundStyle ( Color ( . Separator. post) )
272+ . frame ( height: 10 )
273+ }
274+
246275 // MARK: - Post
247276
248277 @ViewBuilder
0 commit comments