Ferrite-backup/Ferrite/Views/SourceViews/SourceSettingsView.swift
kingbri 0c0b0a252a Sources: Add source updating and source list edits
Sources can now be updated based on the repo ID. To preserve repo IDs
across single URL links, the source lists can be edited and the ID
is transferred over.

Signed-off-by: kingbri <bdashore3@gmail.com>
2022-08-05 22:31:15 -04:00

86 lines
2.7 KiB
Swift

//
// SourceSettingsView.swift
// Ferrite
//
// Created by Brian Dashore on 8/4/22.
//
import SwiftUI
struct SourceSettingsView: View {
@Environment(\.dismiss) var dismiss
@EnvironmentObject var navModel: NavigationViewModel
var body: some View {
NavView {
Form {
if let selectedSource = navModel.selectedSource {
Section("Info") {
VStack(alignment: .leading, spacing: 5) {
HStack {
Text(selectedSource.name)
Text("v\(selectedSource.version)")
.foregroundColor(.secondary)
}
Text("by \(selectedSource.author)")
.foregroundColor(.secondary)
Group {
Text("ID: \(selectedSource.id)")
if let listId = selectedSource.listId {
Text("List ID: \(listId)")
} else {
Text("No list ID found. This source should be removed.")
}
}
.foregroundColor(.secondary)
.font(.caption)
}
}
SourceSettingsMethodView(selectedSource: selectedSource)
}
}
.navigationTitle("Source settings")
.toolbar {
ToolbarItem(placement: .navigationBarTrailing) {
Button("Done") {
dismiss()
}
}
}
}
}
}
struct SourceSettingsMethodView: View {
@ObservedObject var selectedSource: Source
@State private var selectedTempParser: SourcePreferredParser = .none
var body: some View {
Picker("Fetch method", selection: $selectedTempParser) {
if selectedSource.htmlParser != nil {
Text("Web scraping")
.tag(SourcePreferredParser.scraping)
}
if selectedSource.rssParser != nil {
Text("RSS")
.tag(SourcePreferredParser.rss)
}
}
.pickerStyle(.inline)
.onAppear {
selectedTempParser = SourcePreferredParser(rawValue: selectedSource.preferredParser) ?? .none
}
.onChange(of: selectedTempParser) { newMethod in
selectedSource.preferredParser = selectedTempParser.rawValue
PersistenceController.shared.save()
}
}
}