Leave when deleting

This commit is contained in:
Lumaa 2024-01-28 17:51:50 +01:00
parent c99f185205
commit 44ad8975b6
3 changed files with 21 additions and 8 deletions

View File

@ -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())
// }
}
}

View File

@ -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()
}
}
}
}

View File

@ -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)