From 44ad8975b658046d1660b55adfeae8e334cb98fb Mon Sep 17 00:00:00 2001 From: Lumaa Date: Sun, 28 Jan 2024 17:51:50 +0100 Subject: [PATCH] Leave when deleting --- Threaded/Components/Post/CompactPostView.swift | 14 +++++++------- Threaded/Components/Post/PostMenu.swift | 4 ++++ Threaded/Data/Navigator.swift | 11 ++++++++++- 3 files changed, 21 insertions(+), 8 deletions(-) diff --git a/Threaded/Components/Post/CompactPostView.swift b/Threaded/Components/Post/CompactPostView.swift index 3a94fc0..23435d1 100644 --- a/Threaded/Components/Post/CompactPostView.swift +++ b/Threaded/Components/Post/CompactPostView.swift @@ -135,13 +135,13 @@ struct CompactPostView: View { ScrollView(.horizontal, showsIndicators: false) { HStack(alignment: .firstTextBaseline, spacing: 5) { ForEach(status.mediaAttachments) { attachment in - PostAttachment(attachment: attachment, isFeatured: false) + PostAttachment(attachment: attachment, isFeatured: false, isImaging: imaging) } } } .scrollClipDisabled() } else { - PostAttachment(attachment: status.mediaAttachments.first!) + PostAttachment(attachment: status.mediaAttachments.first!, isImaging: imaging) } } @@ -164,11 +164,11 @@ struct CompactPostView: View { stats.padding(.top, 5) } - if !imaging { - PostMenu(status: status) - .padding([.trailing, .top]) - .contentShape(Rectangle()) - } +// if !imaging { +// PostMenu(status: status) +// .padding([.trailing, .top]) +// .contentShape(Rectangle()) +// } } } diff --git a/Threaded/Components/Post/PostMenu.swift b/Threaded/Components/Post/PostMenu.swift index cacccd7..c14f355 100644 --- a/Threaded/Components/Post/PostMenu.swift +++ b/Threaded/Components/Post/PostMenu.swift @@ -6,6 +6,7 @@ import UniformTypeIdentifiers struct PostMenu: View { @Environment(Navigator.self) private var navigator @Environment(AccountManager.self) private var accountManager + @Environment(\.dismiss) private var dismiss @Environment(\.colorScheme) private var colorScheme @Environment(\.displayScale) private var displayScale @@ -92,6 +93,9 @@ struct PostMenu: View { private func deleteStatus() async { if let client = accountManager.getClient() { _ = try? await client.delete(endpoint: Statuses.status(id: status.id)) + if navigator.path.last == .post(status: status) { + dismiss() + } } } } diff --git a/Threaded/Data/Navigator.swift b/Threaded/Data/Navigator.swift index a9690af..fd6f883 100644 --- a/Threaded/Data/Navigator.swift +++ b/Threaded/Data/Navigator.swift @@ -13,6 +13,10 @@ public class Navigator: ObservableObject { path.append(to) print("appended view") } + + public func removeSettingsOfPath() { + self.path = self.path.filter({ !RouterDestination.allSettings.contains($0) }) + } } public enum TabDestination: Identifiable { @@ -90,6 +94,10 @@ public enum RouterDestination: Hashable { case about } +extension RouterDestination { + static let allSettings: [RouterDestination] = [.settings, .privacy, .about, .appearence] +} + extension View { func withAppRouter(_ navigator: Navigator) -> some View { navigationDestination(for: RouterDestination.self) { destination in @@ -158,10 +166,11 @@ extension View { private struct EmptySheetView: View { var destId: String = "???" + let str: String = .init(localized: "about.version-\(AppInfo.appVersion)") var body: some View { ZStack { - ContentUnavailableView(String("Missing view for \"\(destId.isEmpty ? "[EMPTY_DEST_ID]" : destId)\""), systemImage: "exclamationmark.triangle.fill", description: Text(String("Please notify Lumaa as soon as possible!\n\nThreadedApp v\(AppInfo.appVersion)"))) + ContentUnavailableView(String("Missing view for \"\(destId.isEmpty ? "[EMPTY_DEST_ID]" : destId)\""), systemImage: "exclamationmark.triangle.fill", description: Text(String("Please notify Lumaa as soon as possible!\n\n\(str)"))) .ignoresSafeArea() .background(Color.red.gradient) .foregroundStyle(.white)