Move languages into Models

This commit is contained in:
Thomas Ricouard 2023-02-24 08:24:51 +01:00
parent 096e42b1c2
commit 63ff87f640
3 changed files with 15 additions and 15 deletions

View File

@ -44,7 +44,7 @@ class EditAccountViewModel: ObservableObject {
isBot = account.bot
isLocked = account.locked
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 {
isLoading = false
}

View File

@ -1,17 +1,17 @@
import Foundation
struct StatusEditorLanguage: Identifiable, Equatable {
var id: String { isoCode }
public struct Language: Identifiable, Equatable, Hashable {
public var id: String { isoCode }
let isoCode: String
let nativeName: String?
let localizedName: String?
public let isoCode: String
public let nativeName: 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 }
.map { lang in
let nativeLocale = Locale(languageComponents: Locale.Language.Components(languageCode: lang))
return StatusEditorLanguage(
return Language(
isoCode: lang.identifier,
nativeName: nativeLocale.localizedString(forLanguageCode: lang.identifier)?.capitalized,
localizedName: Locale.current.localizedString(forLanguageCode: lang.identifier)?.localizedCapitalized

View File

@ -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
HStack {
languageTextView(
@ -274,18 +274,18 @@ struct StatusEditorAccessoryView: View {
.font(.scaledCallout)
}
private var recentlyUsedLanguages: [StatusEditorLanguage] {
private var recentlyUsedLanguages: [Language] {
preferences.recentlyUsedLanguages.compactMap { isoCode in
StatusEditorLanguage.allAvailableLanguages.first { $0.isoCode == isoCode }
Language.allAvailableLanguages.first { $0.isoCode == isoCode }
}
}
private var otherLanguages: [StatusEditorLanguage] {
StatusEditorLanguage.allAvailableLanguages.filter { !preferences.recentlyUsedLanguages.contains($0.isoCode) }
private var otherLanguages: [Language] {
Language.allAvailableLanguages.filter { !preferences.recentlyUsedLanguages.contains($0.isoCode) }
}
private func languageSearchResult(query: String) -> [StatusEditorLanguage] {
StatusEditorLanguage.allAvailableLanguages.filter { language in
private func languageSearchResult(query: String) -> [Language] {
Language.allAvailableLanguages.filter { language in
guard !languageSearch.isEmpty else {
return true
}