leganto-apple/Leganto/ContentView.swift
Louis Hollingworth 9345b91573
Added Esperanto translations
Added beginnings of feed parsing,
    may need to switch parser.

Signed-off-by: Louis Hollingworth <louis@hollingworth.ch>
2023-05-28 19:43:37 +01:00

76 lines
2.3 KiB
Swift

//
// ContentView.swift
// Leganto
//
// Created by Louis Hollingworth on 2023-05-21.
//
import SwiftUI
import CoreData
struct ContentView: View {
@Environment(\.managedObjectContext) var moc
@FetchRequest(sortDescriptors: [SortDescriptor(\.name)], animation: .default) var feeds: FetchedResults<Feed>
@State private var showAddScreen = false
var body: some View {
NavigationView {
List {
ForEach(feeds) { item in
NavigationLink {
FeedView(feedURL: URL(string: item.url!)!, feedName: item.name!)
} label: {
HStack {
if Genre(rawValue: item.genre) == .news {
Image(systemName: "newspaper")
} else if Genre(rawValue: item.genre) == .technology {
Image(systemName: "laptopcomputer")
} else {
Image(systemName: "doc")
}
Text(item.name!)
}
}
}
.onDelete(perform: deleteItems)
}
.navigationTitle("feeds")
.toolbar {
ToolbarItem {
Button(action: {
showAddScreen.toggle()
}) {
Label("add", systemImage: "plus")
}
}
}
.sheet(isPresented: $showAddScreen) {
AddFeed()
}
}
}
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)")
}
}
}
}
struct ContentView_Previews: PreviewProvider {
static var previews: some View {
ContentView()
.environment(\.managedObjectContext, DataController.preview.container.viewContext)
}
}