Bookmarks are added through search results and can be accessed through the library. These can be moved and deleted within the list. Add a RealDebrid instant availability cache for bookmark IA status to not overwhelm the API. Instant availability results are fresh on every search results since the cache is cleared. Also don't require a source API object to be present for the API parser button in source settings. If a JSON parser exists for a source, allow the option to be presented. Signed-off-by: kingbri <bdashore3@proton.me>
83 lines
2.3 KiB
Swift
83 lines
2.3 KiB
Swift
//
|
|
// Library.swift
|
|
// Ferrite
|
|
//
|
|
// Created by Brian Dashore on 9/2/22.
|
|
//
|
|
|
|
import SwiftUI
|
|
|
|
struct LibraryView: View {
|
|
enum LibraryPickerSegment {
|
|
case bookmarks
|
|
case history
|
|
}
|
|
|
|
@EnvironmentObject var navModel: NavigationViewModel
|
|
|
|
@FetchRequest(
|
|
entity: Bookmark.entity(),
|
|
sortDescriptors: [
|
|
NSSortDescriptor(keyPath: \Bookmark.orderNum, ascending: true)
|
|
]
|
|
) var bookmarks: FetchedResults<Bookmark>
|
|
|
|
@State private var historyEmpty = true
|
|
|
|
@State private var selectedSegment: LibraryPickerSegment = .bookmarks
|
|
@State private var editMode: EditMode = .inactive
|
|
|
|
var body: some View {
|
|
NavView {
|
|
VStack(spacing: 0) {
|
|
Picker("Segments", selection: $selectedSegment) {
|
|
Text("Bookmarks").tag(LibraryPickerSegment.bookmarks)
|
|
Text("History").tag(LibraryPickerSegment.history)
|
|
}
|
|
.pickerStyle(.segmented)
|
|
.padding(.horizontal)
|
|
.padding(.top)
|
|
|
|
switch selectedSegment {
|
|
case .bookmarks:
|
|
BookmarksView(bookmarks: bookmarks)
|
|
case .history:
|
|
HistoryView()
|
|
}
|
|
|
|
Spacer()
|
|
}
|
|
.overlay {
|
|
switch selectedSegment {
|
|
case .bookmarks:
|
|
if bookmarks.isEmpty {
|
|
EmptyInstructionView(title: "No Bookmarks", message: "Add a bookmark from search results")
|
|
}
|
|
case .history:
|
|
if historyEmpty {
|
|
EmptyInstructionView(title: "No History", message: "Start watching to build history")
|
|
}
|
|
}
|
|
}
|
|
.navigationTitle("Library")
|
|
.toolbar {
|
|
ToolbarItem(placement: .navigationBarTrailing) {
|
|
EditButton()
|
|
}
|
|
}
|
|
.environment(\.editMode, $editMode)
|
|
}
|
|
.onChange(of: selectedSegment) { _ in
|
|
editMode = .inactive
|
|
}
|
|
.onDisappear {
|
|
editMode = .inactive
|
|
}
|
|
}
|
|
}
|
|
|
|
struct LibraryView_Previews: PreviewProvider {
|
|
static var previews: some View {
|
|
LibraryView()
|
|
}
|
|
}
|