Profile edit: Allow re order of fields

This commit is contained in:
Thomas Ricouard 2023-02-24 09:23:16 +01:00
parent 293d680510
commit cc4768b5e7
3 changed files with 7 additions and 4 deletions

View file

@ -24,6 +24,7 @@ public struct EditAccountView: View {
accountSection
}
}
.environment(\.editMode, .constant(.active))
.scrollContentBackground(.hidden)
.background(theme.secondaryBackgroundColor)
.scrollDismissesKeyboard(.immediately)
@ -108,6 +109,9 @@ public struct EditAccountView: View {
TextField("account.edit.metadata-value-placeholder", text: $field.value)
}
}
.onMove(perform: { indexSet, newOffset in
viewModel.fields.move(fromOffsets: indexSet, toOffset: newOffset)
})
.onDelete { indexes in
if let index = indexes.first {
viewModel.fields.remove(at: index)

View file

@ -93,6 +93,7 @@ public final class Client: ObservableObject, Equatable, Identifiable, Hashable {
if let json = endpoint.jsonValue {
let encoder = JSONEncoder()
encoder.keyEncodingStrategy = .convertToSnakeCase
encoder.outputFormatting = .sortedKeys
do {
let jsonData = try encoder.encode(json)
request.httpBody = jsonData

View file

@ -199,10 +199,8 @@ public struct UpdateCredentialsData: Encodable, Sendable {
self.discoverable = discoverable
var fieldAttributes: [String: FieldData] = [:]
var index: Int = 0
for fieldsAttribute in fieldsAttributes {
fieldAttributes[String(index)] = fieldsAttribute
index += 1
for (index, field) in fieldsAttributes.enumerated() {
fieldAttributes[String(index)] = field
}
self.fieldsAttributes = fieldAttributes
}