Only ask for draft when text entered by user (#251)

This commit is contained in:
Sean Goldin 2023-01-22 04:28:23 -06:00 committed by GitHub
parent a37d059026
commit 1c679186b0
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 17 additions and 2 deletions

View File

@ -125,7 +125,7 @@ public struct StatusEditorView: View {
}
ToolbarItem(placement: .navigationBarLeading) {
Button {
if !viewModel.statusText.string.isEmpty && !viewModel.mode.isInShareExtension {
if viewModel.shouldDisplayDismissWarning {
isDismissAlertPresented = true
} else {
dismiss()

View File

@ -60,6 +60,16 @@ public class StatusEditorViewModel: ObservableObject {
showPoll || !selectedMedias.isEmpty
}
var shouldDisplayDismissWarning: Bool {
var modifiedStatusText = statusText.string.trimmingCharacters(in: .whitespaces)
if let mentionString, modifiedStatusText.hasPrefix(mentionString) {
modifiedStatusText = String(modifiedStatusText.dropFirst(mentionString.count))
}
return !modifiedStatusText.isEmpty && !mode.isInShareExtension
}
@Published var visibility: Models.Visibility = .pub
@Published var mentionsSuggestions: [Account] = []
@ -68,9 +78,10 @@ public class StatusEditorViewModel: ObservableObject {
private var currentSuggestionRange: NSRange?
private var embeddedStatusURL: URL? {
return URL(string: embeddedStatus?.reblog?.url ?? embeddedStatus?.url ?? "")
URL(string: embeddedStatus?.reblog?.url ?? embeddedStatus?.url ?? "")
}
private var mentionString: String?
private var uploadTask: Task<Void, Never>?
init(mode: Mode) {
@ -171,6 +182,10 @@ public class StatusEditorViewModel: ObservableObject {
visibility = status.visibility
statusText = .init(string: mentionString)
selectedRange = .init(location: mentionString.utf16.count, length: 0)
if !mentionString.isEmpty {
self.mentionString = mentionString.trimmingCharacters(in: .whitespaces)
}
case let .mention(account, visibility):
statusText = .init(string: "@\(account.acct) ")
self.visibility = visibility