Ferrite-backup/Ferrite/Views/ComponentViews/Settings/SettingsPluginListView.swift
kingbri 0f081d0716 Ferrite: Modify UI
The overall UI of Ferrite has been changed to make animations smoother
and streamline the experiences.

A new search filter interface has been added for all iOS versions,
but iOS 15 and up have smooth UI applied due to bugs with searchbars
in iOS 14 (which shouldn't even have a searchbar in the first place).

Also fix the plugin fetching logic to not listen to a combine publisher
and instead use a notification that is easier to control.

Signed-off-by: kingbri <bdashore3@proton.me>
2023-02-16 18:34:05 -05:00

105 lines
3.8 KiB
Swift

//
// SettingsSourceListView.swift
// Ferrite
//
// Created by Brian Dashore on 7/25/22.
//
import SwiftUI
struct SettingsPluginListView: View {
let backgroundContext = PersistenceController.shared.backgroundContext
@EnvironmentObject var navModel: NavigationViewModel
@FetchRequest(
entity: PluginList.entity(),
sortDescriptors: []
) var pluginLists: FetchedResults<PluginList>
@State private var presentSourceSheet = false
@State private var selectedPluginList: PluginList?
var body: some View {
ZStack {
if pluginLists.isEmpty {
EmptyInstructionView(title: "No Lists", message: "Add a source list using the + button in the top-right")
} else {
List {
ForEach(pluginLists, id: \.self) { pluginList in
VStack(alignment: .leading, spacing: 5) {
Text(pluginList.name)
Text(pluginList.author)
.foregroundColor(.gray)
Text("ID: \(pluginList.id)")
.font(.caption)
.foregroundColor(.gray)
}
.padding(.vertical, 2)
.contextMenu {
Button {
selectedPluginList = pluginList
presentSourceSheet.toggle()
} label: {
Text("Edit")
Image(systemName: "pencil")
}
if #available(iOS 15.0, *) {
Button(role: .destructive) {
PersistenceController.shared.delete(pluginList, context: backgroundContext)
} label: {
Text("Remove")
Image(systemName: "trash")
}
} else {
Button {
PersistenceController.shared.delete(pluginList, context: backgroundContext)
} label: {
Text("Remove")
Image(systemName: "trash")
}
}
}
}
.onDelete { offsets in
for index in offsets {
if let list = pluginLists[safe: index] {
PersistenceController.shared.delete(list, context: backgroundContext)
}
}
}
}
.listStyle(.insetGrouped)
.inlinedList(inset: -20)
}
}
.sheet(isPresented: $presentSourceSheet) {
if #available(iOS 16, *) {
PluginListEditorView(selectedPluginList: selectedPluginList)
.presentationDetents([.medium])
} else {
PluginListEditorView(selectedPluginList: selectedPluginList)
}
}
.navigationTitle("Plugin Lists")
.navigationBarTitleDisplayMode(.inline)
.toolbar {
ToolbarItem(placement: .navigationBarTrailing) {
Button {
presentSourceSheet.toggle()
} label: {
Image(systemName: "plus")
}
}
}
}
}
struct SettingsPluginListView_Previews: PreviewProvider {
static var previews: some View {
SettingsPluginListView()
}
}