diff --git a/Modules/Sources/AnalyticsClient/Events/TopicEvent.swift b/Modules/Sources/AnalyticsClient/Events/TopicEvent.swift index 4a89bb40..aad4394c 100644 --- a/Modules/Sources/AnalyticsClient/Events/TopicEvent.swift +++ b/Modules/Sources/AnalyticsClient/Events/TopicEvent.swift @@ -9,7 +9,7 @@ import Foundation public enum TopicEvent: Event { case onRefresh - case topicHatOpenButtonTapped + case topicHatButtonTapped case topicPollOpenButtonTapped case userTapped(Int) case urlTapped(URL) diff --git a/Modules/Sources/TopicFeature/Analytics/TopicFeature+Analytics.swift b/Modules/Sources/TopicFeature/Analytics/TopicFeature+Analytics.swift index 1f5736d6..2fbf4679 100644 --- a/Modules/Sources/TopicFeature/Analytics/TopicFeature+Analytics.swift +++ b/Modules/Sources/TopicFeature/Analytics/TopicFeature+Analytics.swift @@ -40,8 +40,8 @@ extension TopicFeature { case .view(.onRefresh): analytics.log(TopicEvent.onRefresh) - case .view(.topicHatOpenButtonTapped): - analytics.log(TopicEvent.topicHatOpenButtonTapped) + case .view(.topicHatButtonTapped): + analytics.log(TopicEvent.topicHatButtonTapped) case .view(.topicPollOpenButtonTapped): analytics.log(TopicEvent.topicPollOpenButtonTapped) diff --git a/Modules/Sources/TopicFeature/Resources/Localizable.xcstrings b/Modules/Sources/TopicFeature/Resources/Localizable.xcstrings index 2f3c13fb..03ce6230 100644 --- a/Modules/Sources/TopicFeature/Resources/Localizable.xcstrings +++ b/Modules/Sources/TopicFeature/Resources/Localizable.xcstrings @@ -31,6 +31,16 @@ } } }, + "Close Hat" : { + "localizations" : { + "ru" : { + "stringUnit" : { + "state" : "translated", + "value" : "Закрыть шапку" + } + } + } + }, "Copy Link" : { "localizations" : { "ru" : { diff --git a/Modules/Sources/TopicFeature/TopicFeature.swift b/Modules/Sources/TopicFeature/TopicFeature.swift index 0df05793..1b09c238 100644 --- a/Modules/Sources/TopicFeature/TopicFeature.swift +++ b/Modules/Sources/TopicFeature/TopicFeature.swift @@ -118,7 +118,7 @@ public struct TopicFeature: Reducer, Sendable { case onNextAppear case onRefresh case finishedPostAnimation - case topicHatOpenButtonTapped + case topicHatButtonTapped(forOpen: Bool) case topicPollOpenButtonTapped case topicPollVoteButtonTapped([Int: Set]) case changeKarmaTapped(Int, Bool) @@ -226,11 +226,13 @@ public struct TopicFeature: Reducer, Sendable { case .view(.onRefresh): return .send(.internal(.refresh)) - case .view(.topicHatOpenButtonTapped): - guard let firstPost = state.topic?.posts.first else { fatalError("No Topic Hat Found") } - let firstPostNodes = TopicNodeBuilder(text: firstPost.content, attachments: firstPost.attachments).build() - state.posts[0] = UIPost(post: firstPost, content: firstPostNodes.map { .init(value: $0) }) - state.shouldShowTopicHatButton = false + case .view(.topicHatButtonTapped(let forOpen)): + if forOpen { + guard let firstPost = state.topic?.posts.first else { fatalError("No Topic Hat Found") } + let firstPostNodes = TopicNodeBuilder(text: firstPost.content, attachments: firstPost.attachments).build() + state.posts[0] = UIPost(post: firstPost, content: firstPostNodes.map { .init(value: $0) }) + } + state.shouldShowTopicHatButton = !forOpen return .none case .view(.topicPollOpenButtonTapped): diff --git a/Modules/Sources/TopicFeature/TopicScreen.swift b/Modules/Sources/TopicFeature/TopicScreen.swift index 7e2e2cea..8caab3cd 100644 --- a/Modules/Sources/TopicFeature/TopicScreen.swift +++ b/Modules/Sources/TopicFeature/TopicScreen.swift @@ -88,6 +88,7 @@ public struct TopicScreen: View { } .padding(.bottom, 16) } + .id(UUID().uuidString) // bugfix for Hat hiding ._inScrollContentDetector(state: $navigationMinimized) .onAppear { scrollProxy = proxy @@ -212,7 +213,7 @@ public struct TopicScreen: View { if store.shouldShowTopicHatButton { Button { - send(.topicHatOpenButtonTapped) + send(.topicHatButtonTapped(forOpen: true)) } label: { Text("Topic Hat", bundle: .module) .font(.headline) @@ -435,6 +436,12 @@ public struct TopicScreen: View { ContextButton(text: LocalizedStringResource("Copy Link", bundle: .module), symbol: .docOnDoc) { send(.contextPostMenu(.copyLink(post.id))) } + + if store.posts.first?.id == post.id, !store.pageNavigation.isFirstPage, !store.shouldShowTopicHatButton { + ContextButton(text: LocalizedStringResource("Close Hat", bundle: .module), symbol: .eyeSlash) { + send(.topicHatButtonTapped(forOpen: false)) + } + } } } label: { Image(systemSymbol: .ellipsis)