commit 1fd4d4d95025594ad9cc09514ef257c235073d84
parent 7d406fd75fa5a68f4e1da9a9ccdaad2192482069
Author: William Casarin <jb55@jb55.com>
Date: Thu, 2 Feb 2023 13:53:57 -0800
refactor: move translate button into its own view
Diffstat:
1 file changed, 40 insertions(+), 29 deletions(-)
diff --git a/damus/Views/NoteContentView.swift b/damus/Views/NoteContentView.swift
@@ -87,6 +87,35 @@ struct NoteContentView: View {
@EnvironmentObject var user_settings: UserSettingsStore
+ var TranslateButton: some View {
+ Group {
+ let languageName = Locale.current.localizedString(forLanguageCode: noteLanguage!)
+ if show_translated_note {
+ if checkingTranslationStatus {
+ Button(NSLocalizedString("Translating from \(languageName!)...", comment: "Button to indicate that the note is in the process of being translated from a different language.")) {
+ show_translated_note = false
+ }
+ .translate_button_style()
+
+ } else if translated_artifacts != nil {
+ Button(NSLocalizedString("Translated from \(languageName!)", comment: "Button to indicate that the note has been translated from a different language.")) {
+ show_translated_note = false
+ }
+ .translate_button_style()
+
+ Text(translated_artifacts!.content)
+ .font(eventviewsize_to_font(size))
+ .fixedSize(horizontal: false, vertical: true)
+ }
+ } else {
+ Button(NSLocalizedString("Translate Note", comment: "Button to translate note from different language.")) {
+ show_translated_note = true
+ }
+ .translate_button_style()
+ }
+ }
+ }
+
func MainContent() -> some View {
return VStack(alignment: .leading) {
Text(artifacts.content)
@@ -94,35 +123,7 @@ struct NoteContentView: View {
.fixedSize(horizontal: false, vertical: true)
if size == .selected && noteLanguage != nil && noteLanguage != currentLanguage {
- let languageName = Locale.current.localizedString(forLanguageCode: noteLanguage!)
- if show_translated_note {
- if checkingTranslationStatus {
- Button(NSLocalizedString("Translating from \(languageName!)...", comment: "Button to indicate that the note is in the process of being translated from a different language.")) {
- show_translated_note = false
- }
- .font(.footnote)
- .contentShape(Rectangle())
- .padding(.top, 10)
- } else if translated_artifacts != nil {
- Button(NSLocalizedString("Translated from \(languageName!)", comment: "Button to indicate that the note has been translated from a different language.")) {
- show_translated_note = false
- }
- .font(.footnote)
- .contentShape(Rectangle())
- .padding(.top, 10)
-
- Text(translated_artifacts!.content)
- .font(eventviewsize_to_font(size))
- .fixedSize(horizontal: false, vertical: true)
- }
- } else {
- Button(NSLocalizedString("Translate Note", comment: "Button to translate note from different language.")) {
- show_translated_note = true
- }
- .font(.footnote)
- .contentShape(Rectangle())
- .padding(.top, 10)
- }
+ TranslateButton
}
if show_images && artifacts.images.count > 0 {
@@ -374,3 +375,13 @@ struct NoteContentView_Previews: PreviewProvider {
NoteContentView(privkey: "", event: NostrEvent(content: content, pubkey: "pk"), profiles: state.profiles, previews: PreviewCache(), show_images: true, artifacts: artifacts, size: .normal)
}
}
+
+
+extension View {
+ func translate_button_style() -> some View {
+ return self
+ .font(.footnote)
+ .contentShape(Rectangle())
+ .padding([.top, .bottom], 10)
+ }
+}