From 9cde68da85360637ba5a678034ee86383eeba285 Mon Sep 17 00:00:00 2001 From: Justin Mazzocchi <2831158+jzzocc@users.noreply.github.com> Date: Mon, 22 Mar 2021 21:08:09 -0700 Subject: [PATCH] Navigate back after deleting context parent --- View Controllers/TableViewController.swift | 12 ++++++++++-- .../ViewModels/Entities/CollectionItemEvent.swift | 2 ++ .../ViewModels/View Models/StatusViewModel.swift | 9 +++++++-- 3 files changed, 19 insertions(+), 4 deletions(-) diff --git a/View Controllers/TableViewController.swift b/View Controllers/TableViewController.swift index 9606f64..d96cb77 100644 --- a/View Controllers/TableViewController.swift +++ b/View Controllers/TableViewController.swift @@ -520,11 +520,13 @@ private extension TableViewController { } } - // swiftlint:disable:next cyclomatic_complexity + // swiftlint:disable:next cyclomatic_complexity function_body_length func handle(event: CollectionItemEvent) { switch event { case .ignorableOutput: break + case .contextParentDeleted: + navigationController?.popViewController(animated: true) case .refresh: refreshIfAble() case let .share(url): @@ -533,10 +535,11 @@ private extension TableViewController { handle(navigation: navigation) case let .attachment(attachmentViewModel, statusViewModel): present(attachmentViewModel: attachmentViewModel, statusViewModel: statusViewModel) - case let .compose(identity, inReplyToViewModel, redraft, directMessageTo): + case let .compose(identity, inReplyToViewModel, redraft, redraftWasContextParent, directMessageTo): compose(identity: identity, inReplyToViewModel: inReplyToViewModel, redraft: redraft, + redraftWasContextParent: redraftWasContextParent, directMessageTo: directMessageTo) case let .confirmDelete(statusViewModel, redraft): confirmDelete(statusViewModel: statusViewModel, redraft: redraft) @@ -619,7 +622,12 @@ private extension TableViewController { func compose(identity: Identity?, inReplyToViewModel: StatusViewModel?, redraft: Status?, + redraftWasContextParent: Bool, directMessageTo: AccountViewModel?) { + if redraftWasContextParent { + navigationController?.popViewController(animated: true) + } + rootViewModel?.navigationViewModel?.presentedNewStatusViewModel = rootViewModel?.newStatusViewModel( identityContext: viewModel.identityContext, identity: identity, diff --git a/ViewModels/Sources/ViewModels/Entities/CollectionItemEvent.swift b/ViewModels/Sources/ViewModels/Entities/CollectionItemEvent.swift index c937a48..f75b89a 100644 --- a/ViewModels/Sources/ViewModels/Entities/CollectionItemEvent.swift +++ b/ViewModels/Sources/ViewModels/Entities/CollectionItemEvent.swift @@ -6,12 +6,14 @@ import ServiceLayer public enum CollectionItemEvent { case ignorableOutput + case contextParentDeleted case refresh case navigation(Navigation) case attachment(AttachmentViewModel, StatusViewModel) case compose(identity: Identity? = nil, inReplyTo: StatusViewModel? = nil, redraft: Status? = nil, + redraftWasContextParent: Bool = false, directMessageTo: AccountViewModel? = nil) case confirmDelete(StatusViewModel, redraft: Bool) case confirmUnfollow(AccountViewModel) diff --git a/ViewModels/Sources/ViewModels/View Models/StatusViewModel.swift b/ViewModels/Sources/ViewModels/View Models/StatusViewModel.swift index a6a45f3..b142340 100644 --- a/ViewModels/Sources/ViewModels/View Models/StatusViewModel.swift +++ b/ViewModels/Sources/ViewModels/View Models/StatusViewModel.swift @@ -315,14 +315,17 @@ public extension StatusViewModel { } func delete() { + let isContextParent = configuration.isContextParent + eventsSubject.send( statusService.delete() - .map { _ in .ignorableOutput } + .map { _ in isContextParent ? .contextParentDeleted : .ignorableOutput } .eraseToAnyPublisher()) } func deleteAndRedraft() { let identityContext = self.identityContext + let isContextParent = configuration.isContextParent eventsSubject.send( statusService.deleteAndRedraft() @@ -339,7 +342,9 @@ public extension StatusViewModel { inReplyToViewModel = nil } - return .compose(inReplyTo: inReplyToViewModel, redraft: redraft) + return .compose(inReplyTo: inReplyToViewModel, + redraft: redraft, + redraftWasContextParent: isContextParent) } .eraseToAnyPublisher()) }