leganto-apple/Leganto/AddFeed.swift
Louis Hollingworth a18f485502
Basic views added.
Next step is to build the feed item list once a parser has been found/
    made.

Signed-off-by: Louis Hollingworth <louis@hollingworth.ch>
2023-05-22 19:30:02 +01:00

74 lines
1.7 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 {
@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 {
NavigationView {
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(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()
}
}