Ferrite-backup/Ferrite/Views/SettingsViews/SettingsSourceUrlView.swift
kingbri 1eef8202ca Ferrite: Decouple torrent sources
These sources will be converted to be more flexible with JavaScript
in the future.

The source catalog is populated by adding a source list in settings
then installing a source from the catalog.

Sources can be enabled or disabled when using Ferrite.

Signed-off-by: kingbri <bdashore3@gmail.com>
2022-08-04 21:33:59 -04:00

58 lines
1.6 KiB
Swift

//
// SettingsSourceUrlView.swift
// Ferrite
//
// Created by Brian Dashore on 7/25/22.
//
import SwiftUI
struct SettingsSourceListView: View {
let backgroundContext = PersistenceController.shared.backgroundContext
@FetchRequest(
entity: TorrentSourceUrl.entity(),
sortDescriptors: []
) var sourceUrls: FetchedResults<TorrentSourceUrl>
@State private var presentSourceSheet = false
var body: some View {
List {
ForEach(sourceUrls, id: \.self) { sourceUrl in
Text(sourceUrl.repoName ?? "Unknown repo")
}
.onDelete { offsets in
for index in offsets {
if let sourceUrl = sourceUrls[safe: index] {
PersistenceController.shared.delete(sourceUrl, context: backgroundContext)
}
}
}
}
.sheet(isPresented: $presentSourceSheet) {
if #available(iOS 16, *) {
SourceListEditorView()
.presentationDetents([.medium])
} else {
SourceListEditorView()
}
}
.navigationTitle("Source lists")
.toolbar {
ToolbarItem(placement: .navigationBarTrailing) {
Button {
presentSourceSheet.toggle()
} label: {
Image(systemName: "plus")
}
}
}
}
}
struct SettingsSourceListView_Previews: PreviewProvider {
static var previews: some View {
SettingsSourceListView()
}
}