forked from lucxjo/leganto-apple
Louis Hollingworth
9345b91573
Added beginnings of feed parsing, may need to switch parser. Signed-off-by: Louis Hollingworth <louis@hollingworth.ch>
92 lines
2 KiB
Swift
92 lines
2 KiB
Swift
//
|
|
// AddFeed.swift
|
|
// Leganto
|
|
//
|
|
// Created by Louis Hollingworth on 2023-05-21.
|
|
//
|
|
|
|
import SwiftUI
|
|
import CoreData
|
|
|
|
enum Genre: Int16, CaseIterable, Identifiable {
|
|
case uncategorised = 0
|
|
case technology = 1
|
|
case news = 2
|
|
|
|
var id: Self { self }
|
|
}
|
|
|
|
struct AddFeed: View {
|
|
|
|
var body: some View {
|
|
#if os(iOS)
|
|
NavigationView {
|
|
AddFeedContent()
|
|
}
|
|
#else
|
|
AddFeedContent()
|
|
.padding(.all)
|
|
#endif
|
|
}
|
|
}
|
|
|
|
struct AddFeedContent: View {
|
|
@Environment(\.managedObjectContext) var moc
|
|
@Environment(\.dismiss) var dismiss
|
|
|
|
@State private var name = ""
|
|
@State private var desc = ""
|
|
@State private var genre: Genre = .uncategorised
|
|
@State private var url = ""
|
|
|
|
var body: some View {
|
|
Form {
|
|
Section {
|
|
TextField("name", text: $name)
|
|
TextField("desc", text: $desc)
|
|
TextField("url", text: $url)
|
|
Picker("genre", selection: $genre) {
|
|
ForEach(Genre.allCases) { option in
|
|
Text(LocalizedStringKey(String(describing: option)))
|
|
}
|
|
}
|
|
}
|
|
}
|
|
.toolbar {
|
|
ToolbarItem {
|
|
Button {
|
|
dismiss()
|
|
} label: {
|
|
Text("cancel")
|
|
}
|
|
|
|
}
|
|
ToolbarItem {
|
|
Button(action: addItem) {
|
|
Text("save")
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
func addItem() {
|
|
let newFeed = Feed(context: moc)
|
|
newFeed.id = UUID()
|
|
newFeed.name = name
|
|
newFeed.desc = desc
|
|
newFeed.genre = genre.rawValue
|
|
newFeed.url = url
|
|
newFeed.dateAdded = Date()
|
|
newFeed.dateUpdated = Date()
|
|
|
|
try? moc.save()
|
|
dismiss()
|
|
}
|
|
}
|
|
|
|
struct AddFeed_Previews: PreviewProvider {
|
|
static var previews: some View {
|
|
AddFeed()
|
|
}
|
|
}
|