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:
Louis Hollingworth 2023-05-22 19:30:02 +01:00
parent 9701c3428c
commit a18f485502
Signed by: lucxjo
GPG key ID: A11415CB3DC7809B
3 changed files with 93 additions and 8 deletions

View file

@ -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()
}
}

View file

@ -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() {}
func deleteItems(offsets: IndexSet) {
withAnimation {
offsets.map { feeds[$0] }.forEach(moc.delete)
do {
try moc.save()
} catch {
let err = error as NSError
fatalError("Unresolved error \(err), \(err.userInfo)")
}
}
}
}

View file

@ -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";