Skip to content

Commit 6d3f719

Browse files
committed
Add hide topic hat option
1 parent ae738bf commit 6d3f719

File tree

5 files changed

+29
-10
lines changed

5 files changed

+29
-10
lines changed

Modules/Sources/AnalyticsClient/Events/TopicEvent.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import Foundation
99

1010
public enum TopicEvent: Event {
1111
case onRefresh
12-
case topicHatOpenButtonTapped
12+
case topicHatButtonTapped
1313
case topicPollOpenButtonTapped
1414
case userTapped(Int)
1515
case urlTapped(URL)

Modules/Sources/TopicFeature/Analytics/TopicFeature+Analytics.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,8 @@ extension TopicFeature {
4040
case .view(.onRefresh):
4141
analytics.log(TopicEvent.onRefresh)
4242

43-
case .view(.topicHatOpenButtonTapped):
44-
analytics.log(TopicEvent.topicHatOpenButtonTapped)
43+
case .view(.topicHatButtonTapped):
44+
analytics.log(TopicEvent.topicHatButtonTapped)
4545

4646
case .view(.topicPollOpenButtonTapped):
4747
analytics.log(TopicEvent.topicPollOpenButtonTapped)

Modules/Sources/TopicFeature/Resources/Localizable.xcstrings

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,16 @@
3131
}
3232
}
3333
},
34+
"Close Hat" : {
35+
"localizations" : {
36+
"ru" : {
37+
"stringUnit" : {
38+
"state" : "translated",
39+
"value" : "Закрыть шапку"
40+
}
41+
}
42+
}
43+
},
3444
"Copy Link" : {
3545
"localizations" : {
3646
"ru" : {

Modules/Sources/TopicFeature/TopicFeature.swift

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ public struct TopicFeature: Reducer, Sendable {
118118
case onNextAppear
119119
case onRefresh
120120
case finishedPostAnimation
121-
case topicHatOpenButtonTapped
121+
case topicHatButtonTapped(forOpen: Bool)
122122
case topicPollOpenButtonTapped
123123
case topicPollVoteButtonTapped([Int: Set<Int>])
124124
case changeKarmaTapped(Int, Bool)
@@ -226,11 +226,13 @@ public struct TopicFeature: Reducer, Sendable {
226226
case .view(.onRefresh):
227227
return .send(.internal(.refresh))
228228

229-
case .view(.topicHatOpenButtonTapped):
230-
guard let firstPost = state.topic?.posts.first else { fatalError("No Topic Hat Found") }
231-
let firstPostNodes = TopicNodeBuilder(text: firstPost.content, attachments: firstPost.attachments).build()
232-
state.posts[0] = UIPost(post: firstPost, content: firstPostNodes.map { .init(value: $0) })
233-
state.shouldShowTopicHatButton = false
229+
case .view(.topicHatButtonTapped(let forOpen)):
230+
if forOpen {
231+
guard let firstPost = state.topic?.posts.first else { fatalError("No Topic Hat Found") }
232+
let firstPostNodes = TopicNodeBuilder(text: firstPost.content, attachments: firstPost.attachments).build()
233+
state.posts[0] = UIPost(post: firstPost, content: firstPostNodes.map { .init(value: $0) })
234+
}
235+
state.shouldShowTopicHatButton = !forOpen
234236
return .none
235237

236238
case .view(.topicPollOpenButtonTapped):

Modules/Sources/TopicFeature/TopicScreen.swift

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,7 @@ public struct TopicScreen: View {
8888
}
8989
.padding(.bottom, 16)
9090
}
91+
.id(UUID().uuidString) // bugfix for Hat hiding
9192
._inScrollContentDetector(state: $navigationMinimized)
9293
.onAppear {
9394
scrollProxy = proxy
@@ -212,7 +213,7 @@ public struct TopicScreen: View {
212213

213214
if store.shouldShowTopicHatButton {
214215
Button {
215-
send(.topicHatOpenButtonTapped)
216+
send(.topicHatButtonTapped(forOpen: true))
216217
} label: {
217218
Text("Topic Hat", bundle: .module)
218219
.font(.headline)
@@ -435,6 +436,12 @@ public struct TopicScreen: View {
435436
ContextButton(text: LocalizedStringResource("Copy Link", bundle: .module), symbol: .docOnDoc) {
436437
send(.contextPostMenu(.copyLink(post.id)))
437438
}
439+
440+
if store.posts.first?.id == post.id, !store.pageNavigation.isFirstPage, !store.shouldShowTopicHatButton {
441+
ContextButton(text: LocalizedStringResource("Close Hat", bundle: .module), symbol: .eyeSlash) {
442+
send(.topicHatButtonTapped(forOpen: false))
443+
}
444+
}
438445
}
439446
} label: {
440447
Image(systemSymbol: .ellipsis)

0 commit comments

Comments
 (0)