Add menu-action to untranslate a translated status (IOS-103)

This commit is contained in:
Nathan Mattes 2023-06-02 18:31:00 +02:00
parent d455da85d2
commit 7b08403035
5 changed files with 29 additions and 5 deletions

View File

@ -385,6 +385,9 @@ extension DataSourceFacade {
destination: .topLevel)
_ = dependency.coordinator.present(scene: .editStatus(viewModel: editStatusViewModel), transition: .modal(animated: true))
case .showOriginal:
// do nothing, as the translation is reverted in `StatusTableViewCellDelegate` in `DataSourceProvider+StatusTableViewCellDelegate.swift`.
break
case .followUser(_):
guard let author = menuContext.author else { return }

View File

@ -496,6 +496,14 @@ extension StatusTableViewCellDelegate where Self: DataSourceProvider & AuthConte
cell.invalidateIntrinsicContentSize()
}
}
if case .showOriginal = action {
DispatchQueue.main.async {
if let cell = cell as? StatusTableViewCell {
cell.statusView.revertTranslation()
}
}
}
try await DataSourceFacade.responseToMenuAction(
dependency: self,

View File

@ -166,10 +166,12 @@ extension StatusAuthorView {
postActions.append(.editStatus)
}
if let statusLanguage = menuContext.statusLanguage, menuContext.isTranslationEnabled, !menuContext.isTranslated {
postActions.append(
.translateStatus(.init(language: statusLanguage))
)
if let statusLanguage = menuContext.statusLanguage, menuContext.isTranslationEnabled {
if menuContext.isTranslated == false {
postActions.append(.translateStatus(.init(language: statusLanguage)))
} else {
postActions.append(.showOriginal)
}
}
postActions.append(.bookmarkStatus(.init(isBookmarking: menuContext.isBookmarking)))

View File

@ -290,7 +290,7 @@ extension StatusView {
viewModel.applicationName = applicationName
}
func revertTranslation() {
public func revertTranslation() {
guard let originalStatus = viewModel.originalStatus else { return }
viewModel.translatedFromLanguage = nil

View File

@ -48,6 +48,7 @@ public enum MastodonMenu {
extension MastodonMenu {
public enum Action {
case translateStatus(TranslateStatusActionContext)
case showOriginal
case muteUser(MuteUserActionContext)
case blockUser(BlockUserActionContext)
case reportUser(ReportUserActionContext)
@ -161,6 +162,16 @@ extension MastodonMenu {
delegate.menuAction(self)
}
return translateAction
case .showOriginal:
let action = LabeledAction(
title: L10n.Common.Controls.Status.Translation.showOriginal,
image: UIImage(systemName: "character.book.closed")
) { [weak delegate] in
guard let delegate = delegate else { return }
delegate.menuAction(self)
}
return action
case .editStatus:
let editStatusAction = LabeledAction(
title: L10n.Common.Controls.Actions.editPost,