Move languages into Models
This commit is contained in:
parent
096e42b1c2
commit
63ff87f640
|
@ -44,7 +44,7 @@ class EditAccountViewModel: ObservableObject {
|
||||||
isBot = account.bot
|
isBot = account.bot
|
||||||
isLocked = account.locked
|
isLocked = account.locked
|
||||||
isDiscoverable = account.discoverable ?? false
|
isDiscoverable = account.discoverable ?? false
|
||||||
fields = account.fields.map{ .init(name: $0.name, value: $0.value.asRawText )}
|
fields = account.source?.fields.map{ .init(name: $0.name, value: $0.value.asRawText) } ?? []
|
||||||
withAnimation {
|
withAnimation {
|
||||||
isLoading = false
|
isLoading = false
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,17 +1,17 @@
|
||||||
import Foundation
|
import Foundation
|
||||||
|
|
||||||
struct StatusEditorLanguage: Identifiable, Equatable {
|
public struct Language: Identifiable, Equatable, Hashable {
|
||||||
var id: String { isoCode }
|
public var id: String { isoCode }
|
||||||
|
|
||||||
let isoCode: String
|
public let isoCode: String
|
||||||
let nativeName: String?
|
public let nativeName: String?
|
||||||
let localizedName: String?
|
public let localizedName: String?
|
||||||
|
|
||||||
static var allAvailableLanguages: [StatusEditorLanguage] = Locale.LanguageCode.isoLanguageCodes
|
public static var allAvailableLanguages: [Language] = Locale.LanguageCode.isoLanguageCodes
|
||||||
.filter { $0.identifier.count == 2 }
|
.filter { $0.identifier.count == 2 }
|
||||||
.map { lang in
|
.map { lang in
|
||||||
let nativeLocale = Locale(languageComponents: Locale.Language.Components(languageCode: lang))
|
let nativeLocale = Locale(languageComponents: Locale.Language.Components(languageCode: lang))
|
||||||
return StatusEditorLanguage(
|
return Language(
|
||||||
isoCode: lang.identifier,
|
isoCode: lang.identifier,
|
||||||
nativeName: nativeLocale.localizedString(forLanguageCode: lang.identifier)?.capitalized,
|
nativeName: nativeLocale.localizedString(forLanguageCode: lang.identifier)?.capitalized,
|
||||||
localizedName: Locale.current.localizedString(forLanguageCode: lang.identifier)?.localizedCapitalized
|
localizedName: Locale.current.localizedString(forLanguageCode: lang.identifier)?.localizedCapitalized
|
|
@ -181,7 +181,7 @@ struct StatusEditorAccessoryView: View {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private func languageSheetSection(languages: [StatusEditorLanguage]) -> some View {
|
private func languageSheetSection(languages: [Language]) -> some View {
|
||||||
ForEach(languages) { language in
|
ForEach(languages) { language in
|
||||||
HStack {
|
HStack {
|
||||||
languageTextView(
|
languageTextView(
|
||||||
|
@ -274,18 +274,18 @@ struct StatusEditorAccessoryView: View {
|
||||||
.font(.scaledCallout)
|
.font(.scaledCallout)
|
||||||
}
|
}
|
||||||
|
|
||||||
private var recentlyUsedLanguages: [StatusEditorLanguage] {
|
private var recentlyUsedLanguages: [Language] {
|
||||||
preferences.recentlyUsedLanguages.compactMap { isoCode in
|
preferences.recentlyUsedLanguages.compactMap { isoCode in
|
||||||
StatusEditorLanguage.allAvailableLanguages.first { $0.isoCode == isoCode }
|
Language.allAvailableLanguages.first { $0.isoCode == isoCode }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private var otherLanguages: [StatusEditorLanguage] {
|
private var otherLanguages: [Language] {
|
||||||
StatusEditorLanguage.allAvailableLanguages.filter { !preferences.recentlyUsedLanguages.contains($0.isoCode) }
|
Language.allAvailableLanguages.filter { !preferences.recentlyUsedLanguages.contains($0.isoCode) }
|
||||||
}
|
}
|
||||||
|
|
||||||
private func languageSearchResult(query: String) -> [StatusEditorLanguage] {
|
private func languageSearchResult(query: String) -> [Language] {
|
||||||
StatusEditorLanguage.allAvailableLanguages.filter { language in
|
Language.allAvailableLanguages.filter { language in
|
||||||
guard !languageSearch.isEmpty else {
|
guard !languageSearch.isEmpty else {
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue