Update attachment and saving status.
This commit is contained in:
parent
8cd9341218
commit
e60b78b1df
|
@ -70,7 +70,7 @@ extension Mastodon.Media: TargetType {
|
|||
case .upload:
|
||||
return ["content-type": "multipart/form-data; boundary=\(multipartBoundary)"]
|
||||
case .update(_, _, _):
|
||||
return nil
|
||||
return [:].contentTypeApplicationJson
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -92,5 +92,4 @@ extension Mastodon.Media: TargetType {
|
|||
)
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -10,7 +10,6 @@ extension Mastodon {
|
|||
public enum Statuses {
|
||||
public enum Visibility: String, Encodable {
|
||||
case direct = "direct"
|
||||
case priv = "private"
|
||||
case unlisted = "unlisted"
|
||||
case pub = "public"
|
||||
}
|
||||
|
|
|
@ -14,7 +14,6 @@ public class PhotoAttachment: ObservableObject, Identifiable, Equatable, Hashabl
|
|||
public let photosPickerItem: PhotosPickerItem
|
||||
public var photoData: Data
|
||||
|
||||
@Published public var description = String.empty()
|
||||
@Published public var uploadedAttachment: UploadedAttachment?
|
||||
@Published public var error: Error?
|
||||
|
||||
|
|
|
@ -133,18 +133,13 @@ struct ComposeView: View {
|
|||
.frame(alignment: .topLeading)
|
||||
.toolbar {
|
||||
ToolbarItem(placement: .primaryAction) {
|
||||
Button {
|
||||
Task {
|
||||
await self.publishStatus()
|
||||
dismiss()
|
||||
}
|
||||
ActionButton {
|
||||
await self.publishStatus()
|
||||
} label: {
|
||||
Text("Publish")
|
||||
.foregroundColor(.white)
|
||||
}
|
||||
.disabled(self.publishDisabled)
|
||||
.buttonStyle(.borderedProminent)
|
||||
.tint(.accentColor)
|
||||
}
|
||||
|
||||
ToolbarItem(placement: .cancellationAction) {
|
||||
|
@ -212,11 +207,6 @@ struct ComposeView: View {
|
|||
Image(systemName: "lock")
|
||||
Text(" Followers")
|
||||
}.tag(Mastodon.Statuses.Visibility.direct)
|
||||
|
||||
HStack {
|
||||
Image(systemName: "tray.full")
|
||||
Text(" Private")
|
||||
}.tag(Mastodon.Statuses.Visibility.priv)
|
||||
}.buttonStyle(.bordered)
|
||||
}
|
||||
}
|
||||
|
@ -305,6 +295,8 @@ struct ComposeView: View {
|
|||
let statusModel = StatusModel(status: newStatus)
|
||||
let commentModel = CommentModel(status: statusModel, showDivider: false)
|
||||
self.applicationState.newComment = commentModel
|
||||
|
||||
dismiss()
|
||||
}
|
||||
} catch {
|
||||
ErrorService.shared.handle(error, message: "Error during post status.", showToastr: true)
|
||||
|
|
|
@ -7,6 +7,7 @@
|
|||
import SwiftUI
|
||||
|
||||
struct PhotoEditorView: View {
|
||||
@EnvironmentObject var client: Client
|
||||
@Environment(\.dismiss) private var dismiss
|
||||
|
||||
@State private var description: String = String.empty()
|
||||
|
@ -43,7 +44,7 @@ struct PhotoEditorView: View {
|
|||
self.hideKeyboard()
|
||||
}
|
||||
.onAppear {
|
||||
self.description = self.photoAttachment.description
|
||||
self.description = self.photoAttachment.uploadedAttachment?.description ?? String.empty()
|
||||
}
|
||||
.navigationBarTitle("Photo details")
|
||||
.navigationBarTitleDisplayMode(.inline)
|
||||
|
@ -55,16 +56,30 @@ struct PhotoEditorView: View {
|
|||
@ToolbarContentBuilder
|
||||
private func getTrailingToolbar() -> some ToolbarContent {
|
||||
ToolbarItem(placement: .navigationBarTrailing) {
|
||||
Button {
|
||||
HapticService.shared.touch()
|
||||
self.photoAttachment.description = self.description
|
||||
self.hideKeyboard()
|
||||
|
||||
self.dismiss()
|
||||
ActionButton {
|
||||
await self.update()
|
||||
} label: {
|
||||
Text("Update")
|
||||
}.buttonStyle(.borderedProminent)
|
||||
}
|
||||
}
|
||||
|
||||
private func update() async {
|
||||
HapticService.shared.touch()
|
||||
self.hideKeyboard()
|
||||
|
||||
if let uploadedAttachment = self.photoAttachment.uploadedAttachment {
|
||||
do {
|
||||
let updated = try await self.client.media?.update(id: uploadedAttachment.id,
|
||||
description: self.description,
|
||||
focus: nil)
|
||||
|
||||
self.photoAttachment.uploadedAttachment = updated
|
||||
self.dismiss()
|
||||
} catch {
|
||||
ErrorService.shared.handle(error, message: "Cannot update attachment", showToastr: true)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -21,19 +21,15 @@ struct ActionButton<Label>: View where Label: View {
|
|||
Button {
|
||||
Task {
|
||||
HapticService.shared.touch()
|
||||
defer {
|
||||
Task { @MainActor in
|
||||
withAnimation {
|
||||
self.isDuringAction = false
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
withAnimation {
|
||||
self.isDuringAction = true
|
||||
}
|
||||
|
||||
await action()
|
||||
|
||||
withAnimation {
|
||||
self.isDuringAction = false
|
||||
}
|
||||
}
|
||||
} label: {
|
||||
if isDuringAction {
|
||||
|
|
Loading…
Reference in New Issue