Remove duplicate properties

This commit is contained in:
Nathan Mattes 2023-10-16 18:19:52 +02:00
parent 87cb71da5d
commit 3850c24b93
5 changed files with 17 additions and 22 deletions

View File

@ -91,7 +91,7 @@ extension StatusTableViewCell {
.store(in: &_disposeBag)
statusView.viewModel
.$translatedFromLanguage
.$translation
.receive(on: DispatchQueue.main)
.sink(receiveValue: { [weak self] _ in
self?.invalidateIntrinsicContentSize()

View File

@ -77,7 +77,7 @@ extension StatusThreadRootTableViewCell {
statusView.contentMetaText.textView.isSelectable = true
statusView.viewModel
.$translatedFromLanguage
.$translation
.receive(on: DispatchQueue.main)
.sink(receiveValue: { [weak self] _ in
self?.invalidateIntrinsicContentSize()

View File

@ -296,9 +296,7 @@ extension StatusView {
func configureTranslated(status: Status) {
guard let translation = viewModel.translation,
let translatedContent = translation.content,
let sourceLanguage = translation.sourceLanguage,
let provider = translation.provider else {
let translatedContent = translation.content else {
viewModel.isCurrentlyTranslating = false
return
}
@ -308,8 +306,6 @@ extension StatusView {
let content = MastodonContent(content: translatedContent, emojis: status.emojis.asDictionary)
let metaContent = try MastodonMetaContent.convert(document: content)
viewModel.content = metaContent
viewModel.translatedFromLanguage = sourceLanguage
viewModel.translatedUsingProvider = provider
viewModel.isCurrentlyTranslating = false
} catch {
assertionFailure(error.localizedDescription)
@ -329,7 +325,6 @@ extension StatusView {
let content = MastodonContent(content: statusEdit.content, emojis: statusEdit.emojis.asDictionary)
let metaContent = try MastodonMetaContent.convert(document: content)
viewModel.content = metaContent
viewModel.translatedFromLanguage = nil
viewModel.isCurrentlyTranslating = false
} catch {
assertionFailure(error.localizedDescription)
@ -364,7 +359,6 @@ extension StatusView {
let content = MastodonContent(content: status.content, emojis: status.emojis.asDictionary)
let metaContent = try MastodonMetaContent.convert(document: content)
viewModel.content = metaContent
viewModel.translatedFromLanguage = nil
viewModel.isCurrentlyTranslating = false
} catch {
assertionFailure(error.localizedDescription)

View File

@ -46,8 +46,6 @@ extension StatusView {
// Translation
@Published public var isCurrentlyTranslating = false
@Published public var translatedFromLanguage: String?
@Published public var translatedUsingProvider: String?
@Published public var translation: Mastodon.Entity.Translation? = nil
@Published public var timestamp: Date?
@ -149,8 +147,6 @@ extension StatusView {
isContentSensitive = false
isMediaSensitive = false
isSensitiveToggled = false
translatedFromLanguage = nil
translatedUsingProvider = nil
isCurrentlyTranslating = false
translation = nil
@ -879,15 +875,20 @@ extension StatusView.ViewModel {
.assign(to: \.toolbarActions, on: statusView)
.store(in: &disposeBag)
let translatedFromLabel = Publishers.CombineLatest($translatedFromLanguage, $translatedUsingProvider)
.map { (language, provider) -> String? in
if let language {
return L10n.Common.Controls.Status.Translation.translatedFrom(
Locale.current.localizedString(forIdentifier: language) ?? L10n.Common.Controls.Status.Translation.unknownLanguage,
provider ?? L10n.Common.Controls.Status.Translation.unknownProvider
)
let translatedFromLabel = $translation
.map { translation -> String? in
guard let translation else { return nil }
let provider = translation.provider ?? L10n.Common.Controls.Status.Translation.unknownProvider
let sourceLanguage: String
if let language = translation.sourceLanguage {
sourceLanguage = Locale.current.localizedString(forIdentifier: language) ?? L10n.Common.Controls.Status.Translation.unknownLanguage
} else {
sourceLanguage = L10n.Common.Controls.Status.Translation.unknownLanguage
}
return nil
return L10n.Common.Controls.Status.Translation.translatedFrom(sourceLanguage, provider)
}
translatedFromLabel

View File

@ -668,7 +668,7 @@ extension StatusView {
}
private var hideTranslationAction: UIAccessibilityCustomAction? {
guard viewModel.translatedFromLanguage != nil else { return nil }
guard viewModel.translation?.sourceLanguage != nil else { return nil }
return UIAccessibilityCustomAction(name: L10n.Common.Controls.Status.Translation.showOriginal) { [weak self] _ in
self?.revertTranslation()
return true