Filters view UI tweaks

This commit is contained in:
Shadowfacts 2022-12-03 14:47:21 -05:00
parent f71804f094
commit fcf95ba8c1
3 changed files with 22 additions and 24 deletions

View File

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

View File

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

View File

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