mirror of
https://github.com/Dimillian/IceCubesApp.git
synced 2024-11-25 17:51:01 +00:00
Status editor improvements
This commit is contained in:
parent
8e16764ff7
commit
73fde0f6aa
2 changed files with 21 additions and 5 deletions
|
@ -24,7 +24,6 @@ public struct StatusEditorView: View {
|
|||
accountHeaderView
|
||||
TextView($viewModel.statusText)
|
||||
.placeholder("What's on your mind")
|
||||
.foregroundColor(.clear)
|
||||
Spacer()
|
||||
}
|
||||
accessoryView
|
||||
|
@ -41,11 +40,17 @@ public struct StatusEditorView: View {
|
|||
ToolbarItem(placement: .navigationBarTrailing) {
|
||||
Button {
|
||||
Task {
|
||||
_ = await viewModel.postStatus()
|
||||
dismiss()
|
||||
let status = await viewModel.postStatus()
|
||||
if status != nil {
|
||||
dismiss()
|
||||
}
|
||||
}
|
||||
} label: {
|
||||
Text("Post")
|
||||
if viewModel.isPosting {
|
||||
ProgressView()
|
||||
} else {
|
||||
Text("Post")
|
||||
}
|
||||
}
|
||||
}
|
||||
ToolbarItem(placement: .navigationBarLeading) {
|
||||
|
|
|
@ -12,10 +12,14 @@ class StatusEditorViewModel: ObservableObject {
|
|||
}
|
||||
}
|
||||
|
||||
@Published var isPosting: Bool = false
|
||||
|
||||
var client: Client?
|
||||
private var internalUpdate: Bool = false
|
||||
private var inReplyTo: Status?
|
||||
|
||||
let generator = UINotificationFeedbackGenerator()
|
||||
|
||||
init(inReplyTo: Status?) {
|
||||
self.inReplyTo = inReplyTo
|
||||
}
|
||||
|
@ -23,12 +27,17 @@ class StatusEditorViewModel: ObservableObject {
|
|||
func postStatus() async -> Status? {
|
||||
guard let client else { return nil }
|
||||
do {
|
||||
isPosting = true
|
||||
let status: Status = try await client.post(endpoint: Statuses.postStatus(status: statusText.string,
|
||||
inReplyTo: inReplyTo?.id,
|
||||
mediaIds: nil,
|
||||
spoilerText: nil))
|
||||
generator.notificationOccurred(.success)
|
||||
isPosting = false
|
||||
return status
|
||||
} catch {
|
||||
isPosting = false
|
||||
generator.notificationOccurred(.error)
|
||||
return nil
|
||||
}
|
||||
}
|
||||
|
@ -40,7 +49,9 @@ class StatusEditorViewModel: ObservableObject {
|
|||
}
|
||||
|
||||
func highlightMeta() {
|
||||
let mutableString = NSMutableAttributedString(attributedString: statusText)
|
||||
let mutableString = NSMutableAttributedString(string: statusText.string)
|
||||
mutableString.addAttributes([.foregroundColor: UIColor(Color.label)],
|
||||
range: NSMakeRange(0, mutableString.string.utf16.count))
|
||||
let hashtagPattern = "(#+[a-zA-Z0-9(_)]{1,})"
|
||||
let mentionPattern = "(@+[a-zA-Z0-9(_).]{1,})"
|
||||
var ranges: [NSRange] = [NSRange]()
|
||||
|
|
Loading…
Reference in a new issue