Fix draft being deleted too early causing empty UI during dismiss compose animation
This commit is contained in:
parent
40197e04cf
commit
205056f636
|
@ -57,9 +57,6 @@ class PostService: ObservableObject {
|
||||||
do {
|
do {
|
||||||
let (_, _) = try await mastodonController.run(request)
|
let (_, _) = try await mastodonController.run(request)
|
||||||
currentStep += 1
|
currentStep += 1
|
||||||
|
|
||||||
DraftsPersistentContainer.shared.viewContext.delete(self.draft)
|
|
||||||
DraftsPersistentContainer.shared.save()
|
|
||||||
} catch let error as Client.Error {
|
} catch let error as Client.Error {
|
||||||
throw Error.posting(error)
|
throw Error.posting(error)
|
||||||
}
|
}
|
||||||
|
|
|
@ -45,6 +45,7 @@ public final class ComposeController: ViewController {
|
||||||
@Published var isShowingDraftsList = false
|
@Published var isShowingDraftsList = false
|
||||||
@Published var poster: PostService?
|
@Published var poster: PostService?
|
||||||
@Published var postError: (any Error)?
|
@Published var postError: (any Error)?
|
||||||
|
@Published public private(set) var didPostSuccessfully = false
|
||||||
|
|
||||||
var isPosting: Bool {
|
var isPosting: Bool {
|
||||||
poster != nil
|
poster != nil
|
||||||
|
@ -172,13 +173,15 @@ public final class ComposeController: ViewController {
|
||||||
do {
|
do {
|
||||||
try await poster.post()
|
try await poster.post()
|
||||||
|
|
||||||
|
didPostSuccessfully = true
|
||||||
|
|
||||||
// wait .25 seconds so the user can see the progress bar has completed
|
// wait .25 seconds so the user can see the progress bar has completed
|
||||||
try? await Task.sleep(nanoseconds: 250_000_000)
|
try? await Task.sleep(nanoseconds: 250_000_000)
|
||||||
|
|
||||||
config.dismiss(.post)
|
|
||||||
|
|
||||||
// don't unset the poster, so the ui remains disabled while dismissing
|
// don't unset the poster, so the ui remains disabled while dismissing
|
||||||
|
|
||||||
|
config.dismiss(.post)
|
||||||
|
|
||||||
} catch let error as PostService.Error {
|
} catch let error as PostService.Error {
|
||||||
self.postError = error
|
self.postError = error
|
||||||
self.poster = nil
|
self.poster = nil
|
||||||
|
@ -202,7 +205,7 @@ public final class ComposeController: ViewController {
|
||||||
}
|
}
|
||||||
|
|
||||||
func onDisappear() {
|
func onDisappear() {
|
||||||
if !draft.hasContent {
|
if !draft.hasContent || didPostSuccessfully {
|
||||||
DraftsPersistentContainer.shared.viewContext.delete(draft)
|
DraftsPersistentContainer.shared.viewContext.delete(draft)
|
||||||
}
|
}
|
||||||
DraftsPersistentContainer.shared.save()
|
DraftsPersistentContainer.shared.save()
|
||||||
|
|
|
@ -81,7 +81,8 @@ class ComposeSceneDelegate: UIResponder, UIWindowSceneDelegate, TuskerSceneDeleg
|
||||||
|
|
||||||
if let window = window,
|
if let window = window,
|
||||||
let nav = window.rootViewController as? UINavigationController,
|
let nav = window.rootViewController as? UINavigationController,
|
||||||
let compose = nav.topViewController as? ComposeHostingController {
|
let compose = nav.topViewController as? ComposeHostingController,
|
||||||
|
!compose.controller.didPostSuccessfully {
|
||||||
scene.userActivity = UserActivityManager.editDraftActivity(id: compose.controller.draft.id, accountID: scene.session.mastodonController!.accountInfo!.id)
|
scene.userActivity = UserActivityManager.editDraftActivity(id: compose.controller.draft.id, accountID: scene.session.mastodonController!.accountInfo!.id)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue