mirror of
https://github.com/Dimillian/IceCubesApp.git
synced 2025-09-03 00:23:49 +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
|
accountHeaderView
|
||||||
TextView($viewModel.statusText)
|
TextView($viewModel.statusText)
|
||||||
.placeholder("What's on your mind")
|
.placeholder("What's on your mind")
|
||||||
.foregroundColor(.clear)
|
|
||||||
Spacer()
|
Spacer()
|
||||||
}
|
}
|
||||||
accessoryView
|
accessoryView
|
||||||
|
@ -41,11 +40,17 @@ public struct StatusEditorView: View {
|
||||||
ToolbarItem(placement: .navigationBarTrailing) {
|
ToolbarItem(placement: .navigationBarTrailing) {
|
||||||
Button {
|
Button {
|
||||||
Task {
|
Task {
|
||||||
_ = await viewModel.postStatus()
|
let status = await viewModel.postStatus()
|
||||||
dismiss()
|
if status != nil {
|
||||||
|
dismiss()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
} label: {
|
} label: {
|
||||||
Text("Post")
|
if viewModel.isPosting {
|
||||||
|
ProgressView()
|
||||||
|
} else {
|
||||||
|
Text("Post")
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
ToolbarItem(placement: .navigationBarLeading) {
|
ToolbarItem(placement: .navigationBarLeading) {
|
||||||
|
|
|
@ -12,10 +12,14 @@ class StatusEditorViewModel: ObservableObject {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Published var isPosting: Bool = false
|
||||||
|
|
||||||
var client: Client?
|
var client: Client?
|
||||||
private var internalUpdate: Bool = false
|
private var internalUpdate: Bool = false
|
||||||
private var inReplyTo: Status?
|
private var inReplyTo: Status?
|
||||||
|
|
||||||
|
let generator = UINotificationFeedbackGenerator()
|
||||||
|
|
||||||
init(inReplyTo: Status?) {
|
init(inReplyTo: Status?) {
|
||||||
self.inReplyTo = inReplyTo
|
self.inReplyTo = inReplyTo
|
||||||
}
|
}
|
||||||
|
@ -23,12 +27,17 @@ class StatusEditorViewModel: ObservableObject {
|
||||||
func postStatus() async -> Status? {
|
func postStatus() async -> Status? {
|
||||||
guard let client else { return nil }
|
guard let client else { return nil }
|
||||||
do {
|
do {
|
||||||
|
isPosting = true
|
||||||
let status: Status = try await client.post(endpoint: Statuses.postStatus(status: statusText.string,
|
let status: Status = try await client.post(endpoint: Statuses.postStatus(status: statusText.string,
|
||||||
inReplyTo: inReplyTo?.id,
|
inReplyTo: inReplyTo?.id,
|
||||||
mediaIds: nil,
|
mediaIds: nil,
|
||||||
spoilerText: nil))
|
spoilerText: nil))
|
||||||
|
generator.notificationOccurred(.success)
|
||||||
|
isPosting = false
|
||||||
return status
|
return status
|
||||||
} catch {
|
} catch {
|
||||||
|
isPosting = false
|
||||||
|
generator.notificationOccurred(.error)
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -40,7 +49,9 @@ class StatusEditorViewModel: ObservableObject {
|
||||||
}
|
}
|
||||||
|
|
||||||
func highlightMeta() {
|
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 hashtagPattern = "(#+[a-zA-Z0-9(_)]{1,})"
|
||||||
let mentionPattern = "(@+[a-zA-Z0-9(_).]{1,})"
|
let mentionPattern = "(@+[a-zA-Z0-9(_).]{1,})"
|
||||||
var ranges: [NSRange] = [NSRange]()
|
var ranges: [NSRange] = [NSRange]()
|
||||||
|
|
Loading…
Reference in a new issue