Profile edit: Add metadata editing
This commit is contained in:
parent
a14e1b5417
commit
096e42b1c2
|
@ -252,6 +252,12 @@
|
|||
"account.edit.post-settings.privacy" = "Прыватнасць па змаўчанні";
|
||||
"account.edit.post-settings.section-title" = "Налады допісу";
|
||||
"account.edit.post-settings.sensitive" = "Адчувальны змест";
|
||||
|
||||
"account.edit.metadata-section-title" = "Profile Metadata";
|
||||
"account.edit.metadata-name-placeholder" = "Label";
|
||||
"account.edit.metadata-value-placeholder" = "Content";
|
||||
"account.edit.add-metadata-button" = "Add a new metadata";
|
||||
|
||||
"account.favorited-by" = "Улюбёны";
|
||||
"account.follow.follow" = "Сачыць";
|
||||
"account.follow.following" = "Адсочваю";
|
||||
|
|
|
@ -246,6 +246,12 @@
|
|||
"account.edit.post-settings.privacy" = " Privadesa per defecte";
|
||||
"account.edit.post-settings.section-title" = "Configuració de les publicacions";
|
||||
"account.edit.post-settings.sensitive" = "Contingut sensible";
|
||||
|
||||
"account.edit.metadata-section-title" = "Profile Metadata";
|
||||
"account.edit.metadata-name-placeholder" = "Label";
|
||||
"account.edit.metadata-value-placeholder" = "Content";
|
||||
"account.edit.add-metadata-button" = "Add a new metadata";
|
||||
|
||||
"account.favorited-by" = "Marcat com a favorit per";
|
||||
"account.follow.follow" = "Segueix";
|
||||
"account.follow.following" = "Seguint";
|
||||
|
|
|
@ -247,6 +247,12 @@
|
|||
"account.edit.post-settings.privacy" = "Standard-Sichtbarkeit";
|
||||
"account.edit.post-settings.section-title" = "Beitragseinstellungen";
|
||||
"account.edit.post-settings.sensitive" = "Sensibler Inhalt";
|
||||
|
||||
"account.edit.metadata-section-title" = "Profile Metadata";
|
||||
"account.edit.metadata-name-placeholder" = "Label";
|
||||
"account.edit.metadata-value-placeholder" = "Content";
|
||||
"account.edit.add-metadata-button" = "Add a new metadata";
|
||||
|
||||
"account.favorited-by" = "Favorisiert von";
|
||||
"account.follow.follow" = "Folgen";
|
||||
"account.follow.following" = "Entfolgen";
|
||||
|
|
|
@ -249,6 +249,12 @@
|
|||
"account.edit.post-settings.privacy" = "Default privacy";
|
||||
"account.edit.post-settings.section-title" = "Post settings";
|
||||
"account.edit.post-settings.sensitive" = "Sensitive content";
|
||||
|
||||
"account.edit.metadata-section-title" = "Profile Metadata";
|
||||
"account.edit.metadata-name-placeholder" = "Label";
|
||||
"account.edit.metadata-value-placeholder" = "Content";
|
||||
"account.edit.add-metadata-button" = "Add a new metadata";
|
||||
|
||||
"account.favorited-by" = "Favourited by";
|
||||
"account.follow.follow" = "Follow";
|
||||
"account.follow.following" = "Following";
|
||||
|
|
|
@ -248,6 +248,12 @@
|
|||
"account.edit.post-settings.privacy" = "Default privacy";
|
||||
"account.edit.post-settings.section-title" = "Post settings";
|
||||
"account.edit.post-settings.sensitive" = "Sensitive content";
|
||||
|
||||
"account.edit.metadata-section-title" = "Profile Metadata";
|
||||
"account.edit.metadata-name-placeholder" = "Label";
|
||||
"account.edit.metadata-value-placeholder" = "Content";
|
||||
"account.edit.add-metadata-button" = "Add a new metadata";
|
||||
|
||||
"account.favorited-by" = "Favorited by";
|
||||
"account.follow.follow" = "Follow";
|
||||
"account.follow.following" = "Following";
|
||||
|
|
|
@ -248,6 +248,12 @@
|
|||
"account.edit.post-settings.privacy" = "Privacidad por defecto";
|
||||
"account.edit.post-settings.section-title" = "Ajustes de publicaciones";
|
||||
"account.edit.post-settings.sensitive" = "Contenido sensible";
|
||||
|
||||
"account.edit.metadata-section-title" = "Profile Metadata";
|
||||
"account.edit.metadata-name-placeholder" = "Label";
|
||||
"account.edit.metadata-value-placeholder" = "Content";
|
||||
"account.edit.add-metadata-button" = "Add a new metadata";
|
||||
|
||||
"account.favorited-by" = "Marcado como favorito por";
|
||||
"account.follow.follow" = "Seguir";
|
||||
"account.follow.following" = "Siguiendo";
|
||||
|
|
|
@ -247,6 +247,12 @@
|
|||
"account.edit.post-settings.privacy" = "Defektuzko pribatutasuna";
|
||||
"account.edit.post-settings.section-title" = "Bidalketen ezarpenak";
|
||||
"account.edit.post-settings.sensitive" = "Eduki hunkigarria";
|
||||
|
||||
"account.edit.metadata-section-title" = "Profile Metadata";
|
||||
"account.edit.metadata-name-placeholder" = "Label";
|
||||
"account.edit.metadata-value-placeholder" = "Content";
|
||||
"account.edit.add-metadata-button" = "Add a new metadata";
|
||||
|
||||
"account.favorited-by" = "Hauek gogoko egin dute:";
|
||||
"account.follow.follow" = "Jarraitu";
|
||||
"account.follow.following" = "Jarraitzen";
|
||||
|
|
|
@ -247,6 +247,12 @@
|
|||
"account.edit.post-settings.privacy" = "Confidentialité par défaut";
|
||||
"account.edit.post-settings.section-title" = "Paramètres des publications";
|
||||
"account.edit.post-settings.sensitive" = "Contenu sensible";
|
||||
|
||||
"account.edit.metadata-section-title" = "Profile Metadata";
|
||||
"account.edit.metadata-name-placeholder" = "Label";
|
||||
"account.edit.metadata-value-placeholder" = "Content";
|
||||
"account.edit.add-metadata-button" = "Add a new metadata";
|
||||
|
||||
"account.favorited-by" = "Favorisé par";
|
||||
"account.follow.follow" = "Suivre";
|
||||
"account.follow.following" = "Suivi";
|
||||
|
|
|
@ -247,6 +247,12 @@
|
|||
"account.edit.post-settings.privacy" = "Privacy di default";
|
||||
"account.edit.post-settings.section-title" = "Impostazioni post";
|
||||
"account.edit.post-settings.sensitive" = "Contenuto sensibile";
|
||||
|
||||
"account.edit.metadata-section-title" = "Profile Metadata";
|
||||
"account.edit.metadata-name-placeholder" = "Label";
|
||||
"account.edit.metadata-value-placeholder" = "Content";
|
||||
"account.edit.add-metadata-button" = "Add a new metadata";
|
||||
|
||||
"account.favorited-by" = "Tra i preferiti di";
|
||||
"account.follow.follow" = "Segui";
|
||||
"account.follow.following" = "Segui già";
|
||||
|
|
|
@ -247,6 +247,12 @@
|
|||
"account.edit.post-settings.privacy" = "デフォルトのプライバシー";
|
||||
"account.edit.post-settings.section-title" = "投稿設定";
|
||||
"account.edit.post-settings.sensitive" = "センシティブな内容";
|
||||
|
||||
"account.edit.metadata-section-title" = "Profile Metadata";
|
||||
"account.edit.metadata-name-placeholder" = "Label";
|
||||
"account.edit.metadata-value-placeholder" = "Content";
|
||||
"account.edit.add-metadata-button" = "Add a new metadata";
|
||||
|
||||
"account.favorited-by" = "お気に入りされた";
|
||||
"account.follow.follow" = "フォロー";
|
||||
"account.follow.following" = "フォロー中";
|
||||
|
|
|
@ -248,6 +248,12 @@
|
|||
"account.edit.post-settings.privacy" = "기본 공개 범위";
|
||||
"account.edit.post-settings.section-title" = "글 설정";
|
||||
"account.edit.post-settings.sensitive" = "민감한 콘텐츠";
|
||||
|
||||
"account.edit.metadata-section-title" = "Profile Metadata";
|
||||
"account.edit.metadata-name-placeholder" = "Label";
|
||||
"account.edit.metadata-value-placeholder" = "Content";
|
||||
"account.edit.add-metadata-button" = "Add a new metadata";
|
||||
|
||||
"account.favorited-by" = "좋아요한 사용자";
|
||||
"account.follow.follow" = "팔로우";
|
||||
"account.follow.following" = "팔로우 중";
|
||||
|
|
|
@ -247,6 +247,12 @@
|
|||
"account.edit.post-settings.privacy" = "Standard personvern";
|
||||
"account.edit.post-settings.section-title" = "Innstillinger for innlegg";
|
||||
"account.edit.post-settings.sensitive" = "Sensitivt innhold";
|
||||
|
||||
"account.edit.metadata-section-title" = "Profile Metadata";
|
||||
"account.edit.metadata-name-placeholder" = "Label";
|
||||
"account.edit.metadata-value-placeholder" = "Content";
|
||||
"account.edit.add-metadata-button" = "Add a new metadata";
|
||||
|
||||
"account.favorited-by" = "Favoritt av";
|
||||
"account.follow.follow" = "Følg";
|
||||
"account.follow.following" = "Følger";
|
||||
|
|
|
@ -244,6 +244,12 @@
|
|||
"account.edit.post-settings.privacy" = "Standaardprivacy";
|
||||
"account.edit.post-settings.section-title" = "Postinstellingen";
|
||||
"account.edit.post-settings.sensitive" = "Gevoelige inhoud";
|
||||
|
||||
"account.edit.metadata-section-title" = "Profile Metadata";
|
||||
"account.edit.metadata-name-placeholder" = "Label";
|
||||
"account.edit.metadata-value-placeholder" = "Content";
|
||||
"account.edit.add-metadata-button" = "Add a new metadata";
|
||||
|
||||
"account.favorited-by" = "Gefavoriet";
|
||||
"account.follow.follow" = "Volg";
|
||||
"account.follow.following" = "Volgend";
|
||||
|
|
|
@ -245,6 +245,12 @@
|
|||
"account.edit.post-settings.privacy" = "Prywatność domyślna";
|
||||
"account.edit.post-settings.section-title" = "Ustawienia postów";
|
||||
"account.edit.post-settings.sensitive" = "Treści wrażliwe";
|
||||
|
||||
"account.edit.metadata-section-title" = "Profile Metadata";
|
||||
"account.edit.metadata-name-placeholder" = "Label";
|
||||
"account.edit.metadata-value-placeholder" = "Content";
|
||||
"account.edit.add-metadata-button" = "Add a new metadata";
|
||||
|
||||
"account.favorited-by" = "Polubione przez";
|
||||
"account.follow.follow" = "Obserwuj";
|
||||
"account.follow.following" = "Obserwuję";
|
||||
|
|
|
@ -247,6 +247,12 @@
|
|||
"account.edit.post-settings.privacy" = "Privacidade padrão";
|
||||
"account.edit.post-settings.section-title" = "Configuração de postagem";
|
||||
"account.edit.post-settings.sensitive" = "Conteúdo Sensível";
|
||||
|
||||
"account.edit.metadata-section-title" = "Profile Metadata";
|
||||
"account.edit.metadata-name-placeholder" = "Label";
|
||||
"account.edit.metadata-value-placeholder" = "Content";
|
||||
"account.edit.add-metadata-button" = "Add a new metadata";
|
||||
|
||||
"account.favorited-by" = "Favoritado por";
|
||||
"account.follow.follow" = "Seguir";
|
||||
"account.follow.following" = "Seguindo";
|
||||
|
|
|
@ -247,6 +247,12 @@
|
|||
"account.edit.post-settings.privacy" = "Varsayılan gizlilik";
|
||||
"account.edit.post-settings.section-title" = "Gönderi ayarları";
|
||||
"account.edit.post-settings.sensitive" = "Hassas içerik";
|
||||
|
||||
"account.edit.metadata-section-title" = "Profile Metadata";
|
||||
"account.edit.metadata-name-placeholder" = "Label";
|
||||
"account.edit.metadata-value-placeholder" = "Content";
|
||||
"account.edit.add-metadata-button" = "Add a new metadata";
|
||||
|
||||
"account.favorited-by" = "Şunlar tarafından favorilendi";
|
||||
"account.follow.follow" = "Takip Et";
|
||||
"account.follow.following" = "Takip Edilen";
|
||||
|
|
|
@ -248,6 +248,12 @@
|
|||
"account.edit.post-settings.privacy" = "Приватність за замовчуванням";
|
||||
"account.edit.post-settings.section-title" = "Налаштування допису";
|
||||
"account.edit.post-settings.sensitive" = "Делікатний вміст";
|
||||
|
||||
"account.edit.metadata-section-title" = "Profile Metadata";
|
||||
"account.edit.metadata-name-placeholder" = "Label";
|
||||
"account.edit.metadata-value-placeholder" = "Content";
|
||||
"account.edit.add-metadata-button" = "Add a new metadata";
|
||||
|
||||
"account.favorited-by" = "Вподобали";
|
||||
"account.follow.follow" = "Підписатися";
|
||||
"account.follow.following" = "Підписаний";
|
||||
|
|
|
@ -245,6 +245,12 @@
|
|||
"account.edit.post-settings.privacy" = "默认隐私设置";
|
||||
"account.edit.post-settings.section-title" = "嘟文设置";
|
||||
"account.edit.post-settings.sensitive" = "敏感内容";
|
||||
|
||||
"account.edit.metadata-section-title" = "Profile Metadata";
|
||||
"account.edit.metadata-name-placeholder" = "Label";
|
||||
"account.edit.metadata-value-placeholder" = "Content";
|
||||
"account.edit.add-metadata-button" = "Add a new metadata";
|
||||
|
||||
"account.favorited-by" = "同样喜欢的有";
|
||||
"account.follow.follow" = "关注";
|
||||
"account.follow.following" = "正在关注";
|
||||
|
|
|
@ -19,12 +19,14 @@ public struct EditAccountView: View {
|
|||
loadingSection
|
||||
} else {
|
||||
aboutSections
|
||||
fieldsSection
|
||||
postSettingsSection
|
||||
accountSection
|
||||
}
|
||||
}
|
||||
.scrollContentBackground(.hidden)
|
||||
.background(theme.secondaryBackgroundColor)
|
||||
.scrollDismissesKeyboard(.immediately)
|
||||
.navigationTitle("account.edit.navigation-title")
|
||||
.navigationBarTitleDisplayMode(.inline)
|
||||
.toolbar {
|
||||
|
@ -98,6 +100,33 @@ public struct EditAccountView: View {
|
|||
.listRowBackground(theme.primaryBackgroundColor)
|
||||
}
|
||||
|
||||
private var fieldsSection: some View {
|
||||
Section("account.edit.metadata-section-title") {
|
||||
ForEach($viewModel.fields) { $field in
|
||||
VStack(alignment: .leading) {
|
||||
TextField("account.edit.metadata-name-placeholder", text: $field.name)
|
||||
TextField("account.edit.metadata-value-placeholder", text: $field.value)
|
||||
}
|
||||
}
|
||||
.onDelete { indexes in
|
||||
if let index = indexes.first {
|
||||
viewModel.fields.remove(at: index)
|
||||
}
|
||||
}
|
||||
if viewModel.fields.count < 4 {
|
||||
Button {
|
||||
withAnimation {
|
||||
viewModel.fields.append(.init(name: "", value: ""))
|
||||
}
|
||||
} label: {
|
||||
Text("account.edit.add-metadata-button")
|
||||
.foregroundColor(theme.tintColor)
|
||||
}
|
||||
}
|
||||
}
|
||||
.listRowBackground(theme.primaryBackgroundColor)
|
||||
}
|
||||
|
||||
@ToolbarContentBuilder
|
||||
private var toolbarContent: some ToolbarContent {
|
||||
ToolbarItem(placement: .navigationBarLeading) {
|
||||
|
|
|
@ -4,6 +4,18 @@ import SwiftUI
|
|||
|
||||
@MainActor
|
||||
class EditAccountViewModel: ObservableObject {
|
||||
|
||||
class FieldEditViewModel: ObservableObject, Identifiable {
|
||||
let id = UUID().uuidString
|
||||
@Published var name: String = ""
|
||||
@Published var value: String = ""
|
||||
|
||||
init(name: String, value: String) {
|
||||
self.name = name
|
||||
self.value = value
|
||||
}
|
||||
}
|
||||
|
||||
public var client: Client?
|
||||
|
||||
@Published var displayName: String = ""
|
||||
|
@ -13,6 +25,7 @@ class EditAccountViewModel: ObservableObject {
|
|||
@Published var isBot: Bool = false
|
||||
@Published var isLocked: Bool = false
|
||||
@Published var isDiscoverable: Bool = false
|
||||
@Published var fields: [FieldEditViewModel] = []
|
||||
|
||||
@Published var isLoading: Bool = true
|
||||
@Published var isSaving: Bool = false
|
||||
|
@ -31,6 +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 )}
|
||||
withAnimation {
|
||||
isLoading = false
|
||||
}
|
||||
|
@ -40,14 +54,14 @@ class EditAccountViewModel: ObservableObject {
|
|||
func save() async {
|
||||
isSaving = true
|
||||
do {
|
||||
let response =
|
||||
try await client?.patch(endpoint: Accounts.updateCredentials(displayName: displayName,
|
||||
let data = UpdateCredentialsData(displayName: displayName,
|
||||
note: note,
|
||||
privacy: postPrivacy,
|
||||
isSensitive: isSensitive,
|
||||
isBot: isBot,
|
||||
isLocked: isLocked,
|
||||
isDiscoverable: isDiscoverable))
|
||||
source: .init(privacy: postPrivacy, sensitive: isSensitive),
|
||||
bot: isBot,
|
||||
locked: isLocked,
|
||||
discoverable: isDiscoverable,
|
||||
fieldsAttributes: fields.map{ .init(name: $0.name, value: $0.value)})
|
||||
let response = try await client?.patch(endpoint: Accounts.updateCredentials(json: data))
|
||||
if response?.statusCode != 200 {
|
||||
saveError = true
|
||||
}
|
||||
|
|
|
@ -13,7 +13,8 @@ public final class Account: Codable, Identifiable, Hashable, Sendable, Equatable
|
|||
lhs.fields == rhs.fields &&
|
||||
lhs.lastStatusAt == rhs.lastStatusAt &&
|
||||
lhs.discoverable == rhs.discoverable &&
|
||||
lhs.bot == rhs.bot
|
||||
lhs.bot == rhs.bot &&
|
||||
lhs.locked == rhs.locked
|
||||
}
|
||||
|
||||
public func hash(into hasher: inout Hasher) {
|
||||
|
|
|
@ -8,13 +8,7 @@ public enum Accounts: Endpoint {
|
|||
case followedTags
|
||||
case featuredTags(id: String)
|
||||
case verifyCredentials
|
||||
case updateCredentials(displayName: String,
|
||||
note: String,
|
||||
privacy: Visibility,
|
||||
isSensitive: Bool,
|
||||
isBot: Bool,
|
||||
isLocked: Bool,
|
||||
isDiscoverable: Bool)
|
||||
case updateCredentials(json: UpdateCredentialsData)
|
||||
case statuses(id: String,
|
||||
sinceId: String?,
|
||||
tag: String?,
|
||||
|
@ -126,17 +120,6 @@ public enum Accounts: Endpoint {
|
|||
case let .bookmarks(sinceId):
|
||||
guard let sinceId else { return nil }
|
||||
return [.init(name: "max_id", value: sinceId)]
|
||||
case let .updateCredentials(displayName, note, privacy,
|
||||
isSensitive, isBot, isLocked, isDiscoverable):
|
||||
var params: [URLQueryItem] = []
|
||||
params.append(.init(name: "display_name", value: displayName))
|
||||
params.append(.init(name: "note", value: note))
|
||||
params.append(.init(name: "source[privacy]", value: privacy.rawValue))
|
||||
params.append(.init(name: "source[sensitive]", value: isSensitive ? "true" : "false"))
|
||||
params.append(.init(name: "bot", value: isBot ? "true" : "false"))
|
||||
params.append(.init(name: "locked", value: isLocked ? "true" : "false"))
|
||||
params.append(.init(name: "discoverable", value: isDiscoverable ? "true" : "false"))
|
||||
return params
|
||||
default:
|
||||
return nil
|
||||
}
|
||||
|
@ -148,6 +131,8 @@ public enum Accounts: Endpoint {
|
|||
return json
|
||||
case let .relationshipNote(_, json):
|
||||
return json
|
||||
case let .updateCredentials(json):
|
||||
return json
|
||||
default:
|
||||
return nil
|
||||
}
|
||||
|
@ -169,3 +154,57 @@ public struct RelationshipNoteData: Encodable, Sendable {
|
|||
self.comment = comment
|
||||
}
|
||||
}
|
||||
|
||||
public struct UpdateCredentialsData: Encodable, Sendable {
|
||||
public struct SourceData: Encodable, Sendable {
|
||||
public let privacy: Visibility
|
||||
public let sensitive: Bool
|
||||
|
||||
public init(privacy: Visibility, sensitive: Bool) {
|
||||
self.privacy = privacy
|
||||
self.sensitive = sensitive
|
||||
}
|
||||
}
|
||||
|
||||
public struct FieldData: Encodable, Sendable {
|
||||
public let name: String
|
||||
public let value: String
|
||||
|
||||
public init(name: String, value: String) {
|
||||
self.name = name
|
||||
self.value = value
|
||||
}
|
||||
}
|
||||
|
||||
public let displayName: String
|
||||
public let note: String
|
||||
public let source: SourceData
|
||||
public let bot: Bool
|
||||
public let locked: Bool
|
||||
public let discoverable: Bool
|
||||
public let fieldsAttributes: [String: FieldData]
|
||||
|
||||
public init(displayName: String,
|
||||
note: String,
|
||||
source: UpdateCredentialsData.SourceData,
|
||||
bot: Bool,
|
||||
locked: Bool,
|
||||
discoverable: Bool,
|
||||
fieldsAttributes: [FieldData]) {
|
||||
self.displayName = displayName
|
||||
self.note = note
|
||||
self.source = source
|
||||
self.bot = bot
|
||||
self.locked = locked
|
||||
self.discoverable = discoverable
|
||||
|
||||
var fieldAttributes: [String: FieldData] = [:]
|
||||
var index: Int = 0
|
||||
for fieldsAttribute in fieldsAttributes {
|
||||
fieldAttributes[String(index)] = fieldsAttribute
|
||||
index += 1
|
||||
}
|
||||
self.fieldsAttributes = fieldAttributes
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue