From fcf95ba8c136d8d60badd5cce42cb07ec85ed71b Mon Sep 17 00:00:00 2001 From: Shadowfacts Date: Sat, 3 Dec 2022 14:47:21 -0500 Subject: [PATCH] Filters view UI tweaks --- Tusker/Screens/Filters/FilterRow.swift | 4 +- Tusker/Screens/Filters/FiltersView.swift | 38 ++++++++++--------- .../Timeline/TimelineViewController.swift | 4 -- 3 files changed, 22 insertions(+), 24 deletions(-) diff --git a/Tusker/Screens/Filters/FilterRow.swift b/Tusker/Screens/Filters/FilterRow.swift index 801b7eb82b..7cac0871dc 100644 --- a/Tusker/Screens/Filters/FilterRow.swift +++ b/Tusker/Screens/Filters/FilterRow.swift @@ -16,7 +16,7 @@ struct FilterRow: View { var body: some View { VStack(alignment: .leading) { HStack(alignment: .top) { - Text(mastodonController.instanceFeatures.filtersV2 ? filter.title ?? "" : filter.keywordMOs.first!.keyword) + Text(mastodonController.instanceFeatures.filtersV2 ? filter.title ?? "" : filter.keywordMOs.first?.keyword ?? "") .font(.headline) Spacer() @@ -41,7 +41,7 @@ struct FilterRow: View { Text(FilterV1.Context.allCases.filter { filter.contexts.contains($0) }.map(\.displayName).formatted()) .font(.subheadline) - if !mastodonController.instanceFeatures.filtersV2 && filter.keywordMOs.first!.wholeWord { + if !mastodonController.instanceFeatures.filtersV2 && filter.keywordMOs.first?.wholeWord == true { Text("Whole word") .font(.subheadline) .foregroundColor(.secondary) diff --git a/Tusker/Screens/Filters/FiltersView.swift b/Tusker/Screens/Filters/FiltersView.swift index 248271c9a5..498fa60d25 100644 --- a/Tusker/Screens/Filters/FiltersView.swift +++ b/Tusker/Screens/Filters/FiltersView.swift @@ -82,30 +82,32 @@ struct FiltersList: View { } } + @ViewBuilder private func filtersSection(_ filters: [FilterMO], header: some View) -> some View { - Section { - ForEach(filters, id: \.id) { filter in - NavigationLink { - EditFilterView(filter: EditedFilter(filter), create: false) - } label: { - FilterRow(filter: filter) - } - .contextMenu { - Button(role: .destructive) { - deleteFilter(filter) + if !filters.isEmpty { + Section { + ForEach(filters, id: \.id) { filter in + NavigationLink { + EditFilterView(filter: EditedFilter(filter), create: false) } label: { - Text("Delete Filter") + FilterRow(filter: filter) + } + .contextMenu { + Button(role: .destructive) { + deleteFilter(filter) + } label: { + Label("Delete Filter", systemImage: "trash") + } } - } - } - .onDelete { indices in - for filter in indices.map({ filters[$0] }) { - deleteFilter(filter) + .onDelete { indices in + for filter in indices.map({ filters[$0] }) { + deleteFilter(filter) + } } + } header: { + header } - } header: { - header } } diff --git a/Tusker/Screens/Timeline/TimelineViewController.swift b/Tusker/Screens/Timeline/TimelineViewController.swift index ae1aeb88e4..a9a86dcfcf 100644 --- a/Tusker/Screens/Timeline/TimelineViewController.swift +++ b/Tusker/Screens/Timeline/TimelineViewController.swift @@ -96,10 +96,6 @@ class TimelineViewController: UIViewController, TimelineLikeCollectionViewContro } NotificationCenter.default.addObserver(self, selector: #selector(sceneWillEnterForeground), name: UIScene.willEnterForegroundNotification, object: nil) - - mastodonController.run(Client.getFiltersV2()) { response in - print(response) - } } // separate method because InstanceTimelineViewController needs to be able to customize it