forked from lucxjo/leganto-apple
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>
This commit is contained in:
parent
9701c3428c
commit
a18f485502
|
@ -6,20 +6,63 @@
|
|||
//
|
||||
|
||||
import SwiftUI
|
||||
import CoreData
|
||||
|
||||
enum Genre: Int16 {
|
||||
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.rawValue
|
||||
@State private var genre: Genre = .uncategorised
|
||||
@State private var url = ""
|
||||
|
||||
var body: some View {
|
||||
Text(/*@START_MENU_TOKEN@*/"Hello, World!"/*@END_MENU_TOKEN@*/)
|
||||
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()
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -10,16 +10,46 @@ import CoreData
|
|||
|
||||
struct ContentView: View {
|
||||
@Environment(\.managedObjectContext) var moc
|
||||
|
||||
@FetchRequest(sortDescriptors: [], animation: .default) var feeds: FetchedResults<Feed>
|
||||
|
||||
@State private var showAddScreen = false
|
||||
|
||||
var body: some View {
|
||||
Text("Hello World")
|
||||
NavigationView {
|
||||
List {
|
||||
ForEach(feeds) { item in
|
||||
Text(item.name!)
|
||||
}
|
||||
.onDelete(perform: deleteItems)
|
||||
}
|
||||
.navigationTitle("feeds")
|
||||
.toolbar {
|
||||
ToolbarItem {
|
||||
Button(action: {
|
||||
showAddScreen.toggle()
|
||||
}) {
|
||||
Label("add", systemImage: "plus")
|
||||
}
|
||||
}
|
||||
}
|
||||
.sheet(isPresented: $showAddScreen) {
|
||||
AddFeed()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func addItem() {}
|
||||
func deleteItems(offsets: IndexSet) {
|
||||
withAnimation {
|
||||
offsets.map { feeds[$0] }.forEach(moc.delete)
|
||||
|
||||
func deleteItems() {}
|
||||
do {
|
||||
try moc.save()
|
||||
} catch {
|
||||
let err = error as NSError
|
||||
fatalError("Unresolved error \(err), \(err.userInfo)")
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -6,4 +6,16 @@
|
|||
|
||||
*/
|
||||
|
||||
// General
|
||||
"feeds" = "Feeds";
|
||||
"save" = "Save";
|
||||
"name" = "Name";
|
||||
"desc" = "Description";
|
||||
"url" = "URL";
|
||||
"genre" = "Genre";
|
||||
"fadd" = "Add Feed";
|
||||
|
||||
// Genre categories
|
||||
"uncategorised" = "Uncategorised";
|
||||
"technology" = "Technology";
|
||||
"news" = "News";
|
||||
|
|
Loading…
Reference in a new issue