forked from lucxjo/leganto-apple
All basic views now done.
Some tidying of views will be needed. Next, data fetching needs to be worked on. Signed-off-by: Louis Hollingworth <louis@hollingworth.ch>
This commit is contained in:
parent
a18f485502
commit
058cf52926
6 changed files with 167 additions and 25 deletions
82
Leganto/AddFeedView.swift
Normal file
82
Leganto/AddFeedView.swift
Normal file
|
|
@ -0,0 +1,82 @@
|
|||
//
|
||||
// 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()
|
||||
#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(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()
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue